Repository navigation
fix(worktrees): keep retirement tombstones across project and SSH target re-add - #14917
Conversation
|
Warning Review limit reached
Next review available in: 9 seconds Limit details: You’ve used all 10 included reviews currently available under your plan. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe change adds shared SSH endpoint identity helpers and canonical retirement namespace utilities. Retirement registries read canonical and legacy keys, merge matching entries, use capped storage, and persist for non-folder repositories. SSH target reassignment and endpoint updates migrate namespaces. Transfer handling uses canonical endpoint keys. Tests cover migration, endpoint isolation, local and remote persistence, unavailable targets, runtime targets, eviction, and transfer behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/ssh/ssh-target-identity.ts (1)
3-8: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense the new block comments.
Keep the identity invariant in the source. Move detailed rationale to adjacent documentation if needed.
src/main/ssh/ssh-target-identity.ts#L3-L8: reduce the comment to the target re-add identity invariant.src/main/worktree-retirement-namespace.ts#L10-L18: reduce the comment to the repo-ID and namespace-copy retention contract.As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: afdc086f-1cc9-4cfc-80bb-f9f022c51fa4
📒 Files selected for processing (8)
src/main/orca-profiles/profile-project-retired-name-transfer.tssrc/main/orca-profiles/profile-project-transfer.test.tssrc/main/persistence-worktree-name-retirement.test.tssrc/main/persistence.tssrc/main/ssh/ssh-target-identity.tssrc/main/ssh/ssh-target-readoption.tssrc/main/worktree-name-retirement.tssrc/main/worktree-retirement-namespace.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review.
| export function retirementNamespaceKeysToRead( | ||
| repo: RepoHostFields, | ||
| namespaceKey: string, | ||
| lookup?: SshTargetLookup | ||
| ): string[] { | ||
| const legacyKey = swapRetirementNamespaceHost( | ||
| namespaceKey, | ||
| retirementHostIdentity(repo, lookup), | ||
| getRepoExecutionHostId(repo) | ||
| ) | ||
| return legacyKey ? [namespaceKey, legacyKey] : [namespaceKey] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Read the unknown SSH namespace after target recovery.
If getSshTarget is unavailable during retirement, the registry is stored under ssh:?. After the target becomes available, this function reads only the endpoint key and target-ID legacy key. It then misses the prior ssh:? registry, and the same workspace name can be reissued.
For known SSH targets, also read the equivalent ssh:? namespace as a read-only fallback. Add a regression test that retires a name while the target is unavailable, restores the target, and verifies that the name remains retired.
Proposed fix
export function retirementNamespaceKeysToRead(
repo: RepoHostFields,
namespaceKey: string,
lookup?: SshTargetLookup
): string[] {
+ const hostIdentity = retirementHostIdentity(repo, lookup)
const legacyKey = swapRetirementNamespaceHost(
namespaceKey,
- retirementHostIdentity(repo, lookup),
+ hostIdentity,
getRepoExecutionHostId(repo)
)
- return legacyKey ? [namespaceKey, legacyKey] : [namespaceKey]
+ const unknownKey =
+ parseExecutionHostId(getRepoExecutionHostId(repo))?.kind === 'ssh' &&
+ hostIdentity !== UNKNOWN_SSH_HOST_IDENTITY
+ ? swapRetirementNamespaceHost(
+ namespaceKey,
+ hostIdentity,
+ UNKNOWN_SSH_HOST_IDENTITY
+ )
+ : null
+ return [namespaceKey, legacyKey, unknownKey].filter(
+ (key): key is string => key !== null
+ )
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export function retirementNamespaceKeysToRead( | |
| repo: RepoHostFields, | |
| namespaceKey: string, | |
| lookup?: SshTargetLookup | |
| ): string[] { | |
| const legacyKey = swapRetirementNamespaceHost( | |
| namespaceKey, | |
| retirementHostIdentity(repo, lookup), | |
| getRepoExecutionHostId(repo) | |
| ) | |
| return legacyKey ? [namespaceKey, legacyKey] : [namespaceKey] | |
| export function retirementNamespaceKeysToRead( | |
| repo: RepoHostFields, | |
| namespaceKey: string, | |
| lookup?: SshTargetLookup | |
| ): string[] { | |
| const hostIdentity = retirementHostIdentity(repo, lookup) | |
| const legacyKey = swapRetirementNamespaceHost( | |
| namespaceKey, | |
| hostIdentity, | |
| getRepoExecutionHostId(repo) | |
| ) | |
| const unknownKey = | |
| parseExecutionHostId(getRepoExecutionHostId(repo))?.kind === 'ssh' && | |
| hostIdentity !== UNKNOWN_SSH_HOST_IDENTITY | |
| ? swapRetirementNamespaceHost( | |
| namespaceKey, | |
| hostIdentity, | |
| UNKNOWN_SSH_HOST_IDENTITY | |
| ) | |
| : null | |
| return [namespaceKey, legacyKey, unknownKey].filter( | |
| (key): key is string => key !== null | |
| ) | |
| } |
…get re-add Generated workspace names are retired so a name is never reissued onto a cwd that still holds another workspace's Claude/Codex history. Two re-add paths lost that record. STA-4449 (local): retirement was stored only under `repo.id`. Removing a project deletes that row and re-adding the same path mints a new id, so the new repo starts with an empty registry. The on-disk backfill normally re-seeds local repos, but it cannot recover a name whose only surviving evidence is a Codex rollout JSONL — those are deliberately not scanned — so a name spent under Codex with its workspace directory gone came back. STA-4491 (SSH): the second, path-derived copy embedded the SSH target row id. Row ids are minted fresh on every re-add, so `ssh:ssh-old:...` became `ssh:ssh-new:...` and `reassignSshTargetId` migrated other carrier state but not the retirement namespaces. Keying the store on the namespace instead of `repo.id` was rejected in `nestWorkspaces`, `worktreeBasePath` and `repo.path`, so a settings toggle would orphan every retirement at once. `repo.id` therefore stays primary and the path-derived namespace stays a mirror — a settings toggle loses the mirror but keeps the repo row, a re-add loses the repo row but keeps the mirror, and reads union both. - Mirror local repos into the namespace too, not just remote ones. - Key the namespace's host half on the SSH endpoint (host+port+username), the thing that actually decides which filesystem a path lands on, instead of the target row id. Reads also accept the pre-identity key so an upgrade keeps tombstones it already wrote, and `reassignSshTargetId` re-keys the rest. - Cap the namespace map, which by design outlives the repos that wrote it and so has nothing to prune it per repo. Endpoint identity is extracted from ssh-target-readoption.ts, which already compared these fields for exactly the same reason, so re-adoption and retirement cannot drift apart.
46294c6 to
910e39c
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
…g them An endpoint identity is not owned by the target row that rotates: nothing dedupes SSH targets by host|port|username, so a second live target can still resolve to the same host. Moving the bucket stripped that target's tombstones and reissued a path whose agent history is still on disk. Row-id identities stay a move — reassignment leaves nothing pointing at them.
…edits Config sync rewrites host/port/username on the existing target row and a runtime-owned target takes a fresh address from every provision, both keeping the row id. No re-adoption runs, so nothing carried the endpoint-keyed mirror across and it stranded — strictly worse than the pre-change key, which was the row id and was invariant under these edits. Also bound the map after a migration: a retained source bucket grows it, so the cap has to be applied there too, and compare registries by membership rather than size so an uncompacted destination cannot trade a folded name for a new one and read as unchanged.
An on-demand VM is discarded between provisions, so its fresh address reaches an empty filesystem and a reissued name collides with nothing. Migrating there would spend names against history that no longer exists, and because each provision mints another address it would add a namespace bucket per run, evicting the real tombstones of local and ordinary SSH repos.
… wrote Two defects with one root cause. Assigning to an existing key leaves it in its original insertion slot, so a merged destination kept the oldest position and the trim deleted the bucket it had just enriched. Retained source buckets are older than the destinations a copy appends, so at the cap the trim removed exactly the sources the copy existed to keep — silently turning it back into a move. The trim now exempts the keys the migration wrote or deliberately kept. Also stop on-demand runtime workspaces writing namespace mirrors at all: each provision reaches a discarded filesystem under a fresh address, so the entry can never be read back and only spends a capped slot that a local or SSH project needs. The repo-id row still records the name for the live session.
Resolves an import-union conflict in worktree-name-retirement.ts. Main's #15023 gates the backfill on the execution host id rather than connectionId; this branch adds a runtime-owned guard on the namespace write. Both apply.
…a migration Exempting keys from the trim protected them for that one call and no other. A merged destination keeps its original insertion slot, so it sat at the front of the eviction queue and the next unrelated retirement write dropped it — losing both the migrated name and the name the destination already held, on a host that had just been re-added. Re-insert what the migration writes instead, the same discipline the ordinary writer already follows, so insertion order reflects use. That also removes the exemption, which could otherwise leave the map stuck at twice the cap until one later write evicted the whole excess at once. Corrects the runtime-gate comment as well: the mirror is unreadable after the next provision, not immediately, so a remove/re-add inside one provision is a real if narrow loss.
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/persistence/leasing-ssh-ptys/ssh-target-state.ts (1)
58-66: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten the endpoint-migration comment.
Lines 58-66 explain implementation details across nine lines. Keep only the non-obvious decisions: retain the old namespace for sibling targets, and exclude runtime-owned targets because their filesystems are ephemeral.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: dca5b2ea-f242-4e21-9053-5b223fb196eb
📒 Files selected for processing (11)
src/main/orca-profiles/profile-project-retired-name-transfer.tssrc/main/orca-profiles/profile-project-transfer.test.tssrc/main/persistence-worktree-name-retirement.test.tssrc/main/persistence/leasing-ssh-ptys/ssh-target-reassignment.tssrc/main/persistence/leasing-ssh-ptys/ssh-target-state.tssrc/main/persistence/loading-store/store.tssrc/main/ssh/ssh-target-identity.tssrc/main/ssh/ssh-target-readoption.tssrc/main/worktree-name-retirement.tssrc/main/worktree-retirement-namespace.test.tssrc/main/worktree-retirement-namespace.ts
🚧 Files skipped from review as they are similar to previous changes (9)
- src/main/orca-profiles/profile-project-transfer.test.ts
- src/main/persistence/loading-store/store.ts
- src/main/persistence/leasing-ssh-ptys/ssh-target-reassignment.ts
- src/main/orca-profiles/profile-project-retired-name-transfer.ts
- src/main/ssh/ssh-target-identity.ts
- src/main/worktree-retirement-namespace.test.ts
- src/main/ssh/ssh-target-readoption.ts
- src/main/worktree-retirement-namespace.ts
- src/main/worktree-name-retirement.ts
Included review availability: Your plan includes up to 10 reviews per rolling hour; 1 remains after this review.
…ge adds nothing Replacing the trim exemption with re-insertion narrowed the protection: the exemption covered every retained source, the re-insertion only covered sources whose merge actually wrote. A copy whose destination already held the same names was then neither re-inserted nor exempt, so the migration's own trim evicted the shared source bucket ahead of hundreds of untouched ones — losing the tombstones of a live sibling target still on that endpoint, which is what copying exists to prevent. A move's destination gets the same treatment: deleting the source makes it the only remaining copy, so it has been used. Both are order-only and deliberately do not set the changed flag, keeping an import that moved nothing from scheduling a save.
d453d5c to
2e1e6ca
Compare
Independent review rounds — 5 defects found and fixedThe original commit (
Evidence
Prior-art alignmentDeriving workspace identity from the durable endpoint (including host/authority) rather than a session-minted Rendered surfaceThis change has no deterministic rendered surface — it is main-process persistence and SSH target identity. Residual risk (recorded, not blocking)
Final roundThe loop ran to a clean stop: the last round found nothing merge-blocking and changed nothing. Every |
…get re-add (stablyai#14917) * fix(worktrees): keep retirement tombstones across project and SSH target re-add Generated workspace names are retired so a name is never reissued onto a cwd that still holds another workspace's Claude/Codex history. Two re-add paths lost that record. STA-4449 (local): retirement was stored only under `repo.id`. Removing a project deletes that row and re-adding the same path mints a new id, so the new repo starts with an empty registry. The on-disk backfill normally re-seeds local repos, but it cannot recover a name whose only surviving evidence is a Codex rollout JSONL — those are deliberately not scanned — so a name spent under Codex with its workspace directory gone came back. STA-4491 (SSH): the second, path-derived copy embedded the SSH target row id. Row ids are minted fresh on every re-add, so `ssh:ssh-old:...` became `ssh:ssh-new:...` and `reassignSshTargetId` migrated other carrier state but not the retirement namespaces. Keying the store on the namespace instead of `repo.id` was rejected in `nestWorkspaces`, `worktreeBasePath` and `repo.path`, so a settings toggle would orphan every retirement at once. `repo.id` therefore stays primary and the path-derived namespace stays a mirror — a settings toggle loses the mirror but keeps the repo row, a re-add loses the repo row but keeps the mirror, and reads union both. - Mirror local repos into the namespace too, not just remote ones. - Key the namespace's host half on the SSH endpoint (host+port+username), the thing that actually decides which filesystem a path lands on, instead of the target row id. Reads also accept the pre-identity key so an upgrade keeps tombstones it already wrote, and `reassignSshTargetId` re-keys the rest. - Cap the namespace map, which by design outlives the repos that wrote it and so has nothing to prune it per repo. Endpoint identity is extracted from ssh-target-readoption.ts, which already compared these fields for exactly the same reason, so re-adoption and retirement cannot drift apart. * fix(worktrees): copy shared SSH endpoint retirements instead of moving them An endpoint identity is not owned by the target row that rotates: nothing dedupes SSH targets by host|port|username, so a second live target can still resolve to the same host. Moving the bucket stripped that target's tombstones and reissued a path whose agent history is still on disk. Row-id identities stay a move — reassignment leaves nothing pointing at them. * fix(worktrees): carry retirement mirror across in-place SSH endpoint edits Config sync rewrites host/port/username on the existing target row and a runtime-owned target takes a fresh address from every provision, both keeping the row id. No re-adoption runs, so nothing carried the endpoint-keyed mirror across and it stranded — strictly worse than the pre-change key, which was the row id and was invariant under these edits. Also bound the map after a migration: a retained source bucket grows it, so the cap has to be applied there too, and compare registries by membership rather than size so an uncompacted destination cannot trade a folded name for a new one and read as unchanged. * fix(worktrees): skip retirement migration for on-demand runtime targets An on-demand VM is discarded between provisions, so its fresh address reaches an empty filesystem and a reissued name collides with nothing. Migrating there would spend names against history that no longer exists, and because each provision mints another address it would add a namespace bucket per run, evicting the real tombstones of local and ordinary SSH repos. * fix(worktrees): stop the namespace cap evicting what a migration just wrote Two defects with one root cause. Assigning to an existing key leaves it in its original insertion slot, so a merged destination kept the oldest position and the trim deleted the bucket it had just enriched. Retained source buckets are older than the destinations a copy appends, so at the cap the trim removed exactly the sources the copy existed to keep — silently turning it back into a move. The trim now exempts the keys the migration wrote or deliberately kept. Also stop on-demand runtime workspaces writing namespace mirrors at all: each provision reaches a discarded filesystem under a fresh address, so the entry can never be read back and only spends a capped slot that a local or SSH project needs. The repo-id row still records the name for the live session. * fix(worktrees): re-insert migrated namespaces so the cap cannot undo a migration Exempting keys from the trim protected them for that one call and no other. A merged destination keeps its original insertion slot, so it sat at the front of the eviction queue and the next unrelated retirement write dropped it — losing both the migrated name and the name the destination already held, on a host that had just been re-added. Re-insert what the migration writes instead, the same discipline the ordinary writer already follows, so insertion order reflects use. That also removes the exemption, which could otherwise leave the map stuck at twice the cap until one later write evicted the whole excess at once. Corrects the runtime-gate comment as well: the mirror is unreadable after the next provision, not immediately, so a remove/re-add inside one provision is a real if narrow loss. * fix(worktrees): refresh a retained namespace source even when its merge adds nothing Replacing the trim exemption with re-insertion narrowed the protection: the exemption covered every retained source, the re-insertion only covered sources whose merge actually wrote. A copy whose destination already held the same names was then neither re-inserted nor exempt, so the migration's own trim evicted the shared source bucket ahead of hundreds of untouched ones — losing the tombstones of a live sibling target still on that endpoint, which is what copying exists to prevent. A move's destination gets the same treatment: deleting the source makes it the only remaining copy, so it has been used. Both are order-only and deliberately do not set the changed flag, keeping an import that moved nothing from scheduling a save.
…get re-add (stablyai#14917) * fix(worktrees): keep retirement tombstones across project and SSH target re-add Generated workspace names are retired so a name is never reissued onto a cwd that still holds another workspace's Claude/Codex history. Two re-add paths lost that record. STA-4449 (local): retirement was stored only under `repo.id`. Removing a project deletes that row and re-adding the same path mints a new id, so the new repo starts with an empty registry. The on-disk backfill normally re-seeds local repos, but it cannot recover a name whose only surviving evidence is a Codex rollout JSONL — those are deliberately not scanned — so a name spent under Codex with its workspace directory gone came back. STA-4491 (SSH): the second, path-derived copy embedded the SSH target row id. Row ids are minted fresh on every re-add, so `ssh:ssh-old:...` became `ssh:ssh-new:...` and `reassignSshTargetId` migrated other carrier state but not the retirement namespaces. Keying the store on the namespace instead of `repo.id` was rejected in `nestWorkspaces`, `worktreeBasePath` and `repo.path`, so a settings toggle would orphan every retirement at once. `repo.id` therefore stays primary and the path-derived namespace stays a mirror — a settings toggle loses the mirror but keeps the repo row, a re-add loses the repo row but keeps the mirror, and reads union both. - Mirror local repos into the namespace too, not just remote ones. - Key the namespace's host half on the SSH endpoint (host+port+username), the thing that actually decides which filesystem a path lands on, instead of the target row id. Reads also accept the pre-identity key so an upgrade keeps tombstones it already wrote, and `reassignSshTargetId` re-keys the rest. - Cap the namespace map, which by design outlives the repos that wrote it and so has nothing to prune it per repo. Endpoint identity is extracted from ssh-target-readoption.ts, which already compared these fields for exactly the same reason, so re-adoption and retirement cannot drift apart. * fix(worktrees): copy shared SSH endpoint retirements instead of moving them An endpoint identity is not owned by the target row that rotates: nothing dedupes SSH targets by host|port|username, so a second live target can still resolve to the same host. Moving the bucket stripped that target's tombstones and reissued a path whose agent history is still on disk. Row-id identities stay a move — reassignment leaves nothing pointing at them. * fix(worktrees): carry retirement mirror across in-place SSH endpoint edits Config sync rewrites host/port/username on the existing target row and a runtime-owned target takes a fresh address from every provision, both keeping the row id. No re-adoption runs, so nothing carried the endpoint-keyed mirror across and it stranded — strictly worse than the pre-change key, which was the row id and was invariant under these edits. Also bound the map after a migration: a retained source bucket grows it, so the cap has to be applied there too, and compare registries by membership rather than size so an uncompacted destination cannot trade a folded name for a new one and read as unchanged. * fix(worktrees): skip retirement migration for on-demand runtime targets An on-demand VM is discarded between provisions, so its fresh address reaches an empty filesystem and a reissued name collides with nothing. Migrating there would spend names against history that no longer exists, and because each provision mints another address it would add a namespace bucket per run, evicting the real tombstones of local and ordinary SSH repos. * fix(worktrees): stop the namespace cap evicting what a migration just wrote Two defects with one root cause. Assigning to an existing key leaves it in its original insertion slot, so a merged destination kept the oldest position and the trim deleted the bucket it had just enriched. Retained source buckets are older than the destinations a copy appends, so at the cap the trim removed exactly the sources the copy existed to keep — silently turning it back into a move. The trim now exempts the keys the migration wrote or deliberately kept. Also stop on-demand runtime workspaces writing namespace mirrors at all: each provision reaches a discarded filesystem under a fresh address, so the entry can never be read back and only spends a capped slot that a local or SSH project needs. The repo-id row still records the name for the live session. * fix(worktrees): re-insert migrated namespaces so the cap cannot undo a migration Exempting keys from the trim protected them for that one call and no other. A merged destination keeps its original insertion slot, so it sat at the front of the eviction queue and the next unrelated retirement write dropped it — losing both the migrated name and the name the destination already held, on a host that had just been re-added. Re-insert what the migration writes instead, the same discipline the ordinary writer already follows, so insertion order reflects use. That also removes the exemption, which could otherwise leave the map stuck at twice the cap until one later write evicted the whole excess at once. Corrects the runtime-gate comment as well: the mirror is unreadable after the next provision, not immediately, so a remove/re-add inside one provision is a real if narrow loss. * fix(worktrees): refresh a retained namespace source even when its merge adds nothing Replacing the trim exemption with re-insertion narrowed the protection: the exemption covered every retained source, the re-insertion only covered sources whose merge actually wrote. A copy whose destination already held the same names was then neither re-inserted nor exempt, so the migration's own trim evicted the shared source bucket ahead of hundreds of untouched ones — losing the tombstones of a live sibling target still on that endpoint, which is what copying exists to prevent. A move's destination gets the same treatment: deleting the source makes it the only remaining copy, so it has been used. Both are order-only and deliberately do not set the changed flag, keeping an import that moved nothing from scheduling a save.



Merge order — read this first
Merge strictly bottom-up. This PR stands alone: it typechecks and passes its suites with nothing
above it, and it is the one to merge if the stack has to be broken up.
#14919 is deliberately not folded into this one. It reverses a considered #14350 product decision —
a deliberately typed pool name such as
nautilusis now redirected tonautilus-2when that cwd isretired, and typed pool-shaped names are now recorded as spent. That judgement has to stay
rejectable without losing the two P0/P1 tombstone fixes here, which change no user-visible
behaviour.
One sequencing caveat: #14919 widens the set of creates that reach the deadline-less retirement
backfill scan, and only #14924 bounds it. Do not ship a build between those two. #14924's description
has the detail.
Fixes STA-4449 (P0) and STA-4491 (P1) — both regressions from #14350.
What breaks today
Generated workspace names are retired so a name is never reissued onto a cwd that still holds another workspace's Claude/Codex history. Two re-add paths lose that record.
STA-4449 (local, P0). Retirement is stored only under
repo.id. Removing a project deletes that row; re-adding the same path mints a new id, so the new repo starts with an empty registry. The on-disk backfill normally re-seeds local repos, which is why this is narrower than it first looks — the hole is the intersection with the deliberate Codex non-scan. A name spent under Codex whose workspace directory is gone has no evidence the backfill will read, because Codex rollout JSONL files are deliberately not scanned. That name comes back, and the new workspace inherits the old cwd's Codex history.STA-4491 (SSH, P1). The second, path-derived copy embeds the SSH target row id. Row ids are minted fresh on every re-add, so
ssh:ssh-old:…becomesssh:ssh-new:…, andreassignSshTargetIdmigrates other carrier state but notretiredWorktreeNamesByNamespace.Why not just key storage on the namespace
That option is explicitly rejected in #14350's own body, and it is still the wrong call. The namespace derives from
workspaceDir,nestWorkspaces,worktreeBasePathandrepo.path— so keying storage on it orphans every retirement the moment a user toggles any one of those, which is far more common than remove/re-add.So
repo.idstays primary storage and the path-derived namespace stays a mirror. The two fail on different events and reads union both:repo.idrowThe change
host|port|username) rather than the target row id. The endpoint is what actually decides which machine, account, and therefore which filesystem a path lands on; two rows sharing it share every absolute path. This is the STA-4491 fix.reassignSshTargetIdre-keys the rest, covering both the pre-identity row-id key and — via the removal tombstone — an endpoint that genuinely moved while its ssh-config alias stayed put.ssh-target-readoption.ts, which already compared these exact fields for the same reason. Re-adoption and retirement now cannot drift apart.Defect found in this PR's own cap, and fixed
Writing the first direct unit test for the cap turned it RED, and the cap was wrong:
A negative
endmakesslicecount back from the tail, so instead of yielding nothing on an under-full map it yields nearly all of it. Measured on the previous revision: filling the map to its nominal 256 left 128 entries, and every write past that dropped another old namespace. The mirror that exists to survive a remove/re-add was silently discarding itself for anyone with more than ~128 workspace namespaces.Fixed by clamping the overflow to
Math.max(0, …). This is why the newworktree-retirement-namespace.test.tsexists: without it the bug ships behind a comment that claims a 256-entry cap.Rebased onto current
mainmainmoved 29 commits since this branch was cut and split the 8k-linepersistence.tsinto modules, so both persistence hunks were re-homed, not merged:persistence.tspersistence/loading-store/store.tsStoremethodpersistence/leasing-ssh-ptys/ssh-target-reassignment.tsA pre-split branch can merge cleanly into code that no longer runs, so each re-homed hunk was proven live by reverting only that file to
origin/main:persistence/leasing-ssh-ptys/ssh-target-reassignment.tspersistence/loading-store/store.tsThe reassignment hunk moved out of
Storeentirely: it now readsstate.sshTargetsandstate.removedSshTargetTombstonesdirectly, so the private-method indirection is gone.Proof the tests are non-vacuous
Reverting the production files to
origin/mainand keeping the tests turns 5 behavioural tests in this suite RED, with the material diff the reproduction predicted:That diff is the point: it proves the tests reach the registry read after the remove/re-add transition and fail because the name was lost, not because setup threw.
A whole-file revert is a weak proof on its own, so each test was also pinned by a targeted mutation — every test has at least one mutation that kills it and only it:
reassignSshTargetIdstops migrating namespacesretirementNamespaceKeysToReaddrops the legacy keyThe last two matter in the other direction. "Does not leak to a different endpoint" is the guard that this fix does not over-share retirements between distinct hosts — stub the SSH target lookup out and it fails, which is also what proves the SSH tests resolve real
SshTargetrows instead of passing through the unknown-identity fallback.One honest limit:
preserves a remote retirement when an SSH target id rotates before re-addstill passes with the lookup stubbed, because the unknown-identity fallback lands both repos in the same bucket and produces the same answer. It is the paired negative test that discriminates. Read the two together, not alone.An earlier mutation pass also found a real defect in the tests themselves — the "endpoint itself moved" case originally passed via the surviving
repo.idrow rather than the migration under test. It now drops the repo row first.Gates
vitest— the 9 affected suitestypecheck:node+ its 6 suitestsc --noEmit× node/cli/weboxlint --config config/oxlint-code-quality-native-plugins.json … --deny-warningsoxlint --type-aware --config config/oxlint-code-quality-type-aware.json … --deny-warningscheck:max-lines-ratchetoxfmtoxlint prints nothing when clean, so the gate was verified live by injecting a
no-fallthroughviolation intoworktree-retirement-namespace.tsand confirming it was reported, then reverting.What is test-proven vs. reasoned
Test-proven: the local Codex-only retirement survives remove/re-add; the SSH retirement survives a target-id rotation; retirements do not leak between distinct endpoints; the pre-identity key is still read and is folded on profile transfer; unresolvable targets share one bucket; the namespace map is bounded and refreshes on rewrite; Windows path halves are case- and separator-insensitive and cannot collide with a POSIX path.
Reasoned, not test-proven: that
host|port|usernameis the right equivalence class for "same filesystem" — it is the same tuplessh-target-readoption.tsalready trusted for re-adoption, and this PR extracts rather than invents it; that 256 is the right cap; that sharing one bucket for unresolvable targets is the better error (it over-retires rather than reissuing a live cwd). None of these are observed against a real SSH host in CI.Notes for review
retiredWorktreeNamesByNamespaceis local persisted state; nothing a paired client and host exchange is touched.worktreePathComparisonKey, which lowercases and normalizes Windows separators and namespaces the two flavours (windows:/posix:) so they cannot collide. Directly tested.isFolderRepostill returns early).…|devcannot swallow…|dev2. Directly tested.<wslHome>/.claude/projects; this PR does not touch backfill discovery), STA-4473 (backfill scan has no deadline and its Promise is cached forever), STA-4479 / STA-4480 (mobile-side suggestion cache). STA-4471 lands as fix(worktrees): retire a created pool name whatever the client claims (STA-4471) #14919 on top of this.Stacked: this is the base. #14919 sits on top and can be dropped without losing these two fixes.