Repository navigation
fix(ui-server): never retain a worktree checkpoint refused before its pool lease (#3528) - #4060
Merged
Merged
Conversation
… pool lease (#3528) The journal observer retains a checkpoint identity before it asks the manager, and releases it if the call is refused. For a managed worktree, the native lease owner could refuse before recording any pool lease: on an abort while the worktree ledger recorded the identity, or while the owner settled the worktree's interrupted release. The cleanup release was then refused too ("no recorded app lease"), the identity stayed retained, and close() threw "native checkpoint(s) remain retained after shutdown". The lease owner now remembers an identity it refused before any lease existed and acknowledges one release of it without asking the pool to delete anything. Every other identity without a lease is still refused. The worktree journal manager forgets the ledger record of an identity whose record failed, without reaching the pool. A checkpoint whose lease was recorded keeps its retryable cleanup as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 tasks done
Owner
Author
This was referenced Nov 15, 2026
Merged
…ckpoint-abort # Conflicts: # packages/ui-server/tests/native-brain-leases.test.ts
3 of 5 tasks
This was referenced Nov 16, 2026
schlessera
marked this pull request as ready for review
November 16, 2026 15:30
schlessera
marked this pull request as draft
November 16, 2026 17:25
schlessera
marked this pull request as ready for review
November 16, 2026 17:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3528
What changed
A managed worktree's journal observer no longer keeps a checkpoint that the native lease owner refused before it recorded a pool lease. The observer adds an identity to its retained set before it asks the manager, and releases it if the call is refused. For a worktree, the lease owner could refuse before any lease existed: on an abort while the worktree ledger recorded the identity, or while the owner settled the worktree's interrupted release (
settleRelease). The cleanup release was then refused with "no recorded app lease", the identity stayed retained, andclose()threw "native checkpoint(s) remain retained after shutdown". Now the lease owner remembers each identity it refused before recording any lease (unleased, with its worktree) and acknowledges one release of it with adeletedreceipt that says no root was created. It does not ask the pool to delete anything. Any other identity without a lease is still refused. The worktree journal manager also handles a ledgerrecordthat rejects: that identity never reaches the pool, and its release only forgets whatever part of the record may have committed. A checkpoint whose lease was recorded keeps its retryable cleanup as before. The worktree assessment checkpoint inreference-worktrees.tsfollows the same record-then-checkpoint shape, so an abort there before the lease is now cleaned up through the same acknowledgment.Why this shape
#3521 closed the brain's window with a synchronous signal check, because the brain's lease owner records its intent with no earlier wait. A worktree checkpoint has two waits before its lease, and one of them (
settleRelease) must come before the intent, becausepoolCheckpointIntentrequires a held worktree. A synchronous check cannot close that window. Only the lease owner knows whether it recorded a lease, so the handoff belongs there. Two alternatives were rejected. Treating every "no recorded lease" refusal as released would let an arbitrary identity pass as cleaned up. Marking the refusal's error object would leak between callers, because one abort reason is shared by many calls. The acknowledgment is per identity, recorded only when the refusal comes before any lease row exists, cleared when a newpoolCheckpointof the same identity starts, and spent by one release.Proportionate containment (checklist): this narrows how the "no recorded app lease" refusal and the observer's "remain retained after shutdown" refusal apply, and weakens neither.
poolCheckpointbeforepoolCheckpointIntentran, while no lease row exists. It does not cover a failure of the intent write itself, or a crash between the ledger record and the lease (see below).poolReleasestill refuses an identity with no recorded lease. The observer still retains, and refuses shutdown over, any identity whose release fails.releaseFailedand the shutdown error.a worktree checkpoint aborted after its lease is recorded keeps retryable cleanup ownership (#3528)shows that a leased checkpoint's failed release stays owned and retries cleanly. The ledger-wait test shows that the acknowledgment is spent once and that an unrelated identity is still refused.Proof
The new tests in
packages/ui-server/tests/native-brain-leases.test.tsdrive the real lease owner, the realreferenceWorktreeJournalManagerand the real observer over a raw pool double that records every request.Failing-first. I reverted only
packages/ui-server/srctoorigin/mainand kept the new tests:a worktree observation aborted while its checkpoint is being recorded closes with nothing retainedfailed:1 native checkpoint(s) remain retained after shutdown: <id>. NativeBrainManagerError: This reference pool identity has no recorded app lease; arbitrary pool roots cannot be deleted.This is the ledger wait.a worktree observation aborted while the owner settles the worktree's release closes with nothing retainedfailed with the same error. This is the release-settlement wait.a worktree checkpoint ledger record that fails asks the pool nothing and leaves nothing retainedfailed with the same error.a worktree checkpoint aborted after its lease is recorded keeps retryable cleanup ownershippassed on the base too, as intended. It guards behaviour that must not change.With the fix restored, all 18 tests in the file pass. After merging origin/main, which brought in #4050's turn-tree tests in the same file and kept both sets, all 21 pass.
Mutations (each applied alone and then restored; results are for
native-brain-leases.test.ts):unleased.setremoved)remain retained after shutdown)poolReleasenever acknowledgespoolReleaseacknowledges any identity without a leaseREFERENCE_POOL_UNRECORDED_NOT_DELETED(existing test) andWORKTREE_REFUSED_CHECKPOINT_ACKNOWLEDGED_ONCEWORKTREE_REFUSED_CHECKPOINT_ACKNOWLEDGED_ONCEunsent.addremoved)WORKTREE_LEASED_CHECKPOINT_STAYS_RETAINED(post-lease ownership)Collisions (
bun scripts/collisions.ts --json --pr 4060, head16371eec2): textual with #4050 innative-brain-leases.test.ts(both append tests). #4050 has since merged, and its conflict is resolved in the merge commit with both sets of tests kept, closure-only with 24 open PRs, nothing else. Details are in the comment below.{"version":1,"kind":"brain-check-pr-receipt","head":"78744afeb71a1f4956d13c8841857926cb9745be","base":"origin/main","mode":"focused","startedAt":"2026-11-16T10:36:22.205Z","finishedAt":"2026-11-16T10:37:35.335Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":14035.977394999998},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":111.26734700000088},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":96.65781699999934},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":21.687089999999444},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":58846.71882200001}]}Checklist
.changeset/3528-worktree-checkpoint-abort.md, ui-server patch).governed-writable-workers.md,chat-history-deletion.md).Anything left open
The process can crash after a worktree ledger entry is recorded and before the pool lease intent. Startup recovery then still asks
poolReleasefor that identity, is refused, and keeps the entry with a warning on every boot until the worktree's removal forgets it. That was already true before this change and is out of scope here. Follow-up: #4059.🤖 Generated with Claude Code