Skip to content

feat(terminal): main's exit record for a kept pane, its capability-gated publication and one restart - #22953

Open
brennanb2025 wants to merge 48 commits into
mainfrom
brennanb2025/terminal-exit-record
Open

brennanb2025 wants to merge 48 commits into
mainfrom
brennanb2025/terminal-exit-record

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1223 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1223
Prod 44 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​598 $\color{#cf222e}{\Huge{\mathbf{−}}}$​81 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​517

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):

  • Main keeps one in-memory exit record per kept pane, keyed by the pane's leaf id: {worktreeId, leafId, ptyId, incarnationId, terminal?, exitCode, cause, exitedAt}.
  • A record ends when its leaf registers a different process, when its leaf leaves that worktree's stored session-tabs snapshot (a close, a worktree removal, or the desktop no longer publishing the worktree), or when main exits. The frame that removes the leaf is the one that ends its record, so no frame shows a still-listed pane without its exit, and a reopened tab that reuses its leaf ids starts fresh. A leaf the desktop has not published yet keeps its record.
  • A record naming the exiting process keeps its leaf from being retired by that exit. The record is the durable form of main's keep decision, which the follow-up writes before this check.
  • Whether a leaf is exited is decided when each frame is built, from the record and the process the leaf still resolves to. List, subscribe and activate frames all agree, whatever order the exit is recorded in.
  • Paired clients that advertise the new session-tabs.terminal-exit-state.v1 capability see the pane with exited: {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.
  • Every other client gets exactly today's projection of an exit: the pane is omitted and a retirement proof names the handle it knew. No client advertises the capability yet; the phone and paired-web UI come in a follow-up.
  • Opening an exited pane from a phone or paired client (activateMobileSessionTab) is checked before both the materialize branch and the focus branch. A user open restarts the pane; an automatic probe does nothing.
  • There is one restart operation, restartExitedTerminalSurface. It always spawns a plain shell in main, under the pane's own tab and leaf, through the existing runtime terminal create:
    • with the tab's shell (a Windows shell choice is the shell the terminal is, never a command typed into another shell);
    • with the same kind of process id the dead process had, so a local tab stays a local tab;
    • without revealing the worktree or moving the desktop's focus. Main focuses the pane only when the opening client asked to navigate the desktop.
    • A second tap while the spawn is running joins it.
  • A desktop pane showing the exit attaches when its leaf's layout binding names the new process. Its connect resolves main's process for that pane instead of starting another. A pane that is not mounted finds the process when it mounts. The desktop's own Restart button is unchanged.
  • The desktop mirrors main's records. It reads them once at startup (and on a window reload), then receives the whole map on every change. A pane mounting over a leaf that has a record shows the existing "Terminal exited" overlay and does not spawn. When that remount has no saved copy of the output (a local window reload saves none), the overlay shows only the exit code instead of claiming the output is preserved.

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:

  • Put the record on pty:exit at 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 in onPtyExit, before every pty:exit send, so the renderer has the record before it handles the exit.
  • Store the tab id in the record. Not done. Moving a pane between tabs changes the tab and keeps the leaf, so a stored tab id would go stale. The record stores the process identity instead, because an older client's retirement proof must name the handle it knew.
  • Clear the record on every close path. Not done. Each close path would need its own clear, ordered against its own publication, and a miss leaves a stale "exited" on a reopened tab. Ending the record when its leaf leaves the stored snapshot covers every path with one rule.
  • Have the desktop pane run the restart when it holds the pane. Not done. Until main owns tab membership it cannot reliably tell which desktop pane holds a leaf, and every routing rule tried was wrong in some case (an SSH split, an unmounted tab, a reload). Main already has one fact about who holds a pane's process, the pane's stable owner, and every spawn for that pane attaches to it. So main spawns and the desktop attaches.
  • Persist the record so "exited" survives a relaunch. Not done. After a relaunch a kept pane starts a fresh shell, which is the agreed product behaviour. In memory means there is no migration and no stale on-disk state.

Differences from the common pattern

  • Matches: the exit is held in memory on the host as the terminal's status plus exit code, published to clients as part of the terminal's metadata, and opening an exited terminal restarts it.
  • Matches: a restart is a new run in the same pane, started by the host under the pane's identity, and every view attaches to it.
  • Matches: a view mounting onto an exited terminal shows the exit instead of spawning.
  • Differs: the record is not persisted. Some designs persist the exit so "exited" survives a restart. Here, after a relaunch the pane spawns fresh.
  • Differs: the published exit is capability-gated, because older paired clients must keep today's projection.

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

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New tests, each proven by deleting or breaking the production line it guards:

  • A capable client receives exited with 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.
  • Subscribe frames published after an exit show exited (capable) or omit plus proof (older) without any list or activate call.
  • A pane moved within a worktree keeps its record. A leaf not yet published keeps its record across an unrelated snapshot store.
  • A reopened tab with its old leaf ids spawns fresh. A frame published between a desktop close and its removal still shows the leaf as exited. A headless close, a runtime worktree removal and a desktop workspace delete each end the record in the frame that removes the leaf.
  • The exited process registering again keeps the record; a new process ends it, and the older client then sees the pane live and drops its proof.
  • A restart of a mounted, unmounted, reloading or headless pane is one runtime spawn under its tab and leaf, with no command, the tab's shell, the dead process's id kind, and no reveal or focus unless the navigation targets the desktop. An automatic probe restarts nothing. A repeated tap spawns once.
  • During a restart a capable client never sees the pane removed, even when the dead process reports its exit again.
  • A kept exited leaf's tab carries no process id for any client after a reload.
  • Desktop: a pane mounting over a recorded leaf shows the exit and spawns nothing; an exited pane attaches exactly once when its binding names a new process, even in a background tab; it never attaches to the dead id a remounted pane still names, or when its record ends by close or removal; the attach sends no startup and does not move focus; a remount without a saved copy of the output does not claim it is preserved.
  • An exit or restart on another leaf does not re-render an exited pane, and the pane subscription-budget and hook-order guards stay at their pinned values.
  • The record push reaches the desktop before pty:exit on 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)

  • Desktop and SSH, before vs after: identical for exit 0, a failed exit with the overlay's Restart and Close, a split, a tab close, a reload, a folder workspace and a switched-away worktree. No record is written today.
  • With a local test-only patch that writes a record on a non-zero exit: the first frame after the exit shows 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.
  • Windows: a phone restart keeps the tab's shell (Git Bash, PowerShell 7, Windows PowerShell 5.1, and WSL when the project runs in WSL), with exactly one new process.

AI Disclosure

Written with Claude.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Mixed versions: exited is 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.
  • Same-build IPC: terminalExitRecords:list and terminalExitRecords:changed are 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.
  • SSH: the record is main's fact about a death main certified; loss of contact never writes one. A restart on an SSH workspace spawns through the same runtime path, keeps its SSH id kind, and lets the SSH host resolve its own shell.
  • Folder workspaces use the same path as git worktrees; the record is keyed by leaf, not by worktree kind.
  • Windows: the tab's shell choice is passed as the shell the restarted terminal is.
  • Known gaps (dormant until the follow-up):
    • If a pane mounts before the startup read of the records returns, it spawns a fresh shell, which is today's behaviour.
    • A WSL tab whose project runs on the Windows host (for example a repo under \\wsl.localhost with 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.
    • A phone restart shows the new shell without the output from before the exit; the desktop's Restart keeps it.
    • A pane whose shell exits while its worktree is parked is closed by today's renderer exit path, so its record ends with it. The follow-up that moves the exit decision into main changes that.
    • A restart re-selects the restarted pane as its tab's active pane on the desktop, the same way opening a pending pane from a phone does today.
    • After a reload, the tab's shared split layout still names the dead process for that leaf; no client reads it.
  • Performance: a record write or end republishes one worktree's session tabs and sends one small map to the desktop. An unchanged push is a no-op in the renderer, and only panes showing an exit subscribe to their own leaf's binding.

Author X handle: @BrennanKB5

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

… 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 TerminalExitRecords map keyed by leaf, ended on rebind (releaseForBinding), on the close transaction (clearLeaves), or with main.
  • Capability-gated publication — exited is attached only when a terminal tab has no live handle; projectSessionTabTerminalExits returns the payload untouched for clients advertising session-tabs.terminal-exit-state.v1 and retires the leaf (omit + proof, version preserved) for everyone else.
  • One restart — restartExitedTerminalSurface routes a desktop-held pane to notifier.restartExitedTerminal and a headless pane to a plain-shell runtime spawn; activateMobileSessionTab checks the record before both the materialize and focus branches.
  • Desktop mirror and mount — terminalExitRecords:list/:changed IPC, the renderer store slices, and a pane-mount handler that synthesizes the exit and skips spawning.
  • Renderer restart consumption — a new effect drains pendingExitedTerminalRestartLeafIds into handleRestartExitedPane.

ℹ️ 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 pendingExitedTerminalRestartLeafIds into handleRestartExitedPane); only the store actions are covered. The author disclosed this, but it is the linchpin of the desktop restart.
  • onRestartExitedTerminal is dropped if it arrives before listTerminalExitRecords() resolves, because requestExitedTerminalRestart no-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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 — projectSessionTabTerminalExits now takes the whole TerminalExitRecord, 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 own ptyId dropped before retirement.
  • Restart routes by who holds the leaf — restartExitedTerminalSurface now tests isRuntimeOwnedHeadlessMobileTab (renderer graph) instead of the merge-unaware publication predicate, so a renderer-based merged snapshot whose pane is mounted routes to notifier.restartExitedTerminal.
  • Routed restart runs from the exited pane — RoutedExitedTerminalRestart (mounted per exited pane, outside the isActive gate) replaces the previous all-panes subscription; it consumes pendingExitedTerminalRestartLeafIds and calls the pane's own restart.
  • Record lifecycle — clearLeaves split into clearClosedLeaves (records push only; the close's own publication carries the removal) and clearWorktree (a removed worktree's records).
  • Mirror stability — replaceTerminalExitRecords memoizes and keeps the pending-restart map reference stable when nothing changed, so unrelated exits do not re-render every pane.
  • New coverage — terminalExitRecords:changed precedes pty:exit on 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

return {
...payload,
tabs: payload.tabs.map((tab) =>
isExitedTerminalTab(tab) ? { ...tab, exited: toClientExit(tab.exited) } : tab

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Pullfrog  | View workflow run | via Pullfrog | Using 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.
…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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — restartExitedTerminalSurface now always spawns a plain shell through the runtime under the leaf's pane key (with serveOwned/shellOverride/surfaceOwner:false taken from the record), deduped by an in-flight map; the old ui:restartExitedTerminal route and the routed-restart store slice are gone.
  • Desktop pane attaches to main's process — a new ExitedPaneProcessAttach watches the leaf's layout binding and runs the pane's restart as an attach (startup:null, no focus), so the desktop pty:spawn resolves main's stable owner and reattaches instead of starting a second shell.
  • Record lifetime ends on snapshot departure — releaseDepartedLeaves replaces clearClosedLeaves/clearWorktree and runs from storeMobileSessionSnapshot/deleteMobileSessionSnapshot; the close transaction no longer touches records.
  • A kept leaf is not retired on a repeat exit — onPtyExit excludes 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 exited from 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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — onPtyExit now passes retirableSurfaces to the promise-returning retireMobileSessionSurfacesForPty, registers the pending retirement in pendingPtySurfaceRetirementsByPtyId, 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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — 5219c914 merges brennanb2025/terminal-close-intents at b6db605cbc; it adopts only base-owned changes (closeTerminalSurface's new closedByLayoutOwner option, which skips captureTerminalTabRetirement for 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.

Pullfrog  | Fix it ➔ | View workflow run | Using 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.
…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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — projectRuntimeMobileSessionTabs omits tab.ptyId whenever the leaf is exited, so the dead process's id never reaches any client; the per-client unbinding in projectSessionTabTerminalExits was removed as redundant (every client payload flows through this projection). Test: a capable client gets exited with no ptyId while its live sibling keeps one.
  • A remount no longer over-claims preserved output — a pane mounting over a kept leaf sets outputPreserved: false unless this mount replays a saved buffer for that leaf; TerminalProcessExitOverlay gained a failedDetailWithoutOutput string (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.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Live QA on remote machines (macOS + Windows, desktop + SSH)

Tested: PR head c5b58fe8d9. The "before" builds are the base branch at 1c2c599877, which includes current main. The Mac runs were on a remote QA Mac. The Windows runs were on a remote Windows 11 box whose default shell is Git Bash. Every run was a dev build from its own checkout, with an isolated profile, HOME and CODEX_HOME. Apps were launched in the background and driven over CDP.

1. Desktop, before vs after: no behaviour change

Steps, run from an identical fresh start on each build:

  • exit 0;
  • exit 3, then the overlay's Restart;
  • split, exit 3 in one pane, then the overlay's Close;
  • tab close;
  • window reload;
  • a non-git folder workspace (exit 3 and Restart);
  • a parked worktree (switch to another workspace and come back).

Every step matched: the same overlay text, the same number of new shells, and the same process ids across the reload and the park. listTerminalExitRecords() stayed [] on the PR build throughout.

Before After
A2-before-03-exit3.jpg A2-after-03-exit3.jpg
A2-before-09b-parked-back.jpg A2-after-09b-parked-back.jpg

2. SSH, before vs after: no behaviour change

The target was a throwaway Ubuntu 24.04 container, recreated fresh for each build, holding a real repo. The relay was built from each checkout.

Steps: a remote terminal, exit 0, exit 3, split with a pane exit, tab close, and disconnect/reconnect by pausing the container.

Every step matched. The remote process list showed no orphaned or duplicated shells, and the same remote bash resumed after reconnect. Records stayed []. On both builds an SSH exit 3 closes the tab; that is existing behaviour, not a change.

Before (reconnected) After (reconnected)
B2-before-07b-reconnected.jpg B2-after-07b-reconnected.jpg

3. Seeded exit record walkthrough (Mac)

This used a local, test-only patch that was never committed or pushed. It writes a record when a local shell exits non-zero, just before the retirement check. Two paired clients stayed subscribed to session.tabs.subscribe the whole time: one advertising the new capability and one without it. Their frames were logged in order.

Visibility

  • Right after exit 3, with no list or activate call: the first published frame gave the capable client exited with only exitCode, cause and exitedAt, and no ptyId or handle. The older client got the pane omitted plus a retirement proof. Main and the desktop mirror both held the record, and the overlay showed.
  • Window reload: the overlay reads "The shell process ended with exit code 3." with no "output is preserved" claim over a blank pane. Nothing spawned. The record survived. The capable tab still carried no ptyId, even though the reloaded layout names the dead process.

Restarts

  • Desktop Restart: the capable client's frames went exited → ready. The pane was never absent. The record was cleared everywhere, and exactly one new process started.
  • Opens from paired clients:
    • An older client's open gets tab_not_found.
    • A capable client's automatic open does nothing: no spawn and no focus change.
  • A capable client's user open of a background, mounted pane:
    • Main started exactly one process, and the pane attached to it: $$ in the pane matched the new process's pid.
    • The desktop's active tab stayed where it was.
  • The same while the pane's worktree was hidden (another workspace selected): one process, no worktree reveal, and the pane attached when shown again. This also held for a folder workspace.
  • Desktop Restart racing a paired user open, tried in both orders: one process, and the pane attached to it.

Cleanup

  • Pane and tab close: closing an exited split pane (overlay Close), or closing the tab, removed the leaf and cleared the record in a single publication. The sibling's process was unchanged.
  • Workspace removal: deleting a workspace from the desktop ("Delete Workspace") cleared its record in main and in the mirror. Removal through the runtime (worktree.rm) did too.
After exit 3 (record + overlay) Reload remount (new copy, nothing spawned)
C2-02-exit3-record-overlay.jpg C2-03-reload-overlay-new-copy.jpg
Paired user open: desktop stays on Terminal 1 That pane, attached to main's process
C2-06a-mounted-user-restart-no-focus.jpg C2-06b-mounted-pane-attached.jpg
Desktop Restart racing a paired open: one process Desktop "Delete Workspace": record cleared
C2-09c-race2-one-process.jpg C2-12b-desktop-delete-record-cleared.jpg

4. Windows: a restart comes back as the same shell kind

This used the same test-only seed patch in a Windows checkout of c5b58fe8d9, with HOME, USERPROFILE and CODEX_HOME isolated. For each shell I ran exit 3 to write a record, then a user open from a capable paired client through the runtime RPC. The same kind of shell came back every time, as exactly one new process, with the desktop's tab unchanged.

Shell Before exit After paired restart
Git Bash /usr/bin/bash … MINGW64, MINGW64_NT-10.0-26200 … Msys /usr/bin/bash … MINGW64, MINGW64_NT-10.0-26200 … Msys (new pid)
PowerShell 7 Version=7.6.6 PSEdition=Core, pwsh.exe Version=7.6.6 PSEdition=Core, pwsh.exe (new pid)
Windows PowerShell 5.1 Version=5.1.26100.9444 PSEdition=Desktop Version=5.1.26100.9444 PSEdition=Desktop (new pid)
WSL (project runtime set to WSL) Linux … microsoft-standard-WSL2, distro=Ubuntu-24.04 Linux … microsoft-standard-WSL2, distro=Ubuntu-24.04 (new pid)

The desktop overlay's own Restart also worked on Windows. It brought back Git Bash as MINGW64, and WSL as WSL2 on Ubuntu-24.04.

Git Bash before exit Git Bash after paired restart
W-GitBash-a.jpg W-GitBash-c.jpg
PowerShell 7 after paired restart WSL after paired restart (project runtime WSL)
W-PowerShell-c.jpg W-WSL-e-paired-restart.jpg

Found

  • A WSL tab in a repo under \\wsl.localhost\… cannot be restarted from a paired client under default settings.

    • What happens: the restart is refused with "This workspace's project runs its terminals on the Windows host, so --shell wsl.exe cannot be applied." The record and the overlay stay, and nothing spawns.
    • Why: the renderer created the tab with wsl.exe, but main resolves the project's runtime as the Windows host. The same refusal happens for a plain paired terminal.create with wsl.exe, so the conflict itself already exists; this PR's restart is a new way to reach it.
    • What still works: the desktop overlay's Restart on the same pane. The paired restart also works once the project's runtime is set to WSL.
    • The client gets an error, but nothing on the desktop says the restart was refused.

    W-WSL-c-refused.jpg

  • On Windows, after the active pane's shell exits, session.tabs.list named a different active tab than the desktop, until the next activation.

  • On Windows, after a paired restart the pane shows a fresh prompt without its pre-exit output.

Gaps

  • Parked exited pane, not reachable today.
    • A worktree with an exited pane is never parked, because the park safety gate needs every tab to have a restorable process.
    • A pane whose shell exits while it is already parked has its tab closed by the renderer's existing exit path. The seed's record was written and then pruned when the leaf left the snapshot.
    • So the "parked pane attaches when it mounts" path could not be driven live. The hidden-but-mounted case above was covered instead.
  • No real phone or web UI: nothing advertises the capability yet.
  • No exit record over SSH: the seed was local-only, and an SSH exit 3 closes the tab on both builds.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready for review

Head c5b58fe8d9, stacked on #22929 at 1c2c599877 (which includes current main). All required checks pass. The one red e2e shard (ssh docker watcher isolation 1/4, a browser-mount timeout in local-ssh-browser-routing.spec.ts) fails the same way on #22929 and on main's last two e2e runs, and is not a required check.

What the review changed. Four review loops plus an architecture review. The two areas that kept moving between loops were redesigned rather than patched:

  • Record lifetime: a record now ends when its leaf leaves the stored session-tabs snapshot, or when the leaf binds a new process. Every per-close clear and its ordering rules are gone, and a reopened tab with the same leaf ids starts fresh.
  • Restart: main always spawns the plain shell under the pane's stable owner, with the tab's shell, the dead process's id kind and no surfacing, and the desktop pane attaches. The renderer restart message, its pending-restart latch and the routing predicate are gone.
  • Fixes along the way:
    • the published exited carries only exit code, cause and time;
    • subscribe frames derive exited without depending on write order;
    • a restart never shows the pane as removed;
    • desktop Delete Workspace ends the record;
    • no per-pane store subscription is added (the pane listener and hook budgets are unchanged);
    • a phone restart no longer moves desktop focus;
    • the overlay no longer claims preserved output over a blank remount.

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)

  • Desktop and SSH before vs after, on a remote Mac: identical.
  • Seeded walkthrough, with a local test-only patch: passes.
  • Windows: shell preserved on restart for Git Bash, PowerShell 7, Windows PowerShell 5.1 and WSL.

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:

  • a pane that mounts before the startup record read returns;
  • a WSL tab whose project runs on the Windows host can't be restarted from a phone (main already refuses that shell for a phone-created terminal);
  • a phone restart doesn't keep the pre-exit output;
  • a tab parked when its shell exits is still closed by today's renderer exit path.

@brennanb2025
brennanb2025 changed the base branch from brennanb2025/terminal-close-intents to main September 27, 2026 22:30
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main changes: an exit record for kept terminal panes, capability-gated publication, and one restart operation. It is specific and related to the changeset.
Description check ✅ Passed The description is comprehensive and follows the required template. It explains the user impact, implementation, rationale, testing, visual proof, compatibility considerations, known gaps, and checkli…
Full details: Docstring Coverage

Explanation

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 💡
  • Commit to this branch
  • Create a new PR
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch brennanb2025/terminal-exit-record
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: cbe60b92-47e6-464a-b861-013b5fb2930d

📥 Commits

Reviewing files that changed from the base of the PR and between 993183a and c5b58fe.

📒 Files selected for processing (103)
  • src/cli/handlers/terminal-close.ts
  • src/cli/handlers/terminal.test.ts
  • src/cli/terminal-format.test.ts
  • src/cli/terminal-format.ts
  • src/main/ipc/pty-ssh-undelivered-kill.test.ts
  • src/main/ipc/pty/runtime/controller.ts
  • src/main/ipc/pty/runtime/undelivered-ssh-kill.ts
  • src/main/ipc/pty/terminal-exit-record-delivery-order.test.ts
  • src/main/ipc/register-core-handlers/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers/register-core-handlers.ts
  • src/main/ipc/session.ts
  • src/main/persistence/loading-store/terminal-close-async-durability.test.ts
  • src/main/runtime/__fixtures__/orca-runtime-terminal-close-continuity-fixtures.ts
  • src/main/runtime/__fixtures__/orca-runtime-terminal-close-continuity-state-fixture.ts
  • src/main/runtime/orca-runtime-build-headless-mobile-session-browser-tabs.ts
  • src/main/runtime/orca-runtime-close-headless-mobile-terminal-tab.ts
  • src/main/runtime/orca-runtime-close-mobile-session-tab.ts
  • src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts
  • src/main/runtime/orca-runtime-on-pty-exit.ts
  • src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts
  • src/main/runtime/orca-runtime-prune-mobile-session-tab-group-layout.ts
  • src/main/runtime/orca-runtime-register-pty.ts
  • src/main/runtime/orca-runtime-resolve-worktree-removal-target.ts
  • src/main/runtime/orca-runtime-runtime-id.ts
  • src/main/runtime/orca-runtime-stop-explicitly-closed-tab-ptys.ts
  • src/main/runtime/orca-runtime-sync-mobile-session-tabs.ts
  • src/main/runtime/orca-runtime-terminal-close-continuity.test.ts
  • src/main/runtime/orca-runtime-terminal-close-no-widening.test.ts
  • src/main/runtime/orca-runtime-terminal-surface-close.test.ts
  • src/main/runtime/orca-runtime-test-scenario-builders.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-10.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs.spec.ts
  • src/main/runtime/orca-runtime-wait-for-leaf-pty-id.ts
  • src/main/runtime/rpc/methods/session-tab-terminal-exit-projection.ts
  • src/main/runtime/rpc/methods/session-tabs-inventory.ts
  • src/main/runtime/runtime-mobile-session-projection-contract.ts
  • src/main/runtime/runtime-mobile-session-projection.ts
  • src/main/runtime/runtime-notifier-contract.ts
  • src/main/runtime/runtime-pty-controller-contract.ts
  • src/main/runtime/terminal-close-observed-exit-test-fixture.ts
  • src/main/runtime/terminal-exit-records.ts
  • src/main/runtime/terminal-surface-close.test.ts
  • src/main/runtime/terminal-surface-close.ts
  • src/main/runtime/terminal-surface-exit-record.test.ts
  • src/main/window/runtime-window-lifecycle.ts
  • src/preload/api/session-bridge.ts
  • src/preload/api/ui-bridge-clipboard-and-window-controls.ts
  • src/preload/api/ui-bridge-terminal-and-session-tabs.ts
  • src/preload/api/ui-command-event-api.ts
  • src/preload/api/workspace-session-api.ts
  • src/renderer/src/components/terminal-pane/ExitedPaneProcessAttach.tsx
  • src/renderer/src/components/terminal-pane/TerminalPaneRuntimePortals.tsx
  • src/renderer/src/components/terminal-pane/TerminalProcessExitOverlay.test.tsx
  • src/renderer/src/components/terminal-pane/TerminalProcessExitOverlay.tsx
  • src/renderer/src/components/terminal-pane/closed-terminal-leaf-notice.test.ts
  • src/renderer/src/components/terminal-pane/closed-terminal-leaf-notice.ts
  • src/renderer/src/components/terminal-pane/pending-split-close.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-types.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-exited-leaf-mount.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-exited-process-attach.test.tsx
  • src/renderer/src/components/terminal-pane/terminal-pane-exited-restart-focus.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-pane-created.ts
  • src/renderer/src/components/terminal-pane/terminal-parked-pty-watcher.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-close-actions.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-process-exit-actions.ts
  • src/renderer/src/hooks/ipc-events-agent-status-window-test-fixtures.ts
  • src/renderer/src/hooks/ipc-events-close-routing-test-harness.ts
  • src/renderer/src/hooks/ipc-events-terminal-create-window-test-fixtures.ts
  • src/renderer/src/hooks/ipc-events-test-harness.ts
  • src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/mobile-terminal-close-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/terminal-exit-record-ipc-bridge.ts
  • src/renderer/src/hooks/useIpcEvents-browser-tab-create.test.ts
  • src/renderer/src/hooks/useIpcEvents-cli-worktree-activation.test.ts
  • src/renderer/src/hooks/useIpcEvents-close-routing-browser-pages.test.ts
  • src/renderer/src/hooks/useIpcEvents-close-routing-session-tabs.test.ts
  • src/renderer/src/hooks/useIpcEvents-lifecycle.test.ts
  • src/renderer/src/hooks/useIpcEvents-rate-limit-hydration.test.ts
  • src/renderer/src/hooks/useIpcEvents-ssh-disconnect-cleanup.test.ts
  • src/renderer/src/hooks/useIpcEvents-updater-status.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/terminals/terminal-actions.ts
  • src/renderer/src/store/terminals/terminal-exit-record-state.test.ts
  • src/renderer/src/store/terminals/terminal-exit-record-state.ts
  • src/renderer/src/store/terminals/terminal-state.ts
  • src/renderer/src/store/terminals/terminal-surface-close-intent.ts
  • src/renderer/src/store/terminals/terminal-tab-close-intent.test.ts
  • src/renderer/src/store/terminals/terminal-tab-close.ts
  • src/renderer/src/web/preload-api/web-ui-api.ts
  • src/renderer/src/web/preload-api/web-workspace-session-api.ts
  • src/shared/protocol-version.ts
  • src/shared/pty-liveness-verdict.ts
  • src/shared/runtime-mobile-session-tab-contracts.ts
  • src/shared/runtime-terminal-contracts.ts
  • src/shared/terminal-surface-close-target.test.ts
  • src/shared/terminal-surface-close-target.ts
  • src/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.

Comment on lines +101 to +110
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 }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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/main

Repository: 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.ts

Repository: 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.ts

Repository: 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.ts

Repository: 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.ts

Repository: 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/runtime

Repository: 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant