Repository navigation
fix(terminal): make close and handles incarnation-stable (STA-4327) - #14590
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe runtime tracks terminal handles by PTY incarnation and leaf association. It reuses matching handles during renderer recovery and invalidates stale handles when PTY identity, ownership, or incarnation changes. Single-pane terminal closure can use 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
⚔️ Resolve merge conflicts 💡
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: Pro Plus
Run ID: 24f3c415-258c-4e8b-8bc3-4d8146a1a0c5
📥 Commits
Reviewing files that changed from the base of the PR and between 9bb8836 and 5e0bb4fb710e21e90f6a7105140cff093fb600b9.
📒 Files selected for processing (3)
config/reliability-gates.jsoncsrc/main/runtime/orca-runtime-terminal-close-continuity.test.tssrc/main/runtime/orca-runtime.ts
2be9aa5 to
3cf8a37
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7821e92e-2194-4c00-bce5-885692ab0238
📥 Commits
Reviewing files that changed from the base of the PR and between 5e0bb4fb710e21e90f6a7105140cff093fb600b9 and 3cf8a37.
📒 Files selected for processing (3)
config/reliability-gates.jsoncsrc/main/runtime/orca-runtime-terminal-close-continuity.test.tssrc/main/runtime/orca-runtime.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c23a3828-17a1-4643-8fcd-8b4249455506
📒 Files selected for processing (11)
config/reliability-gates.jsoncsrc/main/runtime/orca-runtime-terminal-close-continuity.test.tssrc/main/runtime/orca-runtime.tssrc/renderer/src/components/Terminal.tsxsrc/renderer/src/components/terminal/initial-terminal.test.tssrc/renderer/src/components/terminal/initial-terminal.tssrc/renderer/src/lib/worktree-activation.test.tssrc/renderer/src/lib/worktree-activation.tssrc/renderer/src/store/slices/terminals-explicit-empty-hydration.test.tssrc/renderer/src/store/slices/terminals.tstests/e2e/terminal-tab-close-restart-persistence.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/runtime/orca-runtime-terminal-close-continuity.test.ts
- src/main/runtime/orca-runtime.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a11b0743-34c3-4541-829b-28e55a6515af
📒 Files selected for processing (1)
tests/e2e/completed-worker-retirement-resume.unit.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)
27701-27746: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winHandle
workspace_session_unavailablein the surface-based fast path.If
closeMobileSessionTab()throws this error aftercloseTerminalTab()succeeds, callthis.notifier?.closeTerminal(tabId)and continue PTY cleanup. Re-throw other errors.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6f5fcfdd-f8da-4961-9b95-3d467688bcaa
📒 Files selected for processing (13)
src/main/runtime/orca-runtime-terminal-close-continuity.test.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/window/attach-main-window-services.tssrc/main/window/terminal-tab-close-request-relay.test.tssrc/main/window/terminal-tab-close-request-relay.tssrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/lib/worktree-activation.test.tssrc/renderer/src/lib/worktree-activation.tssrc/renderer/src/store/slices/terminal-tab-id-hydration.test.tssrc/renderer/src/store/slices/terminals.tssrc/shared/terminal-tab-close.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/renderer/src/lib/worktree-activation.ts
- src/renderer/src/store/slices/terminals.ts
- src/renderer/src/lib/worktree-activation.test.ts
…ays re-seeds Review found the carve-out fires nondeterministically: the entry points disagree about `executionHostId` for the *same* local workspace — the sidebar derives `'local'` (use-worktree-card-activation-actions.ts:84 via getRepoExecutionHostId) while the Cmd+J palette (WorktreeJumpPalette.tsx:2520, :2896), keyboard cycling, and back/forward pass nothing — so `activeWorkspaceExecutionHostId === (opts ?.executionHostId ?? null)` flips on how you last opened the workspace. Host-qualifying the comparison was the wrong repair. The carve-out guards a state that closing a tab never produces: `leaveWorktreeIfEmpty` clears activeWorktreeId when the last renderable tab closes (TerminalPaneOverlayLayer.tsx:65-74), so there is no already-active emptied workspace to reselect. It only fires after hydration restores an emptied workspace as active — where suppressing re-seeds the original bug. Clicking the sidebar row of a blank workspace after a restart did nothing, which is the exact report this branch set out to fix. So the guard is removed rather than corrected: explicit activation always re-seeds, startup hydration never does. That restores pre-#14590 behavior wholesale for activation and makes the host asymmetry irrelevant to terminal creation. It also removes the local/remote divergence, since the runtime path's ensureWebRuntimeWorktreeTerminalAfterWake never had a reselect guard either. Reverts the folder-workspace host qualification from 3113610 (the predicate it fixed no longer exists) and keeps its coverage. Tests now pin: explicit activation, the restored-active workspace, host-passed vs host-omitted equivalence, folder same-host and cross-host, the hydration path staying empty, and a browser-only workspace not gaining a terminal. Mutation-checked both ways — forcing the tombstone off fails the hydration case, ignoring the flag fails six.
The previous commit fixed the two editor-opening callers but my sweep only matched openFile/openDiff/setActiveTab, so it missed three call sites that activate purely to route and then create a *browser* tab: - terminal-file-open-routing.ts openHtmlFileInBrowser -> createBrowserTab - workspace-port-actions.ts -> browser tab creation - FeatureWallBrowserAction.tsx -> openNewBrowserTabInActiveWorkspace Same regression: following an HTML file link or a port into a workspace whose last terminal was closed spawned a shell beside the browser tab, and on a remote workspace that is a real SSH PTY. All three now pass providesInitialSurface. Also pins the passive half's wiring. Terminal.tsx is the side of the contract that must keep honouring the tombstone, and its only end-to-end cover is an e2e that did not run on this PR. Mounting a 2892-line component is not worth it, but this repo already asserts un-mountable wiring as source text (app-startup-routing.test.ts and the startup ordering tests), so initial-terminal-wiring.test.ts asserts the effect still derives the tombstone from the active row and passes that identifier — not a literal — into shouldAutoCreateInitialTerminal. Dropping the argument, the established way to re-introduce #14590's bug, now fails a test that runs. Renames the cross-host folder test to say what it actually checks (the shared row is re-seeded, not that the tab lands on the requested host) and records why: the host-blind resolver makes that tab resolve local, which is pre-existing and out of scope. Extends the close-path comment to include closeTabPreservingPty and to note the runtime-owned exception holds only while that session is live.
…icitly activated PR #14590 made an explicit empty tabsByWorktree row a durable closed-last- terminal tombstone, but the same gate sat in the activation path, so waking a sleeping/emptied workspace or clicking automations' Resume gave a blank tab bar. Explicit activation now re-seeds by default; passive startup hydration still honours the tombstone via Terminal.tsx. Callers that activate only as a prelude to opening their own surface (an editor file, browser tab, diff panel, or agent tab) pass providesInitialSurface: true, which reproduces main's pre-#14590 behavior at that call site. The full activation call-site census lives in worktree-activation-surface-caller-wiring.test.ts, which fails if any opt-out is dropped or a new one is added without classifying it there; the census assertion is bound to an actual activateAndReveal* call with comments stripped first, so commenting the flag out in place fails it. The option is also plumbed through activateAndRevealWorkspace and activateAndRevealFolderWorkspace so both workspace shapes share one contract.
ELI5
A — close said “done,” then an empty shell appeared
Two independent gaps combined. Orca killed the shell but acknowledged before the tab removal was durably saved. After the tab was correctly removed, reload hydration erased the meaningful empty row, so the “new workspace” fallback created a brand-new shell with new IDs. The closed PTY did not come back; Orca mistakenly made a replacement default terminal.
B — handles rotated
A renderer refresh discarded the CLI handle before checking whether the provider still reported the same PTY incarnation. Orca now keeps the handle when PTY ID and incarnation are unchanged. A real replacement incarnation still makes the old handle deterministically stale; that safety fence is expected and preserved.
What changed
terminal.close.tui-idlewaiters if the idle transition arrives during the reload gap.terminal-session.explicit-close-retirement.No RPC field, stream opcode, persisted schema, polling loop, retry loop, provider listing, subprocess, or new wire traffic was added.
Red / green / disabled proof
Runtime close + incarnation oracle
Byte-identical SHA-256:
cd248b67cc10ef64f2def315b86c3b0236b102639d03c65a0c5d9519e538d3af0b62333cf19bb8836bb63cf8a37447Final code candidate
121e112d77passes the expanded 6/6 oracle, including atui-idletransition during renderer reload.Persisted-empty/default-terminal oracle
Byte-identical SHA-256:
3b0949eef8b792cf5b09cfa55341f4216c08714f158e4b132e988e8114636cea0b62333cf19bb8836bb6121e112d77All four disposable matrix worktrees used the same oracle bytes and were removed afterward.
Headed Electron / CDP proof
Isolated local macOS app and fixture repo; no user terminal was touched.
term_49a01c5f-1db1-4e3c-b115-922261f8e031, PTY suffix31722a8e, incarnation29055fb9-6319-44af-bb5c-c583b2ce3533, tabdb94668f-16d8-46c2-aefb-dba4c5e52f6a.terminal.closereturnedok:true,ptyKilled:true; the exact shell process died.Validation
pnpm run test:e2e -- tests/e2e/terminal-tab-close-restart-persistence.spec.ts --workers=1— 1 passed; empty after full restartorca-runtime.test.ts+web-runtime-session.test.ts+ continuity — 1,122 passed, 1 unrelated skippnpm run typecheck— passedpnpm run lint— passed, including native/type-aware audits, max-lines ratchet, reliability manifest, skill and localization verificationPerformance review: one empty row per persisted known workspace; the React effect depends only on active-row presence. No timers, polling, provider fanout, subprocesses, process scans, retries, or hot-path network calls were added.
Risks and gaps
Linked issue
Fixes #14524
Linear: https://linear.app/stably/issue/STA-4327/terminal-close-returns-oktrue-but-the-tab-respawns-as-an-empty-shell
Checklist
Do not merge; awaiting review and CI.