Repository navigation
Conversation
…onto it A tab opened right after an SSH reconnect has no PTY yet, so the reconnect's pane-retry ledger bumps its generation and remounts the pane while its first spawn is still in flight. Main's pane-spawn reservation hands the remounted pane the same PTY, and the disposed first transport then killed it as an orphan. A proven exit closed the tab; a synthetic exit left it bound to a dead shell that never answered input. The disposed-spawn kill now asks the pane surface first and skips the kill while the tab still exists and its layout still names the leaf. A genuinely ownerless PTY is still killed. Measured on the Docker-SSH lane: 4-5 failures in 10 rounds before, 0 in 36 after. The new e2e spec runs six rounds and fails in round 2 with only the guard removed. Fixes #17692 Fixes #17047
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (12)
🚧 Files skipped from review as they are similar to previous changes (12)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe change adds worktree-aware retention for disposed PTY spawns during pane remounts. Transport cleanup retains eligible spawns and kills rejected or ownerless spawns. Tests cover retention state, delayed spawn resolution, and admission failures. A six-round Docker SSH E2E test verifies live shells in newly opened tabs after reconnects. Documentation records resolved and unresolved cases. Priority: ➖ Normal — Impact reflects medium issue severity. Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to This change retains eligible PTY spawns during SSH reconnect remounts to keep newly opened terminal tabs live while continuing to clean up ownerless or rejected PTYs. No current merge-blocking risk is established. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The changes address the reconnect-related new-terminal failure in Full details: Docstring CoverageExplanation Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 11 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 2d0be2ea-a612-484e-aae7-c26ceac49ba4
📒 Files selected for processing (11)
config/scripts/run-ssh-docker-e2e.mjsdocs/reference/ssh-reconnect-source-recovery.mdsrc/renderer/src/components/terminal-pane/ipc-pty-connect.tssrc/renderer/src/components/terminal-pane/pty-connection-fresh-spawn-guards.test.tssrc/renderer/src/components/terminal-pane/pty-connection/disposed-spawn-retention.test.tssrc/renderer/src/components/terminal-pane/pty-connection/disposed-spawn-retention.tssrc/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.tssrc/renderer/src/components/terminal-pane/pty-transport-detach-attach-handoff.test.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tstests/e2e/ssh-reconnect-new-tab-liveness.spec.tstests/e2e/ssh-reconnect-tab-destruction.spec.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
A fix for the "tab opened right after an SSH reconnect comes up dead" class of bugs (#17692 tab closes immediately, #17047 blank shell). The disposed first transport's orphan-kill in retireFreshSpawn was landing on the PTY that main's pane-spawn reservation had already handed to the remounted successor. The kill now consults a retainDisposedSpawn callback supplied by the pane, which decides from the live store whether the pane surface still exists.
ipc-pty-connect.ts—retireFreshSpawngates its PTY kill onretainDisposedSpawn?.() !== true(absent/false keeps the existing kill; backwards-compatible).disposed-spawn-retention.ts(new) —shouldRetainDisposedPaneSpawn: retain iff the tab still exists intabsByWorktreeand (when a layout exists) the layout still names the leaf; otherwise the PTY is genuinely orphaned and is killed.pty-input-recovery.ts— wires the callback into every pane's transport options, readinguseAppStore.getState()at decision time.pty-transport-types.ts— the optionalretainDisposedSpawntransport option.tests/e2e/ssh-reconnect-new-tab-liveness.spec.ts(new) — six rounds of reconnect → open tab → assert survival, binding, andecholiveness; registered inrun-ssh-docker-e2e.mjs.
Verified the core claim against the main-side reservation (spawn.ts / spawn-options.ts): the reservation hands the same PTY only when the (worktree, connection, paneKey) owner key matches, which implies an identical leafId — so the retention predicate's use of the disposed session's leafId is consistent with the case the fix targets, and a divergent leafId correctly falls through to the existing kill. Triage found no parallel disposed-spawn orphan-kill path (the remote-runtime transport has its own recovery lifecycle and never calls connectIpcPty), so there is no uncovered sibling of this bug. The unit tests assert exact outcomes (toBe(true)/toBe(false)/not.toHaveBeenCalled()) and the documented mutation testing shows each is a real tripwire, not theatre.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
The round captured activeTabId after opening; if the open ever left the prior (already live) tab active, the PTY and echo checks would pass against it. Record the prior id and assert the new one differs. Scope the resolved note to the measured cause: the disposed-spawn kill. The persistent no-reconnect state in #17047 was not reproduced on it and stays open.
The retention guard was applied to every caller of the shared retirement closure, including the one where a live transport refuses the id it was handed (admitPtyId, the direct-SSH retry admission). That transport is the pane's only one, so nothing else can own the PTY, and the guard always answered "retain" there because the pane doing the refusing is live. Every refused retry PTY would have leaked — the case #11003 added the kill for. Split the two retirements: retireDisposedSpawn consults the pane surface, killFreshSpawn does not. The admission tests now build the transport with retainDisposedSpawn supplied, as installPtyInputRecovery does, so they fail on the previous guard. Exclude a worktree being deleted from retention: its tabs are still in the store, but the teardown kills from the bound-id ledger, which never learned an in-flight spawn's id. Measured the preserved tab in ssh-reconnect-tab-destruction rather than asserting it: 2 misses in 5 and 1 in 6 on this fix, with a live shell on the host and an empty pane — a different shape, recorded as still open. The new spec's loop pointed at a real Ubuntu host (ssh openclaw) was 4/4 live.
There was a problem hiding this comment.
ℹ️ No critical issues — the P1 split is correct and well-tested; one minor observation inline about the worktree-deletion exclusion.
Reviewed changes
Since the prior Pullfrog review (1cc6a79):
- Split the disposed-spawn retirement into two closures.
retireFreshSpawnbecamekillFreshSpawn(the original #11003 kill, unconditional) plusretireDisposedSpawn(consultsretainDisposedSpawn). TheadmitPtyIdrefusal path now callskillFreshSpawn, so a live transport that refuses its own fresh-fallback id is still killed — closing the P1 where the first revision would have leaked every refused direct-SSH retry PTY. - Added a worktree-deletion exclusion.
shouldRetainDisposedPaneSpawnnow takes aworktreeIdand returns false whiledeleteStateByWorktreeId[worktreeId].isDeleting, so a PTY spawned during teardown isn't retained. - Hardened the refusal-path tests. The two reattach-admission tests build the transport the way
installPtyInputRecoverydoes (retainDisposedSpawn: () => true) and still assert the refusal kills — they fail on the first revision's merged guard. - Made the liveness probe assert a new tab (records the active tab id before opening and asserts it changed) and dropped the un-reproduced #17047 claim in favor of a docs note.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| tabId: string, | ||
| leafId: string | ||
| ): boolean { | ||
| if (state.deleteStateByWorktreeId?.[worktreeId]?.isDeleting) { |
There was a problem hiding this comment.
The isDeleting exclusion keys by the bare worktree id, but deleteStateByWorktreeId is keyed host-qualified (hostId|id) for any deleted target carrying a hostId — every SSH/remote worktree (markWorktreesDeleting → getDeleteStateTargetKey, fed target.hostId ? target : target.id from worktree-delete-execution.ts). For a remote worktree the lookup misses, so the exclusion silently no-ops and a mid-spawn PTY is retained (leaked) rather than killed during teardown. Still leak-over-kill and reclaimable — not blocking — but the exclusion's stated purpose isn't met for SSH.
Technical details
# isDeleting exclusion no-ops for host-qualified (SSH/remote) worktrees
## Affected sites
- src/renderer/src/components/terminal-pane/pty-connection/disposed-spawn-retention.ts:24 — `deleteStateByWorktreeId?.[worktreeId]` uses the bare `session.deps.worktreeId`.
- src/renderer/src/store/slices/worktrees/teardown/worktree-delete-state.ts:17 — `getDeleteStateTargetKey` returns `getWorktreeHostIdentity(target)` when `target.hostId` is set.
## Required outcome
- The exclusion must also fire for an SSH/remote worktree being deleted, or the reason it is intentionally local-only must be documented.
## Suggested approach (optional)
- Look up both the host-qualified key and the legacy bare key (mirroring `getDeleteStateForWorktreeHost`), using the host id already available on the session.
## Open questions for the human (optional)
- Does the runtime `terminal.stop` teardown already reclaim remote PTYs, making the renderer-side exclusion unnecessary for SSH?|
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. |
|
Superseded by #22578. It ports this PR's disposed-spawn retention fix and its unit tests onto current main, with credit to this PR. It came from a crash scan 22 user report of new SSH tabs getting killed, and it also adds tab-lifecycle breadcrumbs. The Docker SSH e2e specs from this PR were not ported. Thanks @nwparker for the original diagnosis and fix. |
…as still spawning (#22578) * fix(terminal): a pane disposed mid-spawn no longer kills its successor's shell A new terminal tab whose pane remounts while its first pty:spawn is in flight is handed the SAME PTY by main's pane-spawn reservation. The disposed first transport then killed that PTY as an orphan, so the tab closed on pty-exit (focus fell back to tab 1) or stayed bound to a dead shell. Reported on SSH worktrees (scan 22). A transport destroyed mid-spawn now asks the pane surface first and keeps the PTY while the tab exists, the worktree is not being deleted, and any layout still names the leaf (leak-over-kill). A live transport refusing the id via admitPtyId still kills unconditionally (#11003). Adds rate-limited, id-hashed crash breadcrumbs for the next report: terminal_fresh_spawn_retired (killed vs retained), terminal_tab_pty_exit (host kind, ms since spawn, synthetic), terminal_active_tab_auto_move (active-terminal repair, createTab orphan sweep). The two duplicated tab pty-exit handlers now share handleTerminalTabPtyExit, and the FNV id hash used by two crumbs moves to crash-breadcrumb-id-hash.ts. Ports and supersedes #19386 (disposed-spawn-retention and its unit tests, credit to its author); its Docker SSH e2e specs are not included. * fix(terminal): scope spawn retention to its host and keep the PR focused --------- Co-authored-by: m4air <[email protected]>
|
Closing as fixed: #22578 landed this fix (a remounted new SSH tab keeps the shell its old pane was still spawning). |

ELI5
When Orca reconnects to an SSH host and you open a new terminal right afterwards, the new terminal sometimes came up dead: either the tab vanished a moment later, or it showed a prompt but ignored everything you typed. Two things were racing over the same shell — the reconnect asked the fresh pane to "try again", and the first attempt, on its way out, killed the shell the retry had just been handed. This change stops the first attempt from killing a shell that the tab still owns.
Which shapes this covers. #17692 was triaged into two shapes: (a) the new tab deleted from
tabsByWorktree, (b) the tab surviving with a bound PTY and a painted prompt but dead to input. Both are covered here, because both are the samepty.killon the successor's PTY — (a) when the relay reports a proven exit andhandlePtyExitcloses the tab, (b) when only the synthetic-1arrives. The e2e spec asserts them separately per round (survives / binds / answersecho). What this does not cover: a persistent state where every new terminal on a long-lived connection is blank until Orca restarts, with no reconnect involved — see the #17047 note under Linked Issue.What Changed
src/renderer/src/components/terminal-pane/ipc-pty-connect.ts— the "spawn resolved after the transport was destroyed" branch used to kill the PTY unconditionally. It now asks the transport'sretainDisposedSpawncallback first and only kills when the answer is nottrue. The two retirements are now separate closures:retireDisposedSpawn(transport destroyed mid-spawn; consults retention, because a remounted successor may hold the same id via main's pane-spawn reservation) andkillFreshSpawn(a live transport refusing the id viaadmitPtyId; kills unconditionally, because that transport is the pane's only one and nothing else can own the PTY — the feat: bound direct SSH reconnect fan-out and recovery #11003 behaviour). The first revision of this PR routed both through one guard, which would have leaked every refused direct-SSH retry PTY in production.src/renderer/src/components/terminal-pane/pty-connection/disposed-spawn-retention.ts(new) —shouldRetainDisposedPaneSpawn(state, worktreeId, tabId, leafId): keep the PTY while the worktree is not being deleted, the tab still exists intabsByWorktree, and, if a layout exists, it still names the leaf. Otherwise the PTY is genuinely ownerless and the existing kill stands. The worktree-deletion exclusion is there becauseshutdownWorktreeTerminalskills from the bound-id ledger, which never learns an in-flight spawn's id.src/renderer/src/components/terminal-pane/pty-connection/pty-input-recovery.ts— wires the callback into every IPC transport a pane creates, reading the live store at decision time.src/renderer/src/components/terminal-pane/pty-transport-types.ts— the optionalretainDisposedSpawntransport option.tests/e2e/ssh-reconnect-new-tab-liveness.spec.ts(new, registered inconfig/scripts/run-ssh-docker-e2e.mjs) — six rounds of reconnect → open tab → assert survives, binds, and answersecho.tests/e2e/ssh-reconnect-tab-destruction.spec.ts— the "not asserted" note now records what was measured on this fix for the preserved tab (see Testing): still not deterministic, and a different shape, so the assertion stays out.docs/reference/ssh-reconnect-source-recovery.md— the section is marked resolved for the one measured cause (a newly opened tab), and the preserved-tab shape the section originally recorded is kept open with the sharper measurement.pty-transport-reattach-admission.test.ts— the two "retires a rejected fresh fallback" tests now build the transport the wayinstallPtyInputRecoverydoes (withretainDisposedSpawnsupplied and answeringtrue), so they fail on the first revision of this PR's guard and pass on this one.Why
The cause, measured
The clustered hypothesis pointed at the direct-SSH snapshot apply window (
remote-workspace-snapshot-apply.ts) and the merge's host-unknown branch. That is not where the loss happens. Instrumenting the store,pty.kill, andpty:exiton the Docker-SSH lane showed:retryDirectSshTerminalPanes) bumps itsgenerationand the pane remounts while its firstpty:spawnis still in flight.spawn-begin.ts) sees the same(worktree, connection, paneKey)and hands the remounted pane the SAME PTY the first spawn is about to receive.retireFreshSpawninipc-pty-connect.tscallspty.kill(id)on the id the successor is bound to.One kill, two symptoms. When the relay reported a proven exit (
code 0),handlePtyExitclosed the tab (closeTab reason=pty-exit) — the "tabs close immediately" shape of #17692. When only the synthetic-1arrived, the tab stayed bound to a dead PTY with a painted prompt that never answered — #17692's second shape, which also looks like #17047's symptom but was only ever reproduced here with a reconnect.It needs no second reconnect and no snapshot apply. It reproduces with one reconnect and one new tab, at 40-50% per attempt.
Why this fix and not another
retireFreshSpawnexists to reclaim a genuinely orphaned PTY (pane closed mid-spawn). That case is preserved: no tab, or no leaf in the layout, still kills.docs/reference/ssh-execution-boundary.md: the worst case of a wrong "retain" is a PTY the relay's idle sweep reclaims later; the worst case of a wrong "kill" is the user's shell.Boundaries
tabsByWorktreeis keyed by workspace key for both; the leaf check readsterminalLayoutsByTabId, which is workspace-agnostic.retireDisposedSpawnruns for local spawns. Local panes are remounted mid-spawn far less often, but the same reasoning applies and the same retention rule is correct there.retainDisposedSpawnis consumed only bycreateIpcPtyTransport(local IPC and direct SSH).createRemoteRuntimePtyTransporthas no disposed-spawn kill to guard and ignores the option.Linked Issue
Fixes #17692
This PR does not close #17047, and must not. The link is inferred, not measured: neither reporter mentions a reconnect, the repro here requires one, and the bound-but-dead shape #17047 describes was never observed on this mechanism. The closer candidate is the preserved-tab gap recorded under Testing (live shell on the host, empty pane), which this PR does not fix. The first commit's message still carries a
Fixes #17047line; merge with an explicit squash body (gh pr merge --squash --subject … --body …) so that line never reaches the auto-close parser.Related: #17047 — deliberately not claimed. That report is a persistent state on a long-lived connection (every new terminal blank until Orca restarts, no reconnect mentioned). Nobody has reproduced it, and the only mechanism measured here requires a reconnect to overlap the tab's first spawn. The symptom of shape (b) is identical, so #17047 may share the cause if the user's connection was silently dropping and reconnecting, but that is a hypothesis, not a reproduction. The docs note records it as open.
Visual Proof
N/A — terminal liveness across an SSH reconnect; the evidence is the per-round table below, not a screenshot.
Testing
All measurements on the Docker-SSH lane (
tests/e2e/fixtures/docker-ssh-relay,ORCA_E2E_SSH_DOCKER=1), macOS host, headless Electron. Each round: reconnect, immediately open a tab, then assert the tab survives, binds a PTY, and a writtenecho MARKERproduces output.Before (main at 2265fce, one reconnect + one new tab per round):
Both symptom shapes appeared in the same runs, from the same
pty.killon the successor's PTY. Controls: waiting for the reconnected pane to rebind before opening the tab was 8/8 live, i.e. the bug needs the tab's spawn to overlap the reconnect.After (this branch):
ssh-reconnect-tab-destruction.spec.tsRe-verified after review changes (7e6def8, fresh worktree, fresh
electron-vite build --mode e2e, same Docker-SSH lane):ssh-reconnect-tab-destruction,--repeat-each=2true, rebuilt, new spec rerunsurvived: false, ptyId: null(shape (a) on the instrument)Same new spec with only the guard disabled (
retainDisposedSpawn?.() !== true→true), rebuilt and rerun: fails in round 2 (the new tab never bound a PTY) — reproduced independently in the re-verification above. Six rounds is enough to separate the fix from a lucky run.Per-regression mutation testing (each mutation against the one assertion written for it, all four caught):
retainDisposedSpawnguard from the killpty-transport-detach-attach-handoff.test.ts› keeps a fresh spawn that resolves after destroy when the pane surface still owns ittrueonce the tab exists)disposed-spawn-retention.test.ts› kills the PTY when the leaf was removed from a split layoutdisposed-spawn-retention.test.ts› kills the PTY when the tab is gone from every worktreepty-input-recovery.tspty-connection-fresh-spawn-guards.test.ts› lets a disposed spawn survive while the pane surface still exists in the storepane.idinstead ofdeps.tabIdpty-connection-fresh-spawn-guards.test.ts› lets a disposed spawn survive while the pane surface still exists in the storeAll five re-run at 7e6def8; each mutation fails exactly the named test and nothing else (30 → 29 pass). The e2e spec's distinct-tab assertion (CodeRabbit) is a guard on the probe itself: without it a round could measure the prior, already-live tab.
pnpm tc,pnpm run check:code-quality:changed,oxfmtclean.pr-e2e-gate-contract.test.mjspasses with the new spec claimed byrun-ssh-docker-e2e.mjs.Remediation round (independent verifier's findings; fresh worktree, fresh
electron-vite build --mode e2e):src/renderer/src/components/terminal-pane(442 files, 4231 tests)pnpm tc(all projects),check:code-quality:changed,oxfmt --checkssh-reconnect-new-tab-livenessssh-reconnect-tab-destruction(as committed)ssh openclaw, Ubuntu 24.04, scratch probe = the new spec's loop pointed at the user's ssh-config host)pty2:…:2through:5Per-regression mutation controls on the remediation (each against the assertion written for it):
pty-transport-reattach-admission.test.ts› retires a rejected fresh fallback… and › surfaces rejected fresh fallback retirement… (2 fail, 15 pass)retireDisposedSpawnif (true))pty-transport-detach-attach-handoff.test.ts› keeps a fresh spawn that resolves after destroy… (1 fail, 26 pass)isDeletingexclusion dropped from the predicatedisposed-spawn-retention.test.ts› kills the PTY when the worktree is being deleted… andpty-connection-fresh-spawn-guards.test.ts› lets a disposed spawn survive…tabIdasworktreeIdpty-connection-fresh-spawn-guards.test.ts› lets a disposed spawn survive…Preserved-tab liveness (verifier P2, docs) — measured rather than asserted. A probe that selects the preserved tab after the second reconnect and writes
echo MARKER | tee /tmp/MARKERfailed 2 of 5 and 1 of 6 on this fix. The miss is a different shape from the one fixed here: the pane binds a PTY, the shell is alive on the host (theteefile exists with the marker), and the pane's xterm holds zero bytes before and after the write — an output-delivery gap, not a killed shell. Selecting the tab first does not recover it. So the assertion stays out of the spec, the section stays open for that shape in the docs, and it is the closer candidate for #17047's "live connection, blank new pane" report.Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Review changes in 7e6def8: the e2e spec now records the active tab before
openTerminalTabInActiveGroupand asserts the id changed (CodeRabbit's finding); the#17047claim is dropped for lack of a reproduction; the docs note says which shape stays open.The clustering note asked for the two shapes to be treated as two assertions. They are: the e2e spec asserts survival, binding, and liveness separately per round, and the before table records them separately. The snapshot-apply TOCTOU lead (
mergedbuilt from a stalestate) was checked and is real as a code smell, but it is not on the path this bug takes — the deletion trace goes throughpty-exit → closeTab, never throughhydrateTabsSession. Left alone to keep this PR to one cause.Residual, not attributed to this PR: on the PR head, splitting a tab immediately after opening it right after a reconnect lost the split (
{panes: 1, bound: 1}) in about 2 of 18 review rounds; a control passed. Same reconnect-remount window, no layout code touched here. Recorded in the docs note; worth its own issue.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)