Repository navigation
Description
Context
Found while fixing #3521. The native journal observer adds a checkpoint id to its retained set before it calls the manager (checkpoint, packages/ui-server/src/brain/native-journal-observer.ts:291-302, after #3521). If the manager refuses the call before it records a lease, the release that follows is refused too. The id then stays retained, and close() throws "native checkpoint(s) remain retained after shutdown".
#3521 closes the window for the brain's own journal: the observer now checks the signal in the same synchronous step that hands the id to the native lease owner, and that owner checks the signal before anything else.
The worktree journal has more waits before its lease is recorded:
referenceWorktreeJournalManager().checkpointawaitsledger.record(...)beforepool.poolCheckpoint(...)(packages/ui-server/src/brain/reference-worktree-journal.ts:28-33).- The lease owner's
poolCheckpointawaitssettleRelease(from, signal)with the caller's signal beforepoolCheckpointIntent(packages/ui-server/src/brain/native-brain-leases.ts:176-186).
An abort during either wait refuses the checkpoint before a pool lease exists. poolRelease then refuses the id ("no recorded app lease"), so the worktree observer keeps it and its close() throws.
This has not been seen in CI.
Scope
Correct ownership handoff for worktree observation checkpoints refused before the pool lease is recorded. Cover both the ledger wait and the lease owner's release-settlement wait; preserve recovery ownership once a lease actually exists.
Out of scope
- Weakening arbitrary-root deletion guards or the observer's retained-checkpoint shutdown refusal.
- Refactoring the journal, changing checkpoint budgets, or changing the completed brain-only ui-server: app shutdown intermittently throws on a retained native checkpoint with no recorded lease #3521 fix.
Acceptance criteria
- A deterministic test aborts a worktree journal observation during each of the two waits above, and shows the observer's
close()resolving with no retained checkpoint. - No change weakens the "remain retained after shutdown" refusal or lets
poolReleasedelete a root that has no recorded lease.
Verification
- Run
bun run test packages/ui-server/tests/native-journal-observer.test.ts packages/ui-server/tests/reference-worktree-journal.test.ts packages/ui-server/tests/native-brain-leases.test.tsand the new deterministic regression cases. - For each wait, record the intended failing assertion before the fix and restored passing result. Prove post-lease failure still retains retryable cleanup ownership, and unleased arbitrary roots remain undeletable.
- Run the normal affected preflight before a PR. No keys or network are needed.
Triage evidence — 2026-11-04
Inspected main 53b862123d7b8e4c9d039859fabdc9fc6ad4cd36. The source pointers above still identify the claimed waits (referenceWorktreeJournalManager, packages/ui-server/src/brain/reference-worktree-journal.ts:26-30; poolCheckpoint, packages/ui-server/src/brain/native-brain-leases.ts:176-180). The observer retains the ID before the call (checkpoint, packages/ui-server/src/brain/native-journal-observer.ts:291-302).
A bounded keyless runtime check used the actual observer and worktree manager, a deferred ledger record, and a pool double that rejects an already-aborted checkpoint before recording a lease and refuses release without a lease. Steps: start observer.initialize(signal); wait until record enters; abort; resolve record; await initialization rejection; call observer.close(). Initialization rejected with the supplied abort reason; close rejected with 1 native checkpoint(s) remain retained after shutdown and no recorded app lease. The pool never recorded a lease and received two refused release attempts. This demonstrates the ledger-wait path with a controlled pool double, not a native Btrfs reproduction or proof of the second wait. The implementation must supply both regression cases above.
Contract impact
None expected.
Activity
schlessera commentedon Nov 15, 2026
Claimed for implementation. Claim token:
claim-1a9bda1e. Branch:fix/3528-worktree-checkpoint-abort.Path collision: #4050 also edits native-brain-leases.ts (adds turn-tree methods; different region). Closure-only reports otherwise.
fix(ui-server): never retain a worktree checkpoint refused before its…
schlessera commentedon Nov 16, 2026
Merged in #4060 as
85497b398through the integration lease (orchestrator merge queue for 0.45.0). Candidate confirmation passed on the exact head; the squash's own main run carries the post-merge heavy categories.