Repository navigation
feat(terminal): main's exit record for a kept pane, its capability-gated publication and one restart - #22953
feat(terminal): main's exit record for a kept pane, its capability-gated publication and one restart#22953brennanb2025 wants to merge 48 commits into
Conversation
… transaction A renderer save cannot shrink terminal membership once main owns a repo's topology, so desktop tab and pane closes, CLI split-pane closes and mobile split-pane closes only became durable when the killed process's exit retired the surface. A close whose kill failed or threw, or whose exit was never certified, came back after a reload. Every close now reaches closeTerminalSurface: the renderer sends an explicit intent for user and cleanup closes, the CLI and mobile split-pane closes commit the pane after their stop, and the headless and relayed mobile closes reuse the same commit. A failed flush keeps the in-memory removal and no longer cancels the kill. Exit retirement is unchanged.
…osed A CLI or mobile close of one pane in a split commits the pane in main, but the desktop kept showing it until reload when no exit arrived to remove it. The close now sends a leaf-addressed notice: a mounted pane closes by leaf id, and a parked tab collapses its stored layout. Addressing by leaf makes the notice and the renderer's exit handling no-ops after each other, which replaces the numeric pane-id notice that could close the whole tab when the exit won.
A leaf-addressed close fell through to the whole-tab close whenever main's layout no longer held that leaf as one of several. Main's exit handling retires an exited split pane from the saved layout, so closing that pane afterwards (the exited-pane overlay's Close, or a CLI close whose stop delivers the exit first) removed the whole tab, live sibling included, and the next renderer save could not restore it. A pane close is now a no-op unless its leaf is in a multi-pane layout. Also updates two mobile split-close assertions to expect the leaf-addressed notice, and adds a test that a relayed mobile close of a renderer-listed tab still reaches the renderer's pin guard.
The existing CLI split test resolves its handle through the renderer graph, so the branch that closes a runtime-owned pane by its PTY handle had no test failing without its commit.
…ted publication and one restart Main holds an in-memory exit record per kept leaf. Paired clients that negotiate session-tabs.terminal-exit-state.v1 see the leaf as exited; every other client gets today's retired projection. Activating an exited leaf restarts it as a plain shell (a probe does nothing), routed to the desktop pane that holds it or spawned through the runtime. The desktop mirrors the records, so a remount or window reload shows the exit instead of spawning. Nothing writes a record yet.
…nts' into brennanb2025/terminal-exit-record
There was a problem hiding this comment.
ℹ️ No critical issues — two rough edges inline, one forward-looking clearing asymmetry, and a couple of nitpicks.
Reviewed changes — read the full 40-file diff at head 852c12d, plus two focused re-checks of the record lifecycle and the desktop restart route.
- Main-side exit records — new in-memory
TerminalExitRecordsmap keyed by leaf, ended on rebind (releaseForBinding), on the close transaction (clearLeaves), or with main. - Capability-gated publication —
exitedis attached only when a terminal tab has no live handle;projectSessionTabTerminalExitsreturns the payload untouched for clients advertisingsession-tabs.terminal-exit-state.v1and retires the leaf (omit + proof, version preserved) for everyone else. - One restart —
restartExitedTerminalSurfaceroutes a desktop-held pane tonotifier.restartExitedTerminaland a headless pane to a plain-shell runtime spawn;activateMobileSessionTabchecks the record before both the materialize and focus branches. - Desktop mirror and mount —
terminalExitRecords:list/:changedIPC, the renderer store slices, and a pane-mount handler that synthesizes the exit and skips spawning. - Renderer restart consumption — a new effect drains
pendingExitedTerminalRestartLeafIdsintohandleRestartExitedPane.
ℹ️ A record for a non-UUID (pane:N) leaf can never be cleared
Every path that clears a record is UUID-gated, while every path that reads one accepts any leaf id. registerPty only calls releaseForBinding when paneKey is non-null, which requires isTerminalLeafId(binding.leafId) (a UUID) — and the spawn plumbing only passes a binding when the leaf id is a UUID in the first place. On the tab-close path, collectPersistedTerminalLeafIds filters to UUID leaves too. But getTerminalSurfaceExit(tab.leafId), activateMobileSessionTab, and restartExitedTerminalSurface read terminalExitRecords.get(leafId) for whatever leaf id the snapshot carries, and the projection host explicitly supports legacy pane:N leaves. If the follow-up producer ever writes a record for a legacy leaf, that leaf stays exited forever and every user open routes a restart at a live pane.
Technical details
# Legacy leaves are read but never cleared
## Affected sites
- `src/main/runtime/orca-runtime-register-pty.ts:91-93` — `if (binding && paneKey)`; `paneKey` is null for a non-UUID leaf, so `releaseForBinding` is skipped.
- `src/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.ts:104-108` — tab-close path clears only `collectPersistedTerminalLeafIds(...)`, which filters on `isTerminalLeafId` (UUID).
- `src/main/runtime/mobile-session-layout-projection.ts:12-40` — `collectPersistedTerminalLeafIds` drops non-UUID leaves.
- `src/main/runtime/orca-runtime-prune-mobile-session-tab-group-layout.ts:97-104` and `orca-runtime-perform-mobile-session-pty-records-refresh.ts:102,177` — reads accept any leaf id; the projection host maps legacy `pane:N` pane keys.
## Required outcome
Either the follow-up producer must only write records for UUID leaves, or `releaseForBinding`/`clearLeaves` must clear by leaf id regardless of whether the binding carried a UUID pane key form.
## Open questions for the human
Can the exit disposition that writes the first record ever see a legacy `pane:N` leaf, or is every kept leaf guaranteed to be a UUID by then?ℹ️ Nitpicks
- No test exercises the new effect that consumes a routed restart end to end (a mounted pane draining
pendingExitedTerminalRestartLeafIdsintohandleRestartExitedPane); only the store actions are covered. The author disclosed this, but it is the linchpin of the desktop restart. onRestartExitedTerminalis dropped if it arrives beforelistTerminalExitRecords()resolves, becauserequestExitedTerminalRestartno-ops without a mirrored record. That is a silent no-op rather than the "mount spawns fresh" gap the PR documents, so a phone-triggered restart during a reload can be lost.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…d for a pane Every mounted terminal pane subscribes to the pending-restart map, and each push of main's exit records rebuilt it and the record map, so an exit on any leaf re-rendered every pane. An unchanged push now keeps both references, and a repeated restart request for the same leaf publishes nothing.
… to it The effect is the desktop's only consumer of a routed restart. The test drives the real hook: a request for the pane's exited leaf runs one plain-shell restart and is consumed, and a request for another pane's leaf stays pending.
…that pane `orca terminal close <handle>` on one pane of a split used to close the whole tab, live sibling included, whenever that pane's stop could not be confirmed (for example an unreachable SSH host). An unconfirmed stop is unverifiable, not a reason to drop siblings: the close now commits only that leaf, tells the renderer to drop that leaf, and leaves the owed kill to the controller's existing SSH pending-kill path. On a host where no renderer lists the tab, main now also removes the closed pane from the paired-client snapshot (with its retirement proof), since no exit may arrive to do it.
…ription on every pane The routed-restart effect subscribed every mounted terminal pane to the pending restart map, which broke the pinned per-pane listener budget and hook-order guard. The request is now consumed by a small component that is mounted only while a pane shows an exit. It is rendered outside the overlay's active-tab gate, so a restart routed to a background tab still runs.
…s dead process's ids
A capable client's `exited` carried the dead process's pty id, incarnation id and
runtime handle. Anything published becomes a permanent wire contract. The
client-facing type is now {exitCode, cause, exitedAt}, and main's record keeps
the ids. The per-client projection is the one step that reads past the client
shape: it strips the ids for capable clients and builds an older client's
retirement proof from them. An older client's exact retirement now always
matches, so it can never be left a handle-less leaf that reads as a terminal
starting forever.
Tests: the capable payload carries none of the ids; an older client's view
equals the retirement it got before main kept the leaf; a closed and reopened
leaf shows no stale exit.
… pty:exit On both the local daemon path and the SSH relay path, a record written inside onPtyExit is pushed to the renderer ahead of that exit's pty:exit. A remounting pane therefore reads the record instead of spawning into the leaf.
…e-render an exited pane Live panes no longer subscribe to routed restarts at all. An exited pane reads only its own leaf's request, so another leaf's exit or restart request leaves it untouched.
…not by the publication The restart went to the desktop whenever the worktree's snapshot was not headless. A runtime-owned tab, one with a serve or SSH binding or one the renderer graph does not hold, can sit inside a desktop-published snapshot. Its restart request reached no pane, and the tap did nothing. The route now uses the same ownership test the runtime already applies to teardown.
…ecord Clearing a closed leaf's record republished the worktree's session tabs right away, before the close's removal reached the snapshot. For a moment, clients saw the closed leaf listed as a handle-less terminal, and an older client saw a retired leaf come back. A close now updates only the desktop mirror, and the removal's publication carries both the leaf's absence and the cleared record.
…runtime state Records for a removed worktree lived until main exited. The worktree-removal funnel, which every managed, orphan and folder removal reaches, now clears them next to the worktree's session-tab snapshot and publication state. The desktop mirror is updated once, and the worktree's removal frame is the only session-tabs publication.
…nts' into brennanb2025/terminal-exit-record # Conflicts: # src/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.ts
…ut a JSON round trip
There was a problem hiding this comment.
ℹ️ One minor consistency note inline. The prior review's clearing-asymmetry thread is still open, so this is not an approval.
Reviewed changes — incremental review of the 11 commits since 852c12d, against the full 45-file diff at f857846. The delta rewrites the client projection, moves the desktop restart into the exited pane, and adds delivery-order, mount, and mirror-stability coverage.
- Client projection strips process ids —
projectSessionTabTerminalExitsnow takes the wholeTerminalExitRecord, sends capable clients only{exitCode, cause, exitedAt}(toClientExit), and derives the older client's retirement proof from the record's ids (retirementProofFor); exited tabs have their ownptyIddropped before retirement. - Restart routes by who holds the leaf —
restartExitedTerminalSurfacenow testsisRuntimeOwnedHeadlessMobileTab(renderer graph) instead of the merge-unaware publication predicate, so a renderer-based merged snapshot whose pane is mounted routes tonotifier.restartExitedTerminal. - Routed restart runs from the exited pane —
RoutedExitedTerminalRestart(mounted per exited pane, outside theisActivegate) replaces the previous all-panes subscription; it consumespendingExitedTerminalRestartLeafIdsand calls the pane's own restart. - Record lifecycle —
clearLeavessplit intoclearClosedLeaves(records push only; the close's own publication carries the removal) andclearWorktree(a removed worktree's records). - Mirror stability —
replaceTerminalExitRecordsmemoizes and keeps the pending-restart map reference stable when nothing changed, so unrelated exits do not re-render every pane. - New coverage —
terminalExitRecords:changedprecedespty:exiton the provider and SSH-relay paths; a pane mounting over a recorded leaf shows the exit and spawns nothing; the routed-restart component consumes exactly once, including in a background tab.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| return { | ||
| ...payload, | ||
| tabs: payload.tabs.map((tab) => | ||
| isExitedTerminalTab(tab) ? { ...tab, exited: toClientExit(tab.exited) } : tab |
There was a problem hiding this comment.
This branch strips the dead process's ids from exited but spreads tab otherwise unchanged, so the exited tab's own persisted binding — tab.ptyId, and parentLayout.ptyIdsByLeafId[tab.leafId] — still reaches a capable client. The older-client test "even one still carrying its old binding" constructs exactly that stale binding, and the "no dead ids" assertion cannot catch it because that snapshot has no binding.
Technical details
# Capable-client projection keeps the exited leaf's persisted pty binding
## Affected sites
- `src/main/runtime/rpc/methods/session-tab-terminal-exit-projection.ts:62-68` — the capable branch only replaces `exited` via `toClientExit`, so `tab.ptyId` and `tab.parentLayout.ptyIdsByLeafId[tab.leafId]` survive into the client payload.
- `src/main/runtime/rpc/methods/session-tab-terminal-exit-projection.ts:70-81` — the non-capable branch drops `tab.ptyId` before retiring, so the two projections disagree about what an exited tab may carry.
- `src/main/runtime/runtime-mobile-session-projection.ts:295,300` — `tab.ptyId` and `parentLayout` are attached to the client tab independently of `exited`, so `exited` being stripped does not remove them.
## Required outcome
A capable client sees an exited leaf without the dead process's persisted binding, matching the commit's "never its dead process's ids" goal and the stale-binding case the older-client test already covers.
## Open questions for the human
Does the follow-up producer clear the kept leaf's persisted binding (`tab.ptyId` / `parentLayout.ptyIdsByLeafId`) when it writes the first record? If it does not, the capable path publishes it.There was a problem hiding this comment.
ab34c097 drops tab.ptyId, but the same dead id still rides in parentLayout.ptyIdsByLeafId[leafId] (spread unconditionally at runtime-mobile-session-projection.ts:309, from the same savedPtyIdsByLeafId), so a capable client still receives it — leaving this open.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… a tab close
Every explicit close now states its target as `{kind:'tab'}` or `{kind:'pane', leafId}`; no
optional leaf id silently means the whole tab. Main resolves a close it started in exactly one
place, reading the copy of the tab's panes its layout owner holds (the renderer-published layout
for tabs the desktop renderer lists, main's session layout otherwise). Only `last-pane` escalates,
through the existing tab path so the renderer's pin guard still runs; an unknown pane never widens.
- The CLI and phone paths drop their per-site sibling counts for the resolver.
- The notifier splits into a tab-only close and a leaf-addressed pane close.
- The headless tab closer takes a parent tab id, so a pane row cannot reach it.
- A phone close of one pane on a host with no desktop window now stops and closes only that pane.
- A phone close of one pane with no live process record closes that pane, not its tab.
`orca terminal close` still exits 1 when the process stop cannot be verified, but its message now says the terminal was closed and names the host's reason, instead of "close failed". It promises that the kill retries on reconnect only when the SSH relay itself never answered the stop, the one case a recorded kill order backs.
A paired client's close of one pane threw `terminal_close_failed` before committing anything when the controller reported the kill failed, so the pane stayed. The kill is now best-effort, as it is for a whole-tab close: the pane's removal always commits and the failure stays on the PTY's liveness verdict.
…ast pane The close resolver read an owner copy that records no panes as "the tab has one pane", so a CLI close of one pane of a split, addressed while the renderer listed the tab before publishing its panes, closed the whole tab. Every copy now counts only if it records at least one pane, read in the owner's order with the published rows as the last fallback, and a pane close widens only when a copy lists that pane as the tab's only one. An unsplit tab whose saved layout predates its pane still closes: its published row names the pane.
…that holds it A restart routed by the close-teardown predicate treated every tab with an SSH or serve binding on any leaf as runtime-owned, so an SSH split pane the desktop shows would get a runtime spawn that pane never attaches to. Route by the renderer graph alone: a tab the renderer lists has a desktop pane for each of its leaves.
…sktop focus The routed restart ran the pane's own Restart, which ends by making the pane active and focusing it. A phone restarting a pane would pull the desktop's keyboard focus into that shell, even from another pane or a background tab. The routed restart now leaves focus alone; main already focuses the pane when the navigation targets the desktop.
The close receipt inferred "the kill retries when the host reconnects" from the stop reason's text, which a new transport message or a reworded error would silently break. An explicit close now records the replayable kill order when its stop goes unconfirmed, before sending the follow-up kill (whose own failure is recorded only once its RPC settles), and reports that on the receipt as an optional `pendingKillRecorded`. The CLI promises the retry only from that field, so an older host, which never sends it, gets no promise.
The low-evidence lint gate rejects Reflect.get and broad object parameters, which failed static analysis. Narrow with 'in' checks instead and cover the boundary parser's accept and reject cases.
…d session A record now dies when its leaf departs its worktree's stored session-tabs snapshot, detected at the snapshot's single writer (store, or the two whole-snapshot deletes, now one helper). The per-close clear and the worktree-removal clear go: the frame that removes a leaf is the one that ends its record, so no frame shows a still-listed leaf without its exit, and a reopened tab that reuses its leaf ids finds no stale record.
…aches restartExitedTerminalSurface now always spawns the plain shell through the existing runtime-owned create under the leaf's pane key: the tab's shell override for a local tab, the dead process's id class (a desktop tab never gets a serve- id), and no owner surfacing. A repeated tap joins the spawn in flight. Main focuses the pane only when the navigation targets the host. An exited desktop pane attaches when its leaf's layout binding names a PTY it did not name when the exit showed; the reveal writes that binding, and the pane's spawn resolves main's stable owner instead of starting another process. A parked pane finds the binding when it mounts. Removes the renderer restart IPC, the pending-restart latch and the desktop-or-runtime routing predicate.
…estart Lifetime: a reopened tab reusing its leaf ids finds no record once the session removed the leaf; a closing leaf stays exited until then; a leaf not yet published keeps its record; a headless close ends it in the frame that removes the leaf; worktree removal ends only that worktree's records. Restart: mounted, unmounted and reloading desktop leaves each get one runtime spawn with the tab's shell, no serve id and no surfacing; host navigation alone focuses; a repeated tap joins the spawn and the desktop's spawn for the pane key resolves the same process; an exited pane attaches once on a new binding and never when its record ends by close or removal.
…nts' into brennanb2025/terminal-exit-record
…pane hook count The separate attach callback added a render hook to every TerminalPane and tripped the hook-order parity guard; an attach option on the existing restart action carries the same no-startup, no-focus behaviour.
…tire it The projection now decides `exited` from the record plus the process the leaf still resolves to: a record for that process, or no live process, means the leaf is exited and gets no handle. Subscription frames published before the dead process's records are reaped no longer show it ready with a dead handle, and nothing depends on the order the exit is written in. A leaf with a record for the exiting process is kept: onPtyExit no longer retires it when that process's exit is reported (again, as a failed reattach during a restart does), so a capable client sees exited, then the new process, never the pane removed. Desktop Delete Workspace needs no clear of its own: the renderer's next graph omits the worktree, and that whole-snapshot delete ends its records.
… durable writes Main moved terminal-tab retirement onto awaited background writes (runDurableMutation) with an owner-identity fence. The close transaction now commits through that path instead of a synchronous flush, which the live background writer refuses: - closeTerminalSurface is async over runDurableMutation, keeps main's tab owner fence, and fences a pane close by the pane's own incarnation. - A failed durable write never undoes a user's close or skips its kill: the mutation carries no rollback, the removal stays dirty for the next write. - Every main-side caller awaits the transaction; the renderer's IPC promise is only awaited to report a failure, so its removal and kill stay immediate. - closeHeadlessMobileTerminalTab takes main's tab-row signature.
…nts' into brennanb2025/terminal-exit-record # Conflicts: # src/main/runtime/orca-runtime-on-pty-exit.ts
…atted The merge commit's formatter rewrote files it did not author; they return to the base's exact content. No hook run, so they are not rewritten again.
…nd while it waited The renderer has already removed and killed a tab it closes, so its close intent now skips the owner fence phone and CLI closes use. Before, a split pane whose binding was admitted between the close request and its durable write made main refuse the close, and the tab came back on the next launch whenever its processes did not exit.
…ns the terminal layout
There was a problem hiding this comment.
✅ No new issues found in this delta. Not an approval only because the capable-client binding thread from an earlier review remains open and unaddressed.
Reviewed changes — incremental review of the 24 commits since d1063b3e6e, against the full 49-file diff at 5913252.
- Restart runs in main for every client —
restartExitedTerminalSurfacenow always spawns a plain shell through the runtime under the leaf's pane key (withserveOwned/shellOverride/surfaceOwner:falsetaken from the record), deduped by an in-flight map; the oldui:restartExitedTerminalroute and the routed-restart store slice are gone. - Desktop pane attaches to main's process — a new
ExitedPaneProcessAttachwatches the leaf's layout binding and runs the pane's restart as an attach (startup:null, no focus), so the desktoppty:spawnresolves main's stable owner and reattaches instead of starting a second shell. - Record lifetime ends on snapshot departure —
releaseDepartedLeavesreplacesclearClosedLeaves/clearWorktreeand runs fromstoreMobileSessionSnapshot/deleteMobileSessionSnapshot; the close transaction no longer touches records. - A kept leaf is not retired on a repeat exit —
onPtyExitexcludes surfaces whose leaf has an exit record naming the exiting pty, so a failed reattach of the same dead process cannot retire the kept leaf. - Exit is derived per frame — the projection attaches
exitedfrom the record plus the process the leaf still resolves to, and withholds the handle; the per-client capability gate is unchanged. - Coverage — delivery order (record push before
pty:exit), mount-over-record, attach dedup/background-tab, in-flight restart, and per-frame exit publication.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found in this delta.
Reviewed changes — incremental review of the two commits since 5913252 (the 12e65a3476 merge of the updated base and the 08485e9ecf test-file restoration chore).
- Conformed to the base's async retirement —
onPtyExitnow passesretirableSurfacesto the promise-returningretireMobileSessionSurfacesForPty, registers the pending retirement inpendingPtySurfaceRetirementsByPtyId, and returns the promise; the kept-leaf exclusion is preserved in the merged shape. - Test conformance — the exit-record tests await the now-async
closeTerminalSurfaceFromRenderer; the remaining changes are test-only.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…nts' into brennanb2025/terminal-exit-record
There was a problem hiding this comment.
✅ No new issues found in this delta. Not an approval only because the capable-client binding thread from an earlier review remains open and unaddressed.
Reviewed changes — incremental review of the single commit since 08485e9ecf, against the full 49-file diff at 5219c914.
- Merged the updated base branch —
5219c914mergesbrennanb2025/terminal-close-intentsatb6db605cbc; it adopts only base-owned changes (closeTerminalSurface's newclosedByLayoutOwneroption, which skipscaptureTerminalTabRetirementfor a renderer close, plus a base test), and no file this PR authors changed. The PR's net diff is still the 49 files / +1744 / -76 the body reports, and the two core exit-record test files pass at the merged head.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…ofile store Main now requires a SQLite profile-state authority for a writable Store, so the save-and-reload close tests build and reopen their store through the shared SQLite test harness.
…nts' into brennanb2025/terminal-exit-record
…on at the retirement check
…ny client After a window reload the renderer's layout still binds a kept exited leaf to its dead process, and the projection passed that id through as the tab's ptyId. The tab now omits ptyId while the leaf is exited, which also makes the older-client retirement's own unbinding step redundant.
…laim it is preserved A local window reload saves no terminal scrollback, because the daemon's history is the copy a live pane reattaches to, and the dead process's history is no longer served. A pane that remounts over a leaf main kept after its exit therefore showed "Its output is preserved" over a blank pane. The overlay now says only the exit code unless this mount replays a saved buffer for the leaf.
There was a problem hiding this comment.
✅ No new issues found in this delta. Not an approval only because the capable-client binding thread from an earlier review is now only partially addressed (see the reply on that thread).
Reviewed changes — incremental review of the three commits since 5219c914f3, against the full 58-file diff at c5b58fe8d9.
- An exited tab no longer carries its stale
ptyId—projectRuntimeMobileSessionTabsomitstab.ptyIdwhenever the leaf is exited, so the dead process's id never reaches any client; the per-client unbinding inprojectSessionTabTerminalExitswas removed as redundant (every client payload flows through this projection). Test: a capable client getsexitedwith noptyIdwhile its live sibling keeps one. - A remount no longer over-claims preserved output — a pane mounting over a kept leaf sets
outputPreserved: falseunless this mount replays a saved buffer for that leaf;TerminalProcessExitOverlaygained afailedDetailWithoutOutputstring (all six locales) and drops the "Its output is preserved" clause. Tests cover both the overlay branch and the mount decision. - A comment records that the exit record is the durable keep decision at the retirement check.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Review status: ready for reviewHead What the review changed. Four review loops plus an architecture review. The two areas that kept moving between loops were redesigned rather than patched:
Every fix has a test proven red by deleting the line it guards. Mixed versions. Older paired clients get the same projection as today: the pane is omitted and a retirement proof is sent. The cross-version wire suites pass. Live QA: #22953 (comment)
One small live change. A desktop pane already showing "Terminal exited" now attaches when main binds a new process to it, for example when a phone opens it. Before, it kept showing the overlay over a live process. Known gaps. All of these are dormant until the follow-up writes records, and all are listed in the body:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe change adds explicit tab and pane close targets, shared close resolution, and durable session mutations. It records unconfirmed SSH stop intents and includes retry status in close results. The runtime now tracks terminal exit records and projects them according to client capability. Renderer state consumes those records, shows exit details, and supports restarting exited panes. 🚥 Pre-merge checks | ✅ 4 | ❓ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 45 functions across 50 files. (52 skipped: 6 unsupported, 46 over the file limit.) ✨ Finishing Touches 💡 3📝 Generate docstrings 💡
⚔️ Resolve merge conflicts 💡
🛠️ Fix failing CI checks 💡
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: Advanced
Run ID: cbe60b92-47e6-464a-b861-013b5fb2930d
📒 Files selected for processing (103)
src/cli/handlers/terminal-close.tssrc/cli/handlers/terminal.test.tssrc/cli/terminal-format.test.tssrc/cli/terminal-format.tssrc/main/ipc/pty-ssh-undelivered-kill.test.tssrc/main/ipc/pty/runtime/controller.tssrc/main/ipc/pty/runtime/undelivered-ssh-kill.tssrc/main/ipc/pty/terminal-exit-record-delivery-order.test.tssrc/main/ipc/register-core-handlers/register-core-handlers.test.tssrc/main/ipc/register-core-handlers/register-core-handlers.tssrc/main/ipc/session.tssrc/main/persistence/loading-store/terminal-close-async-durability.test.tssrc/main/runtime/__fixtures__/orca-runtime-terminal-close-continuity-fixtures.tssrc/main/runtime/__fixtures__/orca-runtime-terminal-close-continuity-state-fixture.tssrc/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.tssrc/main/runtime/orca-runtime-close-headless-mobile-terminal-tab.tssrc/main/runtime/orca-runtime-close-mobile-session-tab.tssrc/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.tssrc/main/runtime/orca-runtime-on-pty-exit.tssrc/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.tssrc/main/runtime/orca-runtime-prune-mobile-session-tab-group-layout.tssrc/main/runtime/orca-runtime-register-pty.tssrc/main/runtime/orca-runtime-resolve-worktree-removal-target.tssrc/main/runtime/orca-runtime-runtime-id.tssrc/main/runtime/orca-runtime-stop-explicitly-closed-tab-ptys.tssrc/main/runtime/orca-runtime-sync-mobile-session-tabs.tssrc/main/runtime/orca-runtime-terminal-close-continuity.test.tssrc/main/runtime/orca-runtime-terminal-close-no-widening.test.tssrc/main/runtime/orca-runtime-terminal-surface-close.test.tssrc/main/runtime/orca-runtime-test-scenario-builders.spec.tssrc/main/runtime/orca-runtime-tests/mobile-session-tabs-part-10.spec.tssrc/main/runtime/orca-runtime-tests/mobile-session-tabs.spec.tssrc/main/runtime/orca-runtime-wait-for-leaf-pty-id.tssrc/main/runtime/rpc/methods/session-tab-terminal-exit-projection.tssrc/main/runtime/rpc/methods/session-tabs-inventory.tssrc/main/runtime/runtime-mobile-session-projection-contract.tssrc/main/runtime/runtime-mobile-session-projection.tssrc/main/runtime/runtime-notifier-contract.tssrc/main/runtime/runtime-pty-controller-contract.tssrc/main/runtime/terminal-close-observed-exit-test-fixture.tssrc/main/runtime/terminal-exit-records.tssrc/main/runtime/terminal-surface-close.test.tssrc/main/runtime/terminal-surface-close.tssrc/main/runtime/terminal-surface-exit-record.test.tssrc/main/window/runtime-window-lifecycle.tssrc/preload/api/session-bridge.tssrc/preload/api/ui-bridge-clipboard-and-window-controls.tssrc/preload/api/ui-bridge-terminal-and-session-tabs.tssrc/preload/api/ui-command-event-api.tssrc/preload/api/workspace-session-api.tssrc/renderer/src/components/terminal-pane/ExitedPaneProcessAttach.tsxsrc/renderer/src/components/terminal-pane/TerminalPaneRuntimePortals.tsxsrc/renderer/src/components/terminal-pane/TerminalProcessExitOverlay.test.tsxsrc/renderer/src/components/terminal-pane/TerminalProcessExitOverlay.tsxsrc/renderer/src/components/terminal-pane/closed-terminal-leaf-notice.test.tssrc/renderer/src/components/terminal-pane/closed-terminal-leaf-notice.tssrc/renderer/src/components/terminal-pane/pending-split-close.test.tssrc/renderer/src/components/terminal-pane/pty-connection-types.tssrc/renderer/src/components/terminal-pane/terminal-pane-exited-leaf-mount.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-exited-process-attach.test.tsxsrc/renderer/src/components/terminal-pane/terminal-pane-exited-restart-focus.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-pane-created.tssrc/renderer/src/components/terminal-pane/terminal-parked-pty-watcher.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-process-exit-actions.tssrc/renderer/src/hooks/ipc-events-agent-status-window-test-fixtures.tssrc/renderer/src/hooks/ipc-events-close-routing-test-harness.tssrc/renderer/src/hooks/ipc-events-terminal-create-window-test-fixtures.tssrc/renderer/src/hooks/ipc-events-test-harness.tssrc/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.tssrc/renderer/src/hooks/ipc-events/mobile-terminal-close-ipc-bridge.tssrc/renderer/src/hooks/ipc-events/terminal-exit-record-ipc-bridge.tssrc/renderer/src/hooks/useIpcEvents-browser-tab-create.test.tssrc/renderer/src/hooks/useIpcEvents-cli-worktree-activation.test.tssrc/renderer/src/hooks/useIpcEvents-close-routing-browser-pages.test.tssrc/renderer/src/hooks/useIpcEvents-close-routing-session-tabs.test.tssrc/renderer/src/hooks/useIpcEvents-lifecycle.test.tssrc/renderer/src/hooks/useIpcEvents-rate-limit-hydration.test.tssrc/renderer/src/hooks/useIpcEvents-ssh-disconnect-cleanup.test.tssrc/renderer/src/hooks/useIpcEvents-updater-status.test.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/store/slices/terminals.tssrc/renderer/src/store/terminals/terminal-actions.tssrc/renderer/src/store/terminals/terminal-exit-record-state.test.tssrc/renderer/src/store/terminals/terminal-exit-record-state.tssrc/renderer/src/store/terminals/terminal-state.tssrc/renderer/src/store/terminals/terminal-surface-close-intent.tssrc/renderer/src/store/terminals/terminal-tab-close-intent.test.tssrc/renderer/src/store/terminals/terminal-tab-close.tssrc/renderer/src/web/preload-api/web-ui-api.tssrc/renderer/src/web/preload-api/web-workspace-session-api.tssrc/shared/protocol-version.tssrc/shared/pty-liveness-verdict.tssrc/shared/runtime-mobile-session-tab-contracts.tssrc/shared/runtime-terminal-contracts.tssrc/shared/terminal-surface-close-target.test.tssrc/shared/terminal-surface-close-target.tssrc/shared/terminal-surface-exit.ts
💤 Files with no reviewable changes (1)
- src/main/runtime/orca-runtime-wait-for-leaf-pty-id.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| if (target.kind === 'pane') { | ||
| const layout = session.terminalLayoutsByTabId[target.tabId] | ||
| const resolution = resolvePaneClose( | ||
| layout ? collectTerminalLayoutLeafIds(layout.root) : null, | ||
| target.leafId | ||
| ) | ||
| // Why: the exit may already have retired this pane, leaving only live siblings to lose. | ||
| if (!layout || resolution !== 'pane') { | ||
| return { session, ptyIdsToKill: [], closed: false, pinned: false, resolution } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
rg -nP -C8 'export function rebaseWorkspaceSessionTerminalMembership' src/main
rg -nP -C6 'function recordTerminalSurfaceRetirement' src/mainRepository: stablyai/orca
Length of output: 3336
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- rebase and membership authority ---'
sed -n '1,330p' src/main/runtime/workspace-session-terminal-membership-authority.ts
printf '%s\n' '--- retirement implementation ---'
sed -n '1,230p' src/main/runtime/mobile-session-terminal-persistence-retirement.ts
printf '%s\n' '--- related symbols and save paths ---'
rg -n -C5 'sanitizeWorkspaceSessionTerminalRetirements|rebaseWorkspaceSessionTerminalMembership|recordTerminalSurfaceRetirement|closedByLayoutOwner|persistPtyBinding|renderer.*save|save.*renderer' src/main
printf '%s\n' '--- targeted test references ---'
rg -n -C12 'unbound-sibling|siblingWasPersisted|closedByLayoutOwner|terminal-close-no-widening' .
printf '%s\n' '--- changed-file diff summary and relevant diff ---'
git diff --stat 484598b18e8bce2fd3e3e6672bde03d82679e82c c5b58fe8d97a8198f13c8ad6842e484490686f1d
git diff --unified=30 484598b18e8bce2fd3e3e6672bde03d82679e82c c5b58fe8d97a8198f13c8ad6842e484490686f1d -- src/main/runtime/terminal-surface-close.ts src/main/runtime/workspace-session-terminal-membership-authority.ts src/main/runtime/mobile-session-terminal-persistence-retirement.ts src/main/ipc/session.tsRepository: stablyai/orca
Length of output: 45501
🏁 Script executed:
#!/bin/bash
set -e
sed -n '1,330p' src/main/runtime/workspace-session-terminal-membership-authority.ts
sed -n '1,230p' src/main/runtime/mobile-session-terminal-persistence-retirement.ts
rg -n -C5 'sanitizeWorkspaceSessionTerminalRetirements|rebaseWorkspaceSessionTerminalMembership|recordTerminalSurfaceRetirement|closedByLayoutOwner|persistPtyBinding|renderer.*save|save.*renderer' src/main
rg -n -C12 'unbound-sibling|siblingWasPersisted|closedByLayoutOwner|terminal-close-no-widening' .
git diff --stat 484598b18e8bce2fd3e3e6672bde03d82679e82c c5b58fe8d97a8198f13c8ad6842e484490686f1d
git diff --unified=30 484598b18e8bce2fd3e3e6672bde03d82679e82c c5b58fe8e8bce2fd3e3e6672bde03d82679e82c -- src/main/runtime/terminal-surface-close.ts src/main/runtime/workspace-session-terminal-membership-authority.ts src/main/runtime/mobile-session-terminal-persistence-retirement.ts src/main/ipc/session.tsRepository: stablyai/orca
Length of output: 45667
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- retirement sanitization remainder ---'
sed -n '220,380p' src/main/runtime/mobile-session-terminal-persistence-retirement.ts
printf '%s\n' '--- sanitization and rebase call sites ---'
rg -n -C8 'sanitizeWorkspaceSessionTerminalRetirements|rebaseWorkspaceSessionTerminalMembership' src/main
printf '%s\n' '--- workspace session persistence entrypoints ---'
rg -n -C12 'setWorkspaceSession|persistPtyBinding' src/main/persistence src/main/runtime | head -n 320
printf '%s\n' '--- no-widening test setup and assertions ---'
sed -n '1,275p' src/main/runtime/orca-runtime-terminal-close-no-widening.test.tsRepository: stablyai/orca
Length of output: 42537
🏁 Script executed:
#!/bin/bash
set -e
sed -n '220,380p' src/main/runtime/mobile-session-terminal-persistence-retirement.ts
rg -n -C8 'sanitizeWorkspaceSessionTerminalRetirements|rebaseWorkspaceSessionTerminalMembership' src/main
rg -n -C12 'setWorkspaceSession|persistPtyBinding' src/main/persistence src/main/runtime | head -n 320
sed -n '1,275p' src/main/runtime/orca-runtime-terminal-close-no-widening.test.tsRepository: stablyai/orca
Length of output: 42268
🏁 Script executed:
#!/bin/bash
set -e
sed -n '100,245p' src/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.ts
rg -n -C15 'persistPtyBinding|advanceTerminalTopologyRevision|establishesSplitAuthority|currentRevision' src/main/persistence src/main/runtimeRepository: stablyai/orca
Length of output: 45660
Persist a renderer-owned pane retirement when the saved layout resolves the pane as last-pane.
closeTerminalSurfaceFromRenderer allows a missing close. If the saved layout contains only the target pane, closeTerminalSurfaceInWorkspaceSession returns closed: false with resolution: 'last-pane'. For a repo with an existing positive topology revision, the next renderer save can be rebased to the prior layout and restore the target pane.
When closedByLayoutOwner applies to a pane target that resolves as last-pane, record a pane retirement tombstone before returning the allow-missing result. Do not treat this case as a no-op.


















Stacked on #22929.
ELI5
Soon, when a terminal's process dies, main will decide to keep some of those terminals open (for example one that failed at startup), showing "exited" with a Restart button. This PR builds everything that shows and restarts such a terminal, on the desktop and for paired clients. Nothing tells main to keep a terminal yet, so nothing changes for users today. The follow-up change that moves the exit decision into main turns it on.
What Changed
Before: there is no host-side record of "this pane's process exited and the pane was kept". The desktop's "Terminal exited · Restart" overlay lives only in the pane's component state, so a remount or window reload forgets it and spawns a new shell. A phone or paired web client sees a kept pane with no process as a terminal that is still starting, and opening it either waits forever or spawns the tab's agent into it.
One small change is live today: a desktop pane showing the existing "Terminal exited" overlay now attaches when main binds a new process to its leaf, for example when a phone opens that terminal. Before, the desktop kept showing the overlay while the phone ran a live process in the same pane.
After (dormant until the follow-up writes the first record):
{worktreeId, leafId, ptyId, incarnationId, terminal?, exitCode, cause, exitedAt}.session-tabs.terminal-exit-state.v1capability see the pane withexited: {exitCode, cause, exitedAt}and no process id. The dead process's ids stay in main's record and are used only to build an older client's retirement proof.activateMobileSessionTab) is checked before both the materialize branch and the focus branch. A user open restarts the pane; an automatic probe does nothing.restartExitedTerminalSurface. It always spawns a plain shell in main, under the pane's own tab and leaf, through the existing runtime terminal create:Why
The terminal-membership plan makes main the single decider at exit. When main keeps a pane, every client needs one fact to render, and there needs to be one way to restart it. Without that fact, a kept pane reads as "starting" on every phone build and the desktop respawns it on remount.
Alternatives considered:
pty:exitat each send site. Not done. One main-to-renderer push of the record map covers the write, the end on rebind and the end on departure. The push fires inonPtyExit, before everypty:exitsend, so the renderer has the record before it handles the exit.Differences from the common pattern
Linked Issue
No public issue. This is the exit-record slice of the terminal tab membership work.
Visual Proof
Screenshots and wire evidence are in the live QA comment: #22953 (comment). It covers before/after on the desktop and over SSH (no change today), and a walkthrough with a local test-only patch that writes a record on a non-zero exit (never shipped): the overlay after a reload, the restart frames, the phone restart of a mounted and a hidden pane, and the Windows shells.
Testing
New tests, each proven by deleting or breaking the production line it guards:
exitedwith only exit code, cause and time. An older client gets the pane omitted, a proof naming its handle, and the same snapshot version, field-for-field identical to what an exit produced before main kept the leaf. For an older client only the exited leaf of a split is removed.exited(capable) or omit plus proof (older) without any list or activate call.pty:exiton the local and SSH relay paths.Commands run: the PR's tests; the main runtime, IPC, window and preload suites; the renderer terminal-pane, store, hooks and runtime suites; the cross-version wire suites; typecheck;
oxlint, the anti-slop audit,check:code-quality:changed,check:react-doctor:changed; the localization checks.Live QA on remote machines (a Mac and a Windows PC), at this head and at the base, with isolated profiles: #22953 (comment)
exited(capable) or omit plus proof (older); a reload shows the overlay with the exit-code-only text and spawns nothing; a restart goes exited to ready and never disappears; a phone restart of a mounted or hidden desktop pane starts exactly one process, attaches, and moves no focus; a desktop Restart racing a phone restart starts one process; closes, a desktop workspace delete and a runtime worktree removal each end the record.AI Disclosure
Written with Claude.
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
exitedis a new optional field, sent only to clients that advertise the new capability. Clients without it get the omit-plus-proof projection they already understand, and their retirement ledger drops the proof once the pane is published live again after a restart. A new client on an older host never sees the field; that host retires exits as it does today. No new stream opcode, and the paired-client RPC methods are unchanged.terminalExitRecords:listandterminalExitRecords:changedare between one build's main and renderer. The web client's preload has no-op versions, because it learns exits from the host's projection.\\wsl.localhostwith default settings, or a tab forced onto the host inside a WSL project) cannot be restarted from a phone yet: main refuses the shell, as it already refuses a phone-created terminal with that shell. The pane stays exited and the desktop's Restart works.Author X handle: @BrennanKB5
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)