Repository navigation
fix(ssh): a reattach may bind a pane but never create one - #16751
Conversation
395a238 to
fdc407c
Compare
546005d to
20db4da
Compare
fdc407c to
d82475f
Compare
20db4da to
e9afc48
Compare
d82475f to
e302d3b
Compare
e9afc48 to
562a6ce
Compare
e302d3b to
9cc5bac
Compare
562a6ce to
c65bd84
Compare
9cc5bac to
a7c18c3
Compare
`reattachKnownPtys` treats every non-terminated lease as live and calls `persistPtyBinding`, which had no way to say "bind only". Two of its branches then rebuild UI the user is not asking for: - `pty-binding-persistence.ts:133-143` -- `if (args.incarnationId)` unconditionally deletes the pane's close tombstone. - `:145-160` -- on a tab-not-found it mints one via `createMinimalPersistedTerminalTab`. The in-code comment names its only intended caller: "pty:spawn can beat the debounced writer." Spawn. Reattach took the same branch. This is the mechanism canceled ticket STA-4268 described: "Leases have no pane incarnation and upsert only by target/PTY. Every nonterminal lease is reattached; frozen coordinates are passed to persistPtyBinding, which creates and flushes missing tabs and layout leaves." It was fixed in #13326, reverted by #14361, re-applied by #14384, and reverted again by #14395 (opened and merged nine seconds apart, empty commit body). `grep -rn "mayCreate" src/` returns nothing on main -- the mechanism is genuinely out of the tree. Four parts: 1. `mayCreate` (default true). When false, one pre-mutation check mirrors all four creating branches and returns `false` without mutating, so a refusal leaves nothing half-written. 2. The authority gate -- the part both prior attempts lacked, and probably why both were reverted. `mayCreate: false` alone refuses in two situations: "the user closed it" AND "the renderer has not published its layout yet". The second is routine on disconnect->reconnect and is almost certainly the #14361 tab-loss mechanism. The fence was not wrong; it was UNCONDITIONED. It is now passed only when `hasHostAuthoritativeTerminalMembership()` says the persisted membership speaks for this worktree, reusing the function already guarding the same question at `orca-runtime.ts:8608`. Losing a tab is worse than keeping a duplicate, so an unauthoritative session still gets the creating write. Authority is read from `local` because that is the partition the write lands in -- it is local's absence being interpreted. But a pane the `ssh:<target>` partition still holds is not gone, so it keeps its creating write; refusing there would strand a live pane behind a binding reattach can no longer reach. (SSH spawns bind into `ssh:<target>` while this reattach binds into `local` -- GH #12721/#12723, STA-3980. This does not fix that split; it refuses to judge from one side of it.) 3. `findTerminalTabIdForLeaf` -- bind resolves the tab from the live layout instead of the lease's frozen `tabId`. Only the leaf half of a pane key is remint-stable: `detachTerminalPaneToTab` moves a live pane into a new tab, so a stored tabId names the tab the pane left. Identity vs location. 4. Pane-keyed supersession -- retires siblings on `(targetId, worktreeId, leafId)` to `expired`, guarded by the durable binding, which reads `local` then `ssh:<target>` so it is correct whichever partition the binding landed in. `upsertSshRemotePtyLease` matched `(targetId, ptyId)` alone (`ssh-pty-lease-operations.ts:34-36`), so a new relay pty id on reattach minted a SECOND lease instead of updating the first, leaving the predecessor non-terminated with nothing to retire it. On refusal the lease goes `expired`, never `terminated` -- `expired` records that this shell has no surface to reach it through; `terminated` would assert an exit nothing here observed, which `docs/reference/ssh-execution-boundary.md` forbids. The remote process is left running. Deliberately NOT done: - A collision guard for `upsertSshRemotePtyLease`. Built, tested, and REMOVED -- its own test passed with the guard disabled, i.e. vacuous. Telling "same lease" from "recycled id on a different shell" needs a relay-start identity, which would be a twelfth per-tab identity concept; the codebase already carries eleven (784 refs) that SSH-v3 Phase 3 deletes. Left as an in-code NOTE. This handles lease DIVERGENCE, not COLLISION. - A port of #13324. Its own authors deleted its load fold and reverted its local-only reader in #13326 ("a headless-owned pane still gets a vote before its lease is retired"); porting it ships a state-destroying migration they removed. - `bindPaneShell` from #13325. Its purpose is making `isSupersededPtyId` live, and that fence does not exist in main. It would have been a refactor plus a silently-ignored `mayCreate` -- TS drops excess props through spreads (verified), which is why `mayCreate` is passed as a conditional spread here. Honesty about scope: this does NOT close the daily-tab-growth report. The deterministic e2e repro (`ssh-lost-kill-tab-resurrection.spec.ts`, later in this stack) is byte-identical before and after, and instrumentation shows why -- in that scenario `restoreReattachedPtyRuntime` is never called at all (`CREATING TAB` 9 hits, `reattach gate` 0, `BYPASS` 0). The fence is on a path that bug does not take. It is a real, separately-provable defect; it is not the headline fix, and must not be claimed as one. Evidence, A/B on this tree. Disabling the authority gate (`mayCreate = true`) and the supersession call by hand: **8 of 12 fail**, including "does not resurrect a tab whose closing pty.kill failed with a transport error" and "holds the live lease count flat across ten reconnects of one pane" (`[ 'pty-0', 'pty-1', 'pty-2', …(7) ]` vs `[ 'pty-9' ]`). The 4 that pass both ways are the over-refusal tripwires, which is the point of having them. Restored: 12 passed; 2,439 passed across `src/main/ssh`, `src/main/persistence` and `src/main/runtime/workspace-session`.
c65bd84 to
1a69ed3
Compare
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe change updates SSH PTY lease recovery and reattachment. Lease operations compare relay PTY identities, find durable pane bindings, and expire stale sibling leases. Binding persistence can reject creation of missing terminal topology. Reattach recovery resolves tabs from current workspace layouts and expires leases when authoritative membership rejects a binding. New tests cover tab movement, topology authority, lease cardinality, pane isolation, and partial lease updates. ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
…yai#16751) `reattachKnownPtys` treats every non-terminated lease as live and calls `persistPtyBinding`, which had no way to say "bind only". Two of its branches then rebuild UI the user is not asking for: - `pty-binding-persistence.ts:133-143` -- `if (args.incarnationId)` unconditionally deletes the pane's close tombstone. - `:145-160` -- on a tab-not-found it mints one via `createMinimalPersistedTerminalTab`. The in-code comment names its only intended caller: "pty:spawn can beat the debounced writer." Spawn. Reattach took the same branch. This is the mechanism canceled ticket STA-4268 described: "Leases have no pane incarnation and upsert only by target/PTY. Every nonterminal lease is reattached; frozen coordinates are passed to persistPtyBinding, which creates and flushes missing tabs and layout leaves." It was fixed in stablyai#13326, reverted by stablyai#14361, re-applied by stablyai#14384, and reverted again by stablyai#14395 (opened and merged nine seconds apart, empty commit body). `grep -rn "mayCreate" src/` returns nothing on main -- the mechanism is genuinely out of the tree. Four parts: 1. `mayCreate` (default true). When false, one pre-mutation check mirrors all four creating branches and returns `false` without mutating, so a refusal leaves nothing half-written. 2. The authority gate -- the part both prior attempts lacked, and probably why both were reverted. `mayCreate: false` alone refuses in two situations: "the user closed it" AND "the renderer has not published its layout yet". The second is routine on disconnect->reconnect and is almost certainly the stablyai#14361 tab-loss mechanism. The fence was not wrong; it was UNCONDITIONED. It is now passed only when `hasHostAuthoritativeTerminalMembership()` says the persisted membership speaks for this worktree, reusing the function already guarding the same question at `orca-runtime.ts:8608`. Losing a tab is worse than keeping a duplicate, so an unauthoritative session still gets the creating write. Authority is read from `local` because that is the partition the write lands in -- it is local's absence being interpreted. But a pane the `ssh:<target>` partition still holds is not gone, so it keeps its creating write; refusing there would strand a live pane behind a binding reattach can no longer reach. (SSH spawns bind into `ssh:<target>` while this reattach binds into `local` -- GH stablyai#12721/stablyai#12723, STA-3980. This does not fix that split; it refuses to judge from one side of it.) 3. `findTerminalTabIdForLeaf` -- bind resolves the tab from the live layout instead of the lease's frozen `tabId`. Only the leaf half of a pane key is remint-stable: `detachTerminalPaneToTab` moves a live pane into a new tab, so a stored tabId names the tab the pane left. Identity vs location. 4. Pane-keyed supersession -- retires siblings on `(targetId, worktreeId, leafId)` to `expired`, guarded by the durable binding, which reads `local` then `ssh:<target>` so it is correct whichever partition the binding landed in. `upsertSshRemotePtyLease` matched `(targetId, ptyId)` alone (`ssh-pty-lease-operations.ts:34-36`), so a new relay pty id on reattach minted a SECOND lease instead of updating the first, leaving the predecessor non-terminated with nothing to retire it. On refusal the lease goes `expired`, never `terminated` -- `expired` records that this shell has no surface to reach it through; `terminated` would assert an exit nothing here observed, which `docs/reference/ssh-execution-boundary.md` forbids. The remote process is left running. Deliberately NOT done: - A collision guard for `upsertSshRemotePtyLease`. Built, tested, and REMOVED -- its own test passed with the guard disabled, i.e. vacuous. Telling "same lease" from "recycled id on a different shell" needs a relay-start identity, which would be a twelfth per-tab identity concept; the codebase already carries eleven (784 refs) that SSH-v3 Phase 3 deletes. Left as an in-code NOTE. This handles lease DIVERGENCE, not COLLISION. - A port of stablyai#13324. Its own authors deleted its load fold and reverted its local-only reader in stablyai#13326 ("a headless-owned pane still gets a vote before its lease is retired"); porting it ships a state-destroying migration they removed. - `bindPaneShell` from stablyai#13325. Its purpose is making `isSupersededPtyId` live, and that fence does not exist in main. It would have been a refactor plus a silently-ignored `mayCreate` -- TS drops excess props through spreads (verified), which is why `mayCreate` is passed as a conditional spread here. Honesty about scope: this does NOT close the daily-tab-growth report. The deterministic e2e repro (`ssh-lost-kill-tab-resurrection.spec.ts`, later in this stack) is byte-identical before and after, and instrumentation shows why -- in that scenario `restoreReattachedPtyRuntime` is never called at all (`CREATING TAB` 9 hits, `reattach gate` 0, `BYPASS` 0). The fence is on a path that bug does not take. It is a real, separately-provable defect; it is not the headline fix, and must not be claimed as one. Evidence, A/B on this tree. Disabling the authority gate (`mayCreate = true`) and the supersession call by hand: **8 of 12 fail**, including "does not resurrect a tab whose closing pty.kill failed with a transport error" and "holds the live lease count flat across ten reconnects of one pane" (`[ 'pty-0', 'pty-1', 'pty-2', …(7) ]` vs `[ 'pty-9' ]`). The 4 that pass both ways are the over-refusal tripwires, which is the point of having them. Restored: 12 passed; 2,439 passed across `src/main/ssh`, `src/main/persistence` and `src/main/runtime/workspace-session`. (cherry picked from commit a7b1da9)
…yai#16751) `reattachKnownPtys` treats every non-terminated lease as live and calls `persistPtyBinding`, which had no way to say "bind only". Two of its branches then rebuild UI the user is not asking for: - `pty-binding-persistence.ts:133-143` -- `if (args.incarnationId)` unconditionally deletes the pane's close tombstone. - `:145-160` -- on a tab-not-found it mints one via `createMinimalPersistedTerminalTab`. The in-code comment names its only intended caller: "pty:spawn can beat the debounced writer." Spawn. Reattach took the same branch. This is the mechanism canceled ticket STA-4268 described: "Leases have no pane incarnation and upsert only by target/PTY. Every nonterminal lease is reattached; frozen coordinates are passed to persistPtyBinding, which creates and flushes missing tabs and layout leaves." It was fixed in stablyai#13326, reverted by stablyai#14361, re-applied by stablyai#14384, and reverted again by stablyai#14395 (opened and merged nine seconds apart, empty commit body). `grep -rn "mayCreate" src/` returns nothing on main -- the mechanism is genuinely out of the tree. Four parts: 1. `mayCreate` (default true). When false, one pre-mutation check mirrors all four creating branches and returns `false` without mutating, so a refusal leaves nothing half-written. 2. The authority gate -- the part both prior attempts lacked, and probably why both were reverted. `mayCreate: false` alone refuses in two situations: "the user closed it" AND "the renderer has not published its layout yet". The second is routine on disconnect->reconnect and is almost certainly the stablyai#14361 tab-loss mechanism. The fence was not wrong; it was UNCONDITIONED. It is now passed only when `hasHostAuthoritativeTerminalMembership()` says the persisted membership speaks for this worktree, reusing the function already guarding the same question at `orca-runtime.ts:8608`. Losing a tab is worse than keeping a duplicate, so an unauthoritative session still gets the creating write. Authority is read from `local` because that is the partition the write lands in -- it is local's absence being interpreted. But a pane the `ssh:<target>` partition still holds is not gone, so it keeps its creating write; refusing there would strand a live pane behind a binding reattach can no longer reach. (SSH spawns bind into `ssh:<target>` while this reattach binds into `local` -- GH stablyai#12721/stablyai#12723, STA-3980. This does not fix that split; it refuses to judge from one side of it.) 3. `findTerminalTabIdForLeaf` -- bind resolves the tab from the live layout instead of the lease's frozen `tabId`. Only the leaf half of a pane key is remint-stable: `detachTerminalPaneToTab` moves a live pane into a new tab, so a stored tabId names the tab the pane left. Identity vs location. 4. Pane-keyed supersession -- retires siblings on `(targetId, worktreeId, leafId)` to `expired`, guarded by the durable binding, which reads `local` then `ssh:<target>` so it is correct whichever partition the binding landed in. `upsertSshRemotePtyLease` matched `(targetId, ptyId)` alone (`ssh-pty-lease-operations.ts:34-36`), so a new relay pty id on reattach minted a SECOND lease instead of updating the first, leaving the predecessor non-terminated with nothing to retire it. On refusal the lease goes `expired`, never `terminated` -- `expired` records that this shell has no surface to reach it through; `terminated` would assert an exit nothing here observed, which `docs/reference/ssh-execution-boundary.md` forbids. The remote process is left running. Deliberately NOT done: - A collision guard for `upsertSshRemotePtyLease`. Built, tested, and REMOVED -- its own test passed with the guard disabled, i.e. vacuous. Telling "same lease" from "recycled id on a different shell" needs a relay-start identity, which would be a twelfth per-tab identity concept; the codebase already carries eleven (784 refs) that SSH-v3 Phase 3 deletes. Left as an in-code NOTE. This handles lease DIVERGENCE, not COLLISION. - A port of stablyai#13324. Its own authors deleted its load fold and reverted its local-only reader in stablyai#13326 ("a headless-owned pane still gets a vote before its lease is retired"); porting it ships a state-destroying migration they removed. - `bindPaneShell` from stablyai#13325. Its purpose is making `isSupersededPtyId` live, and that fence does not exist in main. It would have been a refactor plus a silently-ignored `mayCreate` -- TS drops excess props through spreads (verified), which is why `mayCreate` is passed as a conditional spread here. Honesty about scope: this does NOT close the daily-tab-growth report. The deterministic e2e repro (`ssh-lost-kill-tab-resurrection.spec.ts`, later in this stack) is byte-identical before and after, and instrumentation shows why -- in that scenario `restoreReattachedPtyRuntime` is never called at all (`CREATING TAB` 9 hits, `reattach gate` 0, `BYPASS` 0). The fence is on a path that bug does not take. It is a real, separately-provable defect; it is not the headline fix, and must not be claimed as one. Evidence, A/B on this tree. Disabling the authority gate (`mayCreate = true`) and the supersession call by hand: **8 of 12 fail**, including "does not resurrect a tab whose closing pty.kill failed with a transport error" and "holds the live lease count flat across ten reconnects of one pane" (`[ 'pty-0', 'pty-1', 'pty-2', …(7) ]` vs `[ 'pty-9' ]`). The 4 that pass both ways are the over-refusal tripwires, which is the point of having them. Restored: 12 passed; 2,439 passed across `src/main/ssh`, `src/main/persistence` and `src/main/runtime/workspace-session`.
Stack: 5 of 6 — based on #16750.
Symptom
An SSH reconnect rewrites deleted pane state from stale leases: tabs the user closed are grafted back, close tombstones are erased, and duplicate pane leases accumulate. Canceled ticket STA-4268 (P0) states the mechanism exactly:
Root cause
reattachKnownPtystreats every non-terminated lease as live and callspersistPtyBinding, which had no way to say "bind only". Two of its branches then rebuild UI nobody asked for:src/main/persistence/loading-store/pty-binding-persistence.ts:133-143—if (args.incarnationId)unconditionally deletes the pane's close tombstone.:145-160— on a tab-not-found it mints one viacreateMinimalPersistedTerminalTab. The in-code comment names its only intended caller: "pty:spawn can beat the debounced writer." Spawn. There was no guard, so reattach took the same branch.Separately,
upsertSshRemotePtyLeasematched(targetId, ptyId)alone (src/main/persistence/leasing-ssh-ptys/ssh-pty-lease-operations.ts:34-36), so a new relay pty id on the second reattach minted a SECOND lease instead of updating the first, leaving the predecessor non-terminated with nothing to retire it.Revert history — please read before reviewing. #13326 landed this; #14361 reverted it (−23,088, 165 files); #14384 re-applied it (+23,281); #14395 reverted again — opened and merged nine seconds apart, empty commit body. Five readiness tickets filed against that revert (STA-4268, STA-4272, STA-4357, STA-4446, STA-4661) were all canceled while automated counsel re-proved the defect on three consecutive dailies; STA-4661 went through 4-seat counsel and was classified "release-blocking, revert-class."
grep -rn "mayCreate" src/returns nothing onmain— the mechanism is genuinely out of the tree. #13324/#13325 are attempt three, untouched since 08-09.The fix, and why this shape
+160 production lines across 5 files.
mayCreate, default true. When false, one pre-mutation check mirrors all four creating branches (mint a tab, mint a root leaf, split the root and graft a leaf, mint a layout) and returnsfalsewithout mutating, so a refusal leaves nothing half-written.The authority gate — the part both prior attempts lacked, and probably why both were reverted.
mayCreate: falsealone refuses in two situations: "the user closed it" and "the renderer has not published its layout yet". The second is routine on disconnect→reconnect and is almost certainly the revert(ssh): back out #13326 and #13928 — reconnect loses every tab #14361 tab-loss mechanism. The fence was not wrong; it was UNCONDITIONED. It is now passed only whenhasHostAuthoritativeTerminalMembership()says the persisted membership speaks for this worktree — reusing the function already guarding the same question atorca-runtime.ts:8608. Losing a tab is worse than keeping a duplicate, so an unauthoritative session still gets the creating write.Authority is read from the
localpartition because that is the partition this write lands in — it is local's absence being interpreted. But a pane thessh:<target>partition still holds is not gone, so it keeps its creating write; refusing there would strand a live pane behind a binding reattach can no longer reach. (This is the GH SSH host session partitions are written but never read — tab lists round-trip as empty and remote sync permanently deletes them #12721/Renderer and runtime disagree on which partition owns SSH worktree session state #12723 / STA-3980 partition split-brain. This PR does not fix it; it refuses to judge from one side of it.)findTerminalTabIdForLeaf— bind resolves the tab from the live layout instead of the lease's frozentabId. Only the leaf half of a pane key is remint-stable:detachTerminalPaneToTabmoves a live pane into a new tab, so a storedtabIdnames the tab the pane left. Identity vs location.Pane-keyed supersession — retires siblings on
(targetId, worktreeId, leafId)toexpired, guarded by the durable binding, which readslocalthenssh:<target>so it is correct whichever partition the binding landed in.On refusal the lease goes
expired, neverterminated, and the remote shell is left running.expiredrecords that this shell has no surface to reach it through;terminatedwould assert an exit nothing here observed, whichdocs/reference/ssh-execution-boundary.mdforbids.Evidence
A/B on this tree: disable the authority gate (
mayCreate = true) and the supersession call by hand.That
[ 'pty-0' … 7 more ]vs[ 'pty-9' ]is the lease-accumulation mechanism in miniature. The 4 that pass both ways are the over-refusal tripwires, which is the point of having them.Restored:
Honesty about scope — this is NOT the fix for the daily tab growth
The deterministic e2e repro (
ssh-lost-kill-tab-resurrection.spec.ts, PR 6 of this stack) is byte-identical before and after this change — not a partial improvement, no change at all. Instrumentation shows why: in that scenariorestoreReattachedPtyRuntimeis never called (CREATING TAB9 hits,reattach gate0,BYPASS0). The fence is on a path that bug does not take. Build provenance was verified positively, not by mtime:mayCreateappears 3× inout/main/index.jsfor the fenced build and 0× for every control run.This is a real, separately-provable defect with an A/B control behind it. It must not be claimed as the fix for the user report, and this PR does not claim it. PR 6 is the one that closes that.
Deliberately NOT done
upsertSshRemotePtyLease. Built, tested, and removed — its own test passed with the guard disabled, i.e. vacuous. Distinguishing "same lease" from "recycled id on a different shell" from lease state alone needs a relay-start identity, which would be a twelfth per-tab identity concept; the codebase already carries eleven (784 refs) that SSH-v3 Phase 3 deletes. Left as an in-code NOTE and a follow-up. This handles lease DIVERGENCE, not COLLISION.bindPaneShellfrom fix(ssh): one bind producer, so the superseded-pane fence is live on reattach (STA-3077 F) #13325. Its purpose is makingisSupersededPtyIdlive, and that fence does not exist inmain. It would have been a refactor plus a silently-ignoredmayCreate— TS drops excess props through spreads (verified), which is whymayCreateis passed here as a conditional spread rather than a plain property.sanitizeWorkspaceSessionTerminalRetirementsapplies every tombstone then clears the map on every session write, soterminalSurfaceTombstonesByPaneKeyis structurally always empty atpty-binding-persistence.ts:163. Guarding it would have been inert. Correction recorded here rather than shipped as dead code.Still unfixed, carried forward
attachIdentityMismatches(src/relay/pty-handler.ts:399) still comparestabId, andexpectedIdentityForLease(ssh-relay-session.ts:197) composes its paneKey from the frozentabId. That refusal maps toSSH_SESSION_EXPIRED, which authorises a respawn onto a shell just proved alive. #14384 fixed it;eb22e49reverted it; it never came back. It needs its own PR.The revert-class risk changes shape rather than disappearing
Both prior reverts (#14361, #14395) were for tab loss. The authority gate is what stops that
recurrence, and four of the twelve tests are over-refusal tripwires.
But a wrong refusal here has a different signature, and a reviewer should weigh it deliberately
rather than assume the old one is the only one: refusing to bind leaves the lease
expiredand theremote shell still running with no surface to reach it through — an orphaned remote writer, the
thread <uuid> already has an active writershape #16752's own body cites from a user report. Theuser does not lose a tab; they lose the ability to reattach to work that is still alive, and a later
reattach can collide with the orphan.
That is why refusal is gated on
hasHostAuthoritativeTerminalMembershipand on the pane beingabsent from both partitions, and why the lease goes
expiredrather thanterminated— the remoteprocess is deliberately left running so it remains recoverable.
Risk / blast radius
Main-process, SSH reattach path only.
mayCreatedefaults true, so every genuine-create caller (pty:spawn, stable-pane adoption, runtime spawn-commit) is unchanged by construction — enumerated below. Given the revert history, the specific risk to weigh is over-refusal losing a user's tab, which is what the authority gate exists to prevent and what four of the twelve tests assert directly.reattachKnownPtys→restoreReattachedPtyRuntime(:2247/:2548)reattachRejectedPty(:1960)pty:spawn→reattachSshPtySession→pty.attachattachStablePaneOwnerruntime/spawn-commit.ts:163There is no separate wake-sweep binder; sleep/wake re-enters via
reattachKnownPtys.How to verify
To reproduce the defect: set
mayCreatetotrueinssh-relay-session.tsand comment out thesupersedeSiblingLeasesForPane(operations, next, now)call inssh-pty-lease-operations.ts:139, then re-run — 8 of 12 fail.End-to-end verification
Specs this PR routes to
Seven specs — the widest of the stack, because this is the only level touching
src/main/ssh/. Undermain's router it routed to 5; #16746 addsssh-port-forward-lifecycleandssh-reconnect-tab-destruction.ssh-port-forward-lifecyclefailed in the full lane and was cleared — it passes onmainand passes at this stack tip in isolation (59.6s, same build); it is flaky only inside the full lane. See the verdict table below. Note the routing change is what put it in front of this PR at all: undermain's router this level would never have run it.Given this PR restores a twice-reverted mechanism, breadth here matters more than anywhere else in the stack. The reverts were both for tab loss, so the specs that matter most are the reconnect/restore ones —
ssh-docker-reconnect-pane-restore,ssh-reconnect-tab-destruction,ssh-cold-activation-restore.Lane result
Covered by the full Docker-SSH lane at the stack tip (below). The routed subset for this level can also be run directly:
The two lane failures, resolved — and one is now exempted:
mainssh-docker-bulk-open-freeze-reproTypeError: … reading 'workerIndex'atdocker-ssh-relay-target.ts:226ssh-port-forward-lifecyclessh-port-forward-lifecycle-evidence.ts:159waiting ongetByText('Ports')Port-forward was re-run at the same commit and build and passed in 59.6s. It is green on
main, green at the tip in isolation, and red only inside the full lane — it is the set's one@headfulspec and runs last. Called flaky in-lane rather than "unrelated": a real lane-ordering problem, pre-existing, and worth tracking.Build provenance
mayCreateis a new identifier — 0 occurrences inmain's source, which is the positive check that the fence is in the build. It lands in the main bundle:This count is load-bearing for the honesty section below: every red run cited in this campaign was verified at
mayCreate= 0, establishing those runs were against a build without this fence. A green claim made against a bundle showing 0 would be meaningless.Measured on the lane build:
mayCreate=3is this level's symbol; the other three prove the rest of the stack is in the same build.What is NOT covered — read this before approving
ssh-lost-kill-tab-resurrection.spec.ts(in fix(terminal): a close the host never heard must survive the reconnect #16752) is byte-identical before and after this change — not a partial improvement, no change at all. Instrumentation shows why: in that scenariorestoreReattachedPtyRuntimeis never called (CREATING TAB9 hits,reattach gate0,BYPASS0). The fence is on a path that bug does not take. This PR does not claim otherwise; fix(terminal): a close the host never heard must survive the reconnect #16752 is the fix for the user report.upsertSshRemotePtyLeasewas built, tested, and removed — its own test passed with the guard disabled, i.e. vacuous. Distinguishing "same lease" from "recycled id on a different shell" needs a relay-start identity, which would be a twelfth per-tab identity concept. Left as an in-code NOTE.localandssh:<target>before deciding a pane is gone — but the two owner maps still disagree.attachIdentityMismatchesstill comparestabId(src/relay/pty-handler.ts:399), andexpectedIdentityForLeasestill composes its paneKey from the frozen tabId (ssh-relay-session.ts:197). That refusal maps toSSH_SESSION_EXPIRED, which authorises a respawn onto a shell just proved alive. fix(ssh): reapply the reattach-identity work and stop the fallback fence stranding moved panes #14384 fixed it;eb22e49reverted it; it never came back. Needs its own PR.SSH_SESSION_EXPIREDerror class is lossy one layer up, and that is a separate defect from the one above:ssh-pty-session-reattach.ts:227-231rewrites the relay'sPTY "pty-1" not foundinto a bareSSH_SESSION_EXPIRED, soisPtyAlreadyGoneError's/PTY ".+" not found/cannot match andattachStablePaneOwner:242's already-correct fallback never runs. Owned bynwparker/ssh-07-absent-from-relay, stacked after this one. Not fixed here.sanitizeWorkspaceSessionTerminalRetirementsapplies every tombstone then clears the map on every session write, soterminalSurfaceTombstonesByPaneKeyis structurally always empty atpty-binding-persistence.ts:163. Guarding it would have been inert; recorded rather than shipped as dead code.Failing-first test
Yes — an A/B control on this tree rather than a revert, because the two halves interact.
Reproduce: set
mayCreatetotrueinssh-relay-session.tsand comment outsupersedeSiblingLeasesForPane(operations, next, now)atssh-pty-lease-operations.ts:139. Restored: 12 passed. The 4 that pass both ways are the over-refusal tripwires.