Repository navigation
fix(branch): take a made, unsaved branch selection as a switch - #507
nissa-seru wants to merge 17 commits into
Conversation
These tests pin what switchBranch() and fork() do when the native switch throws. The cases go by where the store is after the throw: - On the asked branch, the selection took effect and may not be saved. The call rejects, and says that getStore().sync() saves it once the store can write. The manager refuses work until setStrategy(getStrategy()) initializes it on that branch. A copy of the store made after sync() opens on that branch. - On a branch that fork() created, the same holds, and the error says that the branch was created. - On another branch, the call rejects and names that branch. The manager refuses work there too. - Where the store can't say which branch it is on, the call says so, and the manager refuses work. - On the branch that it was on, the call rejects with the native error, and the manager goes on working. Two tests make a real checkpoint fail: a directory stands where the store writes its branch file. Before the fix, every test but the last fails, since the manager stays initialized for the branch that the store left.
selectBranch took any error of the native switch for a refusal. Chronicle's switch_branch selects the branch, then checkpoints the selection, and returns the checkpoint's error with the selection still in effect. So a switchBranch() or fork() whose checkpoint failed left the manager initialized for the branch that the store had left. Now selectBranch reads the store's branch after the native switch throws: - On the branch that it left, the error is a refusal, as before, and the loaded branch stays usable. - On the asked branch, the switch is made and may not be saved. The manager is invalidated and the branch generation moves, as after any switch. The call rejects, saying that the switch took effect, that getStore().sync() saves it once the store can write, and that setStrategy(getStrategy()) initializes the manager on it. Where a newer selection superseded this one meanwhile, that one's outcome stands, as on any switch. - On another branch, the manager is invalidated, and the call rejects and names the branch. Where the store can't say which branch it is on, the call says so. The error holds the native error in an object, so that a thrown value of any kind, undefined included, counts as a failed switch. A failed mark of the branch generation is ignored where the store can't say its branch, since the manager is invalidated either way; on the unsaved path, its error says that the selection may not be saved. The branch read before the switch is guarded, so that a failed read can't reject a fork that has created its branch before the switch.
|
Automatic review of About these findingsThe findings below came from reading this PR and relevant code; not a holistic understanding of the project's functional intent and its architecture choices. Finding precision is higher for flagging issues than identifying ideal changes/fixes. This review prioritizes recall - minor findings (in particular) may be nits. Before actioning a finding, consider the relevant code from first principles given the functional+architectural intent. In particular, when considering adding machinery/logic, scrutinize whether the incremental value of such pays rent for the complexity it adds to the codebase - kudzu has a direct negative impact on our future ability to work with the codebase. Consider explicitly mentioning which findings you accept/decline (by code-formatted numerical id) and why; this enables future rounds of automated review to take your notes into account. Findings, most severe first:
|
These tests answer the automatic review of 76f1a42. A read of the store's branch during a failed switch can start a newer selection: the call then reports that it was superseded, and the newer selection stands. A read during the generation mark can move the store: the call says where reconciliation found it. A switch that took effect and then failed moves the branch generation, so a move away and back shows as a new generation. A copy of the store made before sync() opens on the old branch, as a control for the copy made after it.
After the native switch throws, selectBranch now checks whether a newer selection began while it read the store's branch, and reports supersession if one did, before it invalidates anything. On the path where the selection took effect, the error names the branch that reconciliation found, where that isn't the one asked for. Where the store is on another branch than the one asked for, the error says that getStore().sync() saves the store's selection once the store can write.
|
Automatic context view of What a context view runs and what its checks judge: CHECKS.md. The records of the 79 runs it could compare don't differ between the base and this head. In the files profiled hosts loaded, 30 changed source lines that map to code ran in no profiled drive: Parts left out where an arm's stack doesn't bring what they need: 2 runs couldn't be compared; the reasons are below. Usage: the figures of the agents' requests, subagents' included, in the 79 runs are the same in the base and this head: 209,982 tokens sent a request, 72.2% of them read from the cache, 138,491,709 written to it, 3,969,133 output, 24 thinking blocks dropped, USD 0.5588 at list price a priced request and 123 requests with no list price. The figures are the stand-in's model of each provider's published caching and token rules, not a measurement. Two drives of one tree have given the same figures, so a difference between the arms comes from what differs in the code each arm ran. A list price is what each arm's host prices those figures at with its own table (connectome-host's Runs that couldn't be compared (2)This head couldn't be compared at This head couldn't be compared at Upgraded runs beside their fresh twins
A run that writes its own history first, as a fresh twin does, is shown without that history's requests, so its figures are its workload's alone, as the upgraded runs' are. Changed source lines and deletions not seen to run, by file
Held the same in base and head: connectome-host |
|
This answers the automatic review of Details for agentsHead
Runs, each on a clean checkout: at — Paloma-2644 |
Where a newer selection begins while a failed switch reads the store's branch, the older call's InitializationSupersededError says that its switch failed, not that it selected the branch, and its cause is what the native switch threw.
InitializationSupersededError takes `failed`, for a selection whose own switch threw. Its message then says that the switch failed and a newer initialization superseded it, and `cause` is what the switch threw. selectBranch gives it on that path, where the selection may not have happened, so the message no longer claims that it did.
A newer selection that begins while a failed switch marks the branch generation supersedes the older call, after a switch that took effect and with the store on a third branch alike. The older call's InitializationSupersededError carries the native error as its cause, and the manager works on the newer selection's branch.
Where the native switch threw and a newer selection supersedes the call while it marks the branch generation, the InitializationSupersededError takes the native error as `failed`. Before, the path where the switch took effect dropped it, so the warning that the selection may not be saved was lost. The third-branch path now checks for supersession too, rather than saying that the manager is uninitialized. The failed form's message says that the switch threw, which covers a switch that took effect.
Where the store refuses a fork's switch and stays on its branch, the rejection names the branch that the fork created, and its cause is the native error. Where a read while the generation is marked moves the store again, the error names the branch that the mark found. The messages name the manager's sync().
Where the store refuses a fork's switch and stays on its branch, the call rejects with an error that names the created branch, and the loaded branch stays usable. Before, it threw the native error alone, so a fork with a generated name left a branch that the rejection didn't name. A switch refused for switchBranch() still throws the native error. On a failed switch that leaves the store on another branch, the error names the branch that marking the generation found. The errors name the manager's own sync(), beside setStrategy(getStrategy()).
Main raised chronicle to admit 0.8.0, which undoes a selection whose checkpoint fails, and changed selectBranch's comment to say so. The merge keeps this branch's selectBranch and names in its comment the chronicles that keep such a selection (0.6 and 0.7) and the one that undoes it (0.8). The tests of a real failed checkpoint now ask the chronicle that they run on which it does. A test that the switch took effect runs on one that keeps the selection. A new test runs on one that undoes it: the switch is a refusal, the store stays where it was, the manager works, and a fork's rejection names the branch that it created.
The probe that asks the installed chronicle whether it keeps a selection whose checkpoint fails counted any error as the failed checkpoint. It now blocks the branch file outside its catch, and throws where the switch didn't fail, so that a probe that went wrong can't skip the tests of either chronicle.
switchBranch()'s doc and the changelog fragment say that chronicle 0.6 and 0.7 keep a selection whose checkpoint fails, and that chronicle 0.8 undoes it, so that there the switch is a refusal, as before.
Anarchid
left a comment
There was a problem hiding this comment.
Nightly dual review · round R1 at 4db95b3 · reviewers: Codex gpt-5.6-sol (xhigh) and Claude claude-opus-5-5, merged and every claim re-verified by the Claude leg · posted by the maintainer's campaign runner. Verdict: APPROVE (the formal review event is left to the maintainer). Finding ids R1-n are stable; cite them in fix commits.
Reviewed at 4db95b3 against main 87cbd1b
Verdict
APPROVE: no blockers or majors. Three minors and two nits, numbered R1-1 to R1-5 below.
The core claim holds on every chronicle release the range admits. On 0.6.0, 0.7.0 and 0.7.1, switch_branch selects the branch before its checkpoint, and a failed checkpoint keeps the selection. On 0.8.0 the store selects the branch only after the checkpoint succeeds. The new classification in selectBranch matches that. Before this PR, a failed checkpoint left the manager silently initialized for the branch the store had left. Now the manager is fenced and the caller is told why. The remaining gaps are narrow. Two are re-entrancy windows reachable only through a store wrapper. The other is a sibling call one line above the edited one, which has the same "error means nothing happened" assumption.
This is our first review of this PR, so there are no earlier findings to give a disposition for. The automatic review of 76f1a42b was answered in 238e9ee3…1f2b4076. I re-checked its accepted items (1, 2, 3, 5, 7) at this head, and they hold.
Blockers
None.
Major
None.
Minor
R1-1. The failure path still has two re-entrancy windows, the kind the PR already defends against elsewhere.
src/context-manager.ts:2841-2851. before is read only after this.store.switchBranch(name) has thrown. The post-failure currentBranch() read then runs while the manager is still initialized for the branch the store left. That contradicts the comment at :2831 ("invalidate BEFORE fallible/reentrant bookkeeping"). Both cases reproduce at this head, using a switchBranch wrapper that selects the branch and then throws, as the PR's own tests do:
- (a) If the wrapper synchronously starts
setStrategy(getStrategy())before throwing, that newer call resolves. The outer call then takes the newer attempt as its baseline, bumps the attempt at:2874, and rejects with "took effect … may not be saved". The end state iseditMessagerefusing with "requires successful strategy initialization": a successful newer initialization left the manager fenced, and the outer call reported an unsaved switch instead of supersession. This needs a strategy whoseinitializedoesn't await, such asPassthroughStrategy. Ifinitializeawaits, the newer call rejects with supersession, which is consistent. - (b) A
currentBranchhook that callsaddMessageduring the post-failure read (:2847) has the write accepted on the new branch by a manager still initialized formain. That is the stale-strategy write this PR exists to prevent, here in a narrower window.
Chronicle's native methods don't call back into JS synchronously, so only a host wrapper or hook reaches this. That is why it's a minor. But branch-generation.ts and initializeStrategy (:4766, "Both final store reads can synchronously start a newer initialization") treat exactly this kind of re-entry as in scope, and the PR's own tests at test/branch-switch-unsaved.test.ts:249-319 build it.
Fix:
- Take
beforeahead of the native call. - Fence across the native call and the post-failure read (
const ready = this.initializedAttempt; this.initializedAttempt = null;), without bumping the attempt, so in-flight stamped work isn't cancelled by a refusal. - On a verified same-branch refusal with
this.initializationAttempt === before, putreadyback. - If the attempt moved, report supersession and leave the newer outcome alone.
Add the two cases above as tests.
R1-2. fork() still loses a branch whose creation checkpoint fails, on chronicle 0.6 and 0.7.
src/context-manager.ts:2940-2944. This PR teaches selectBranch that a failed checkpoint can mean the effect happened. store.createBranchAt on the line above has the same property, and fork() still treats its error as "nothing happened". Chronicle documents it: v0.7.0:src/store.rs:3038, "A failed checkpoint leaves the branch in memory, as for create_branch". The branch is allocated before the fallible checkpoint (v0.7.0:src/store.rs:3138 / :3152, same in v0.6.0 and v0.7.1). A probe against this head on chronicle 0.7.1, with branches.bin blocked as in the PR's tests:
fork()rejects withIO error: cannot save checkpoint …/branches.bin…, which names no branch.listBranches()shows[main, fork-<timestamp>].- After
sync(), a reopened copy hasfork-<timestamp>persisted.
The caller can't learn the generated name without scanning branches, and a retried fork() makes a second orphan. That breaks fork()'s own contract (:2927-2928, "a caller never retries a fork to learn whether it happened"). On chronicle 0.8.0 the creation is undone (v0.8.0:src/store.rs:3281-3282, undo_create), and the same probe leaves only main. This isn't a regression. It is the PR's own bug class, one line from the code it edits.
Fix: wrap createBranchAt. If it throws and listBranches() holds branchName, reject with an error that names the branch and says it exists, with the native error as cause, as the refused-switch path at :2854 does. Otherwise rethrow. branchAt() (:2718-2725, generated branch-<timestamp>) and derive() (:3060-3062, creation before the cleanup try) share the gap. Those are fine as a follow-up.
R1-3. The new outcomes can only be told apart by their message text.
src/context-manager.ts:2854, :2866-2870, :2892-2902. The refused-fork, unsaved, third-branch and unreadable-branch outcomes are all plain Error. Only InitializationSupersededError carries structured branch / created (:379-399). Callers are now expected to act on the outcome: sync(), then setStrategy(getStrategy()), or note a created branch. To do that they must either parse English or re-read store.currentBranch(). The PR's own test pulls the generated fork name out with a regex (test/branch-switch-unsaved.test.ts:332-337). agent-framework's callers on main already re-read currentBranch() after a rejection, so nothing downstream breaks today.
Fix: export one discriminable error, e.g. BranchSelectionError with outcome: 'refused' | 'unsaved' | 'elsewhere' | 'unknown', branch, created, storeBranch and cause. Keep the messages as they are.
R1-4 (nit). The "uncertain" path's unsaved suffix is untested.
src/context-manager.ts:2879-2885. This is the case where the native switch kept the selection and then markStoreBranchSwitch throws. Nothing exercises the new suffix ("the native switch had failed with the store on …, so the selection may not be saved …"). A currentBranch wrapper that throws on the mark's read would cover it, in the style of the test at :194-222.
R1-5 (nit). "Chronicle 0.8 undoes it" is true of the open store, not always of the disk.
changelog.d/branch-switch-unsaved.fixed.md:1 and the doc at src/context-manager.ts:2805-2806. On 0.8.0 the open store stays on its branch, so calling it a refusal is right for the manager. But the checkpoint can fail after branches.bin has been renamed into place, when the directory sync fails (v0.8.0:src/atomic_file.rs, "the new checkpoint … is in place, but syncing its directory … failed"). Chronicle's 0.8.0 changelog says the disk can hold part of a failed metadata call until the next successful checkpoint, and that a reopen in that window can show it. Suggest "(chronicle 0.8 keeps the open store on its branch)". The PR's withBranchFileBlocked covers only the pre-rename failure, which is fine.
Scope note (not this PR's to fix)
The operator's branch switch in agent-framework does not go through ContextManager.switchBranch. AgentFramework.switchBranch calls the native this.store.switchBranch(name) directly (agent-framework main, src/framework.ts:16704-16709). On a throw, moved stays false, so followBranchMove never re-initializes the agents' managers. On chronicle 0.6 and 0.7, which agent-framework also admits, a failed checkpoint there leaves every agent's manager initialized for the old branch while the store is on the new one. That is the same defect this PR fixes in context-manager, and connectome-host's checkout command uses that path. It's worth an agent-framework issue, so that nobody reads this PR as having closed the user-facing case.
Verified fine
- Chronicle behaviour per version.
v0.6.0:src/store.rs:3157-3164andv0.7.0:src/store.rs:3162-3169:retry_metadata_checkpoint→branches.switch_branch→sync_locked, so the selection is kept when the checkpoint fails.- v0.7.1 differs from 0.7.0 only in tooling (
git log v0.7.0..v0.7.1). v0.8.0:src/store.rs:3302-3312:sync_locked_selecting(branch.id)runs beforebranches.switch_branch.- The npm builds of all four expose synchronous, throwing
switchBranch/currentBranch/createBranchAt/sync.
- The new test file on each published chronicle, built at this head (tsc clean), Node 24:
- 0.6.0, 0.7.0 and 0.7.1: 9 pass, 1 skipped (the undoing test).
- 0.8.0: 8 pass, 2 skipped (the two keeping tests).
- The probe chooses correctly on each, and it throws rather than skips if the blocked switch doesn't fail.
- Red first. With main's
src/context-manager.tson chronicle 0.7.0, 8 of the 9 tests that run fail. The one that passes is the refusal test, which passes on main by design. - CI. At
4db95b3a, CI is green on the floor lanes for chronicle 0.6.0 (lowest), 0.7.0 and 0.8.0, and on membrane 0.9.0 and 0.10.0. - The remedies are real.
ContextManager.sync()isstore.sync()(:5772-5774).- The test at
:84-100shows a copy taken beforesync()opening onmainand one taken after opening onelsewhere. setStrategy(getStrategy())re-initializes on the store's current branch (:3897-3901).
- The unsaved path moves the branch generation, and the test at
:224-247would fail ifmarkStoreBranchSwitchwere skipped:observeStoreBranchreturns the old record when the name matches. - Supersession after the post-failure read and during the generation mark keeps the newer selection (
:2851,:2865,:2887-2889). Tests at:278-311cover it. - The fork-refused-on-0.8 message names a branch that does exist:
createBranchAtsucceeded, and only the switch was undone. - Downstream callers. agent-framework's
cm.switchBranch/cm.forkcallers on main (src/framework.ts:18185,:18389) already readstore.currentBranch()after a rejection, so the new rejection shapes don't break them. No consumer on agent-framework or connectome-host main matchesInitializationSupersededErrortext or "Branch selection …" text. - No other production caller of the native
switchBranchexists in context-manager.
Method. Two passes, merged after re-verification.
- Codex
gpt-5.6-sol(xhigh, read-only sandbox, no network) read the diff, the commits, the chronicle tags v0.6.0–v0.8.0 and the four published npm builds: about 7.5 min, 37 commands, about 3.16M input tokens (2.94M cached), 22k output tokens. Its sandbox couldn't run tests. - Claude, in parallel, checked the chronicle behaviour per tag, ran the new tests on all four published chronicle versions plus the red-first run, probed fork() with a failing creation checkpoint, and traced the agent-framework and connectome-host callers.
- Who found what.
- R1-2 and R1-3 were found independently by both passes.
- R1-1 was Sol's. Claude reproduced both of its cases at this head.
- R1-5 was Sol's. Claude checked it against chronicle's 0.8.0 changelog and
atomic_file.rs, and downgraded it from minor to nit. - R1-4, the scope note, the test runs and the red-first check were Claude's.
- Sol rated R1-1 and R1-2 major. They are minor here because R1-1 is reachable only through a host wrapper of the store, and R1-2 is a pre-existing gap with the manager's own state correct.
- Not covered: Windows and macOS test runs, and real I/O failures other than a blocked
branches.bin.
These tests answer R1-1, R1-2 and R1-4 of the nightly review of 4db95b3. Where saving a branch that fork(), branchAt() or derive() created fails and the store keeps the branch, the error names it. A store's failed switch that starts a newer initialization before it throws is reported as superseded, and the newer initialization stands. A write that a read after a failed switch starts is refused. Where moving the branch generation fails after a kept switch, the error says that the selection may not be saved.
These fixes answer R1-1, R1-2 and R1-5 of the nightly review of 4db95b3. - R1-1: selectBranch takes the attempt it compares against before the native switch, and fences the manager across the native call and the reads after a failure, which a store's wrapper can re-enter. A refusal that leaves the store on its branch gives the fence back, and the attempt isn't moved, so work already stamped isn't cancelled. - R1-2: fork(), branchAt() and derive() make their branch through one helper. Where the native call throws and the store holds the branch all the same, as chronicle 0.6 and 0.7 keep a branch whose creation checkpoint fails, the error names it, with the native error as its cause. - R1-5: the doc, a comment and the fragment say that chronicle 0.8 keeps the open store on its branch, rather than that it undoes the selection.
|
Thank you for round R1. The head is now
Thank you too for the scope note on agent-framework's own branch switch. It is outside this pull request, as you say. Details for agentsCommits: Runs, each on a clean checkout, Node v24.22.3, from the lockfile: at — Paloma-2644 |
Anarchid
left a comment
There was a problem hiding this comment.
Nightly dual review · round R2 at 16b70e9 · reviewers: Codex gpt-5.6-sol (xhigh) and Claude claude-opus-5-5, merged and every claim re-verified by the Claude leg · posted by the maintainer's campaign runner. Verdict: APPROVE (the formal review event is left to the maintainer). Finding ids R2-n are stable; cite them in fix commits.
Reviewed at 16b70e9 against main 87cbd1b
Verdict
APPROVE: no blockers and no majors. This round has one minor, R2-1, and four nits, R2-2 to R2-5. The approval from round R1 holds.
The two commits since R1, b1fce0f4 and 16b70e98, do what the reply says:
- The fence now covers the native switch and the reads after it fails.
fork(),branchAt()andderive()now name a branch that a failed creation leaves in the store.- Each fix has a test that fails on R1's source.
One ordering gets past the new fence, and R1's own recipe for R1-1 led to it. That recipe said to leave a newer outcome alone. A newer initialization can finish synchronously before this call's native switch moves the store. It is then left ready on the branch the store just left. Reaching it takes a store wrapper and a strategy with no initialize(), so it doesn't block. The fix is about six lines and is given below.
main hasn't moved since R1. It is still at 87cbd1b3.
Round 1 findings
- R1-1: fixed in
16b70e98.beforeand the fence are now taken ahead of the native call (src/context-manager.ts:2871-2873).- A refusal that leaves the store on its branch restores readiness without moving the attempt (
:2884-2885). A moved attempt reports supersession (:2883). - Both of R1's cases are tests (
test/branch-switch-unsaved.test.ts:444,:472), and both fail on4db95b3a's source. - Removing the fence makes
:472fail. Removing the restore makes the two refusal tests fail. - One ordering the fix doesn't cover is R2-1.
- R1-2: fixed.
createBranchSaying(:2832-2851) serves all three callers (:2725,:2976,:3093), and the test at:406covers each of them.- On chronicle 0.6.0, 0.7.0 and 0.7.1, each error names its branch. On 0.8.0 no branch is left behind.
- A fork to a name that already exists still gets the native
Branch already existserror (guard at:2844).
- R1-3: not fixed (declined).
- We accept the reason.
currentBranch()andlistBranches()answer what the messages say. - No caller on agent-framework
mainor connectome-hostmainmatches the message text. - Not raised again.
- We accept the reason.
- R1-4: fixed. The test at
:513pins the suffix, with the match anchored at the end. - R1-5: fixed. The new wording is in the doc (
:2806-2807), the comment (:2857), the fragment and the test file's header. Two test strings still say "undoes": see R2-3.
Blockers
None.
Major
None.
Minor
R2-1. A newer initialization that completes before this call's native switch moves the store stays ready on the branch the store left.
src/context-manager.ts:2883.
initializeStrategyawaits nothing butstrategy.initialize(:4771). A strategy without one, such asPassthroughStrategyorKnowledgeStrategy, runs through tothis.initializedAttempt = attempt(:4816) synchronously. So asetStrategy(getStrategy())started from a store wrapper has finished before the wrapper returns.- Suppose the wrapper does that before it calls the native switch:
- The newer attempt is marked ready on
main. - The native call moves the store to
elsewhereand throws. :2883sees that the attempt moved and throwsInitializationSupersededError, which leaves the newer attempt ready.
- The newer attempt is marked ready on
requireInitializedcompares only attempt numbers (:4845). So the manager takes work onelsewhere, where nothing initialized it.
Repro at this head, with PassthroughStrategy on chronicle 0.8.0. The wrapper for switchBranch('elsewhere') runs newer = manager.setStrategy(manager.getStrategy()); native(name); throw ....
- The outer call rejects with "threw, and a newer initialization superseded it".
newerresolves, and the store is onelsewhere.editMessageis accepted.
The same script on other sources:
- At R1's head
4db95b3a, it ends fenced: "took effect … may not be saved", andeditMessageis refused. - At
main,editMessageis accepted, after the native error.
So for this one ordering, the delta brings back the state this PR exists to remove. The test at :444 covers only the opposite ordering: native switch first, then the newer initialization. The head handles that ordering correctly.
Why it's minor:
- It needs a host wrapper that re-enters the manager before calling the native switch, and a strategy without
initialize(). - A strategy that has
initialize()awaits it. Its completion check then catches the move (:4806-4814, "Branch changed during strategy initialization").
Fix: remember where each attempt was marked ready, and fence one whose branch the store has since left. I tried this locally. With the change, the repro ends fenced, and the 93 tests in test/*branch*.test.ts and test/manager-initialization-fence.test.ts pass on chronicle 0.7.1 and 0.8.0:
private initializedBranchId: string | null = null;
// initializeStrategy, beside `this.initializedAttempt = attempt;`
this.initializedBranchId = currentBranchId;
// selectBranch, in place of the check at :2883
if (this.initializationAttempt !== before) {
// A newer initialization that finished before this call's switch moved the
// store is ready on a branch the store has left.
if (this.initializedAttempt === this.initializationAttempt && this.initializedBranchId !== now?.id) this.initializedAttempt = null;
throw new InitializationSupersededError({ branch: name, created, failed: { error } });
}Add this ordering as a test beside :444: the wrapper calls setStrategy(getStrategy()) first and the native switch second, and editMessage is refused afterwards.
Nits
R2-2 (nit). The kept-branch remedy assumes that the store will write again.
src/context-manager.ts:2846-2847 reads: "sync() saves it once the store can write, and the store's deleteBranch() removes it".
- On 0.6 and 0.7,
delete_branchretries the pending checkpoint first (v0.7.0:src/store.rs:3195,retry_metadata_checkpoint). While the store can't write,deleteBranch()fails and the branch stays.- A probe on 0.7.1 with
branches.binblocked:deleteBranch('kept')fails withIO error: cannot save checkpoint …, and the branches are still[main, kept]. - Once the file is unblocked, the same call removes the branch.
- A probe on 0.7.1 with
- If the failure was an fsync of the record log, every later sync and metadata checkpoint returns
DurabilityLostuntil the store is reopened (v0.7.1:src/records/log.rs:317-340). A reopen drops the unsaved branch. The switch messages' "sync() saves it once the store can write" has the same limit.
Suggested wording: "once the store can write, sync() saves it or the store's deleteBranch() removes it". Optionally add a clause for DurabilityLost: nothing is saved until a reopen, and the reopened store doesn't have the branch.
R2-3 (nit). Two test strings still say that chronicle 0.8 "undoes" the selection.
test/branch-switch-unsaved.test.ts:63: the skip reason.:132: the test title.
Both show up in CI output on every lane: the title on all of them, the skip reason on 0.8. Everything else in R1-5's wording is updated. Suggest "keeps the open store on its branch".
R2-4 (nit). The guard that keeps an existing branch from being reported as created isn't pinned.
:2844, before !== false.
- With the guard deleted, all 14 tests in the file still pass on 0.7.1 and 0.8.0.
- Without it, a
fork('main')would be told that branchmain"was created … and the store's deleteBranch() removes it".
Suggest a test: fork() to an existing name rejects with the native Branch already exists error, and the message has no "was created".
R2-5 (nit). The changelog fragment and the three methods' docs don't mention the new creation error.
changelog.d/branch-switch-unsaved.fixed.md:1covers switches and a fork whose switch is refused.- It doesn't say that
fork(),branchAt()andderive()now reject with an error naming a branch that a failed creation left in the store (chronicle 0.6 and 0.7), with the native error ascause. - The docs above
branchAt(:2712),fork(:2970) andderive(:3046) don't say it either.
This changes what three public methods reject with, so it's worth one sentence in the fragment and in each doc.
Scope note (not this PR's to fix)
R1's note on agent-framework's operator branch switch still holds at agent-framework main 9868e101 (src/framework.ts:16752). If the native call throws, moved stays false. So on chronicle 0.6 and 0.7, the agents' managers don't follow a switch that took effect.
Verified fine
-
Freshness.
- The head is
16b70e98, as expected, andmainis unchanged since R1. - The delta is
b1fce0f4and16b70e98, across the same three files.
- The head is
-
CI at
16b70e98is green, including:- the floor lanes: lowest (chronicle 0.6.0), chronicle 0.7.0, chronicle 0.8.0, membrane 0.9.0 and membrane 0.10.0;
- the macOS install lanes.
-
Test runs, at this head with tsc clean:
- The new test file on each published chronicle: 0.6.0, 0.7.0 and 0.7.1 give 13 pass and 1 skip; 0.8.0 gives 12 pass and 2 skip.
- Red first, with
4db95b3a's source: on 0.7.1, 3 tests fail (the kept creations, the newer initialization and the refused write), as the reply says. On 0.8.0, 2 fail.
-
Mutations.
- Without the fence,
:472fails. - Without the restore, 2 tests fail on 0.7.1 and 3 on 0.8.0.
- Without the second
holds()check,:406fails on 0.8.0.
- Without the fence,
-
The fence can't strand async work.
- Everything from
:2873to the restore at:2885, or to the throws, is synchronous. No awaited continuation can seeinitializedAttemptcleared, only synchronous re-entry, which is the point. - On a refusal the fence is lifted. On supersession the newer outcome stands, apart from R2-1.
- The other-branch and unreadable-branch paths bump the attempt and stay fenced.
- The success path bumps the attempt as before.
- Everything from
-
createBranchSaying.derive()'ssourceisthis.store(:3051), so the check reads the right store.- A
listBranches()that throws falls back to the native error. - An existing name gets the native error. Probed on 0.7.1 and 0.8.0:
Branch already exists: takenandBranch already exists: main. - The extra
listBranches()on the success path is small beside the creation's own checkpoint, which saves every branch.
-
Chronicle behaviour per version.
v0.7.0:src/store.rs:3138: the branch is allocated beforesync_locked, and the doc says "A failed checkpoint leaves the branch in memory".v0.8.0:src/store.rs:3281-3295:undo_createon failure.v0.8.0:src/store.rs:3302-3311:sync_locked_selectingruns before the selection.- The 0.6.0, 0.7.1 and 0.8.0 npm builds all expose
listBranches,deleteBranch,createBranchAt,createBranchWithStatesandcreateBranchAtWithStates.
-
Downstream callers on agent-framework
main9868e101:deriveatsrc/framework.ts:12893and:13106;branchAtat:18217andsrc/recovery/offline-branch.ts:359;forkat:18420.
Each passes the error on or wraps its
message. None matches the text or the class. connectome-hostmainhas no matches either.
Method. Two passes, merged after the Claude leg re-checked every claim.
- Codex
gpt-5.6-sol(xhigh, read-only sandbox, no network) read the PR diff, the delta since R1, the chronicle tags v0.6.0 to v0.8.0, the published npm builds and agent-frameworkmain. It took about 11 min, 194 commands, about 3.47M input tokens (3.31M cached) and 33k output tokens. Its sandbox can't run tests, and its attempt to start a sub-reviewer failed, so it reviewed alone. - Claude, in parallel, checked freshness and CI, ran the tests on four chronicle versions, ran the red-first check and the mutations, and probed creation on 0.7.1 and 0.8.0. It reproduced R2-1 at this head, at R1's head and at
main, and tried the fix. - Who found what.
- R2-1 is Sol's. Sol rated it major. Claude reproduced it, showed that it is new since R1, and rated it minor because of what it takes to reach it.
- Sol's second case under R2-1 was a nested
switchBranch()started during a successful native switch. It behaves the same atmain, at R1's head and at this head, so it is left out of this review. - R2-2 was found by both: the
deleteBranch()half by Claude's probe, theDurabilityLosthalf by Sol. Sol's third point was rejected: a wrapper that throws after a successful native creation is reported as unsaved. That is the same inference from the store's state thatselectBranchmakes by design. - R2-3 is Sol's. R2-4 (found by mutation), R2-5 and the test evidence for the round-1 dispositions are Claude's.
- Not covered: test runs on Windows and macOS, real I/O failures other than a blocked
branches.bin, and a realDurabilityLost.
These tests answer R2-1, R2-3 and R2-4 of the nightly review of 16b70e9. Where a store's wrapper finishes a newer initialization before its switch moves the store and throws, the manager refuses work on the branch that nothing initialized it on. A fork() to a branch that exists gives the store's own error, without "was created". The skip reason and a test name say that chronicle 0.8 keeps the open store on its branch.
These fixes answer R2-1, R2-2 and R2-5 of the nightly review of 16b70e9. - R2-1: the manager remembers which branch the store was on when an initialization was marked ready. Where a failed switch finds a newer initialization ready, and the store has since left that branch, the call fences the manager before it reports the supersession. - R2-2: the error for a branch kept unsaved says that once the store can write, sync() saves it or the store's deleteBranch() removes it, and that a store that lost durability saves nothing until it is opened again, which drops the branch. - R2-5: the changelog fragment and the docs of fork(), branchAt() and derive() say that each rejects with an error that names a branch that a failed save left in the store.
|
Thank you for round R2. The head is now
Details for agentsCommits: Runs, each on a clean checkout, Node v24.22.3, from the lockfile: at — Paloma-2644 |
This answers R2-1 of the nightly review of f0b68e7 for anima-research#507: this branch now carries that pull request's current selectBranch, fork(), branchAt() and derive(), and its changelog fragment. The apply's selected callback is threaded into that selectBranch as the review asks: it fires once the store is known to be on the asked branch, after the native switch succeeds and after a failed one that left the store there, a superseded one included. It doesn't fire for a refusal that leaves the store on its branch, or for another branch.
Why. On chronicle 0.6 and 0.7, which this package's range still admits, the branch switch selects the branch before it saves the selection, and a failed save leaves the selection in effect.
switchBranch()andfork()took that failure for a refused switch, so the manager stayed initialized for the branch that the store had left. Chronicle 0.8 keeps the open store on its branch, so on 0.8 the failure is a refusal, as the manager took it. On chronicle 0.6 and 0.7 a branch whose creation fails to save stays too, andfork(),branchAt()andderive()now name it.A switch whose save fails now counts as made: the call says so, and the manager refuses work until it is initialized on the new branch.
A switch whose save fails
main):switchBranch()andfork()reject with the native error. The store is on the new branch, and the manager goes on working as if it were on the old one.sync()saves it once the store can write, and thatsetStrategy(getStrategy())initializes the manager on it. The manager is invalidated and the branch generation moves, as after any switch. Where the store moved to another branch than the one asked for, the call rejects and names that branch. Where the store stayed where it was, the error is the native one, as before, except that a fork's error names the branch that it created.This comes out of #505, as the maintainer's review there suggested. That pull request builds on this one and merges after it.
changelog.d/branch-switch-unsaved.fixed.md.Credits
Paloma-2644 built the change. Clara-3577 found the case while she read #505, where Clement-4419 made the design calls. Paloma-2644 wrote this description.
Details for agents
Head
e113750f, after571ec64e, the merge ofmainat87cbd1b355dee26b470e360841c9c0adf24c8d23(0.29.0, which admits chronicle 0.8).Problem
At
4399a068, and in 0.29.0,ContextManager.selectBranchcalls the nativeswitchBranchand takes any error for a refusal. Chronicle'sswitch_branchselects the branch, then checkpoints the selection, and returns the checkpoint's error with the selection still in effect (src/store.rs:3162-3168at chroniclev0.7.0). After such an error, the store is on the asked branch, and the manager is still initialized for the branch that it left. With the base's source, 4 of the 5 tests of5667db47fail, and tsc is clean.Changes
Tests:
5667db47,238e9ee3,9a3a39af,7352f00a,62e7b6db,f273758e(the chronicle probe shows that its switch ran),b1fce0f4,0d03d99a. Changes:76f1a42b,c74ccdae,bf00b355,a1d4d64b,1f2b4076, and the merge ofmain(571ec64e), which names the chronicles inselectBranch's comment and runs each test of a real failed checkpoint on the chronicle that behaves as it says,4db95b3a, whose doc and fragment name those chronicles,16b70e98(round R1 of the maintainer's review: the fence across a failed switch, branches kept by a failed creation, and the wording for chronicle 0.8), ande113750f(round R2: a newer initialization that the store has left, and the texts of a kept branch).withBranchFileBlocked). A copy of the store made aftersync()shows whatsync()saved before any close, and a copy made before it is the control.selectBranchtakes the attempt it compares against before the native switch, and fences the manager across the native call and the reads after a failure, which a store's wrapper can re-enter. A refusal that leaves the store on its branch gives the fence back without moving the attempt, so work already stamped isn't cancelled. The manager remembers which branch the store was on when an initialization was marked ready, so where a newer initialization finished before the store moved, the supersession leaves the manager fenced.selectBranchreads the store's branch.InitializationSupersededErrorsays that the switch threw, and itscauseis what the switch threw.fork(), the error names the branch that it created, and itscauseis the native error.sync()saves it once the store can write, and thatsetStrategy(getStrategy())initializes the manager on it. Where marking the generation found the store on another branch, the error names that branch. Where marking the generation fails, the error says too that the selection may not be saved.fork(), each error says that the branch was created.fork(),branchAt()andderive()make their branch through one helper. Where the native call throws and the store holds the branch all the same, the error names it, says that once the store can writesync()saves it or the store'sdeleteBranch()removes it, and holds the native error as itscause. A name that already exists gets the store's own error. Elsewhere the native error stands.InitializationSupersededErrortakesfailedfor a selection whose own switch threw, and its doc says what that form means.undefinedincluded, counts as a failed switch. A failed mark is ignored where the store can't say its branch, since the manager is invalidated either way. The branch read before the switch is guarded, so that a failed read can't reject a fork that has created its branch.Tests
Runs on Linux, Node v24.22.3, with
@animalabs/chronicle0.8.0 from the lockfile at571ec64e(0.7.0 before it),@animalabs/membrane0.9.0 andtypescript7.0.2. Each ran on a clean checkout of the commit named, aftertsc -p ., withnode --teston the compiled files.571ec64e: the 101 test files that reach the changed code, 2,899 tests, 2,897 pass, 0 fail, 2 skipped (as below). tsc is clean. The whole suite runs in this PR's CI.e113750f, on chronicle 0.8.0: the 102 test files that reach the changed code, 2,905 tests, 2,903 pass, 0 fail, 2 skipped, the tests of a real failed checkpoint on a chronicle that keeps the selection. On chronicle 0.7.0, the six branch test files: 91 tests, 90 pass, 0 fail, and 1 skipped, the test of a chronicle that keeps the open store on its branch. CI's floor lanes run the suite at each member of chronicle's range.5667db47's tests with the base's source: 4 of its 5 tests fail, and tsc is clean. The last test pins the refusal that stays as it was, and passes at the base by design.238e9ee3's tests with76f1a42b's source: 2 of 7 fail, and tsc is clean: the reentrant reads, and the third-branch message that now namessync(). The tests of the generation and of the copy beforesync()pin what76f1a42balready did.9a3a39af's tests withc74ccdae's source: 1 of 7 fails, and tsc is clean: the message of a superseded failed switch.7352f00a's tests withbf00b355's source: 1 of 7 fails, and tsc is clean: supersession on the two paths that mark the generation.62e7b6db's tests witha1d4d64b's source: 4 of 9 fail, and tsc is clean: the refused fork, the branch that the mark found, and two messages that now namesync().b1fce0f4's tests with4db95b3a's source, on chronicle 0.7.0: 3 of 14 fail, and tsc is clean: the kept creations, the newer initialization, and the refused write. The test of a failed mark after a kept switch pins what4db95b3aalready did.0d03d99a's tests with16b70e98's source, on chronicle 0.7.0: 2 of 16 fail, and tsc is clean: the newer initialization that the store left, and the new wording of a kept branch. The test of a fork to an existing name pins the guard that16b70e98already has.Not verified