Skip to content

Layout groundwork (switched off): every question about which pane holds a terminal asks main's layout - #32002

Merged
Jinwoo-H merged 63 commits into
mainfrom
fd/a1b-pane-of-pty
Oct 22, 2026
Merged

Jinwoo-H merged 63 commits into
mainfrom
fd/a1b-pane-of-pty

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 133 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4635 $\color{#cf222e}{\Huge{\mathbf{−}}}$​903 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3732
Prod 100 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2041 $\color{#cf222e}{\Huge{\mathbf{−}}}$​370 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1671

ELI5

Each terminal record used to keep its own copy of which tab and pane it sits in. In the layout-owner build, main's layout already knows that, so the two copies could disagree. This PR sends every "which pane holds this terminal?" question through one function. Shipped builds get the record's copy back, exactly as before. Layout-owner builds ask main's layout and never touch the copy.

What Changed

All behaviour changes are behind the layout-owner build switch. Shipped builds are unchanged; see the bundle diff below.

  • One reader. paneOfPty (src/main/runtime/terminal/surface/pty-pane-query.ts) is the only reader of a PTY record's tabId, paneKey and graph stamp.
    • With the switch off, it returns the record's values.
    • With the switch on, it answers only from main's pane index. That index is created on first use, so a host with no window gets answers too.
    • Pure helpers receive it as a paneOf callback.
    • With the switch on, the record copies are never written; the writers that would set them return early.
  • A pane names its terminal only when it is that terminal. Main's layout binds a pane to a terminal id. It now answers for a registered terminal only when the workspace matches, and the incarnation matches whenever the binding carries one (terminalHoldsPane).
    • Without this, a terminal record made before its adoption registered (a server restart) matched by id alone. A paired desktop was then handed a second handle for the pane and stayed on it.
    • The same check stops a reused local id from claiming another workspace's saved pane.
  • Bind first. Every create path writes the pane binding before it registers the terminal. Registration checks this in tests and dev builds. A census test lists every registration site with the binding write that precedes it.
  • Closed panes, when the terminal exits later. Main's close drops a pane before its terminal exits.
    • Every live layout edit runs one dropped-leaf step (runDroppedLeafStep, src/shared/workspace-layout/workspace-layout-dropped-leaves.ts). It records each dropped pane's terminal in a new optional session field, closedTerminalPanesByPaneKey, which has the same TTL and cap as closed-tab records.
    • A pane moved to another tab or workspace is not dropped. Loading, restoring, peer merges and moves record nothing.
    • Exit cleanup reads main's layout first, then that record, matching both terminal id and incarnation, and removes the entry it used. Older builds drop the field.
  • Close paths after main's close.
    • A phone or headless tab close reads each row's live terminal before main drops the panes it is found by, so the terminal is still stopped.
    • A tab the window retired releases the owned terminal that main left in no pane.
  • Spilled tabs ([Bug]: exact terminal close snaps back when one worktree is split across local and runtime session partitions #18202). A local workspace's terminal tab that an older build saved into a paired server's partition is main's pane. Its terminals are local.
    • Workspaces count as local by the index's own routing (homeHostId, the same check owner partitions use).
    • A tab or terminal the local partition also holds is indexed once, from there. SSH and server-owned workspaces are skipped as before.
  • Whether a terminal still runs is never read from the pane. A pane main's layout owns is no proof its terminal runs. The host's inventory and the terminal's record decide: a shell the host no longer lists reads disconnected, never exited, and an SSH terminal whose relay did not answer stays unverifiable. Stop targets, exit waits and the agent-launch check use main's holds check (workspace and stamped incarnation), so a disconnected terminal main still binds stays a stop target and an exit wait keeps waiting until an exit event arrives.
  • Exited split panes (corrects Layout groundwork (switched off): main creates, starts and closes terminal tabs and panes itself #31130's rule). Main keeps a split pane whose terminal ended with any non-zero code, negative included, and closes it on 0, as the window does (pty-exit-hibernate.ts reads only the code). Layout groundwork (switched off): main creates, starts and closes terminal tabs and panes itself #31130 closed it on a negative code a stop or the host vouched for, so an SSH pane whose host confirmed its shell ended lost its leaf instead of letting recovery start a shell in it.
  • A stale handle of a replaced pane. A handle carries the pane it was issued for (issuedForPaneKey, on the handle record only, never on the wire). Recovery with that handle learns the replacement terminal only when its own terminal ended, the replacement is connected and bound at that pane now, and the workspace matches; otherwise it is refused as before. The client fallback is unchanged (remote-runtime-pty-transport.ts:1616-1620).
  • A reused terminal id. A spawn commit that binds a reused local id unbinds it from the older process's saved pane, inside the same binding write (applyPtyBinding). A new process under a reused id also starts with no exit code, so an exit wait on it cannot settle on the earlier process's code.
  • One write per exit. The exit drops the closed-pane record entry inside the retirement write for that pane (stageTerminalSurfaceRetirements), re-checked by terminal id and incarnation. An exit that keeps the surface (relay contact lost, intentional stop) keeps the entry until a confirmed exit or its TTL.
  • One own-handle rule (L250). A terminal's own handle names it when main's pane binds it, with or without a window. fix(runtime): a server with no window answers its first terminal create, not 'handle stale' (switch-on builds only) #31391's windowless branch is gone.
  • Visible differences, switch-on only:
    • terminal resolve-pane on a pane whose failed start withdrew its tab now returns the existing terminal_not_found error, where it used to return a disconnected stub. The callers already handle it:

      1. stable-owner.ts:78-117 resolves to null either way (the error is caught at :85).
      2. structured-session-cli-writer-host.ts:41 returns at its precheck (:36-37) first, and catches a throw as {pane:null}.
      3. resolve-terminal-pane.ts:118 runs only for a connected PTY, so it never reaches this case.
      4. CLI terminal-identity.ts:132 treats terminal_not_found as isPaneRemintUnavailableError (:150), so the handle resolves to undefined. Base returned a dead handle that failed later with terminal_gone.
      5. terminal-handle-copy.ts:39 shows the error instead of copying a dead handle. There is no pane left to right-click.
      6. pty-kitty-file-reader.ts:38 fails either way (base: "Terminal binding changed").
      7. remote-runtime-pty-transport.ts:
      8. web-session-terminal-orphan-recovery-pane.ts:139 resolves to null either way (base's stub read as disconnected).

      Mobile has no caller; its two matches are resolvePanelAction.

    • orca terminal wait --for exit on a terminal that disconnected without an exit event keeps waiting while main's layout still binds it; base returned at once.

    • Stopping a workspace's terminals also stops a disconnected terminal main still binds.

    • A split pane whose terminal ended with a negative code keeps its leaf (its "Terminal exited" card), including on SSH when the host confirmed the end, as the window already does.

    • A recovery with the handle of a pane whose terminal was replaced returns the connected replacement instead of terminal_not_found.

    • A terminal the host no longer lists reads disconnected, not exited, in terminal list and worktree ps.

The runtime: surviving-terminal rescue (renderer-session-terminal-rescue.ts:13) is unreachable in production for a paired server's workspace:

  • Its two ownership writers (mobile-terminal-surface.ts:197, terminal-split-surface.ts:121) need a local spawn.
  • perform-mobile-session-pty-records-refresh.ts:65 never builds local records for runtime hosts.

So the switch-on test asserts that nothing is rescued.

Why

  • One reader in both modes makes the later deletion of the copies mechanical and leaves shipped builds untouched.
  • The alternatives:
    • Keep writing the copies as a fallback. That keeps two answers alive in layout-owner builds, and this branch shows how they diverge.
    • Delete the window-owned path now, before its time.
  • The closed-pane record is a separate field rather than an addition to closed-tab records. A closed-tab entry keyed by a surviving tab makes every reader, in this build and in older ones, treat that tab as closed.

Linked Issue

Part of the terminal layout final design (A1b: one reader of a terminal's pane). Ledger rows L80 and L250.

Visual Proof

N/A: no change in shipped builds (the switch is off); the switch-on server specs below cover the paired phone and desktop flows.

Testing

Head 3764776. The branch carries main up to B = f8aa685 (merged twice, no rebase; see "Merge of main"). Each gate below also ran on a scratch merge of the head with a later main, against that main: the merge was made, never committed, and its tree is recorded. Platforms: macOS, unit tests and hidden-window e2e. SSH and paired-server paths are covered by the unit suites and the four server specs.

A correction. Earlier versions of this body reported "switch-on" full-suite numbers that were in fact switch-off runs. The runner script set ORCA_LAYOUT_OWNER=main only for the package build, not for vitest. The real switch-on runs below export the variable and log owner=main. The real runs found six tests that pass at base and fail at the head with the switch on; the disguised runs had hidden them. Commit 3764776 converts all six. All six are listed under "The six tests the real runs found".

Full suite. run-vitest (the CI runner) over src/main/runtime src/main/persistence, pinned Bun 1.4.3, per test. No file ran zero tests. Pass / fail / skipped:

Gate Base Head Pass at base, fail at head
Earlier "switch on" (really off): b9bc689 vs 4dd97f0 17129 / 4 / 33 17209 / 4 / 36 0
Real switch on: e04678e vs B f8aa685 17116 / 12 / 47 17185 / 18 / 55 6 (below)
Real switch on: merge of 3764776 with main e710e89 (tree 9b913876a545) vs e710e89 17112 / 12 / 51 17187 / 12 / 59 0, no new failures
Switch off: the same merge (tree 9b913876a545) vs e710e89 17134 / 4 / 37 17216 / 2 / 40 0, no new failures
  • The 12 failures with the switch on fail on both sides:
    • persistence-empty-root-layout-load ×3;
    • orcad-migration ×4 (received-blob, restore hints, catalog ×2);
    • the existing-folder imports in orca-runtime.test.ts ×2 (they read this machine's git setup);
    • profile-state-backup-worker ×2;
    • live-store-factory ×1.
  • With the switch off, only the two existing-folder imports fail at head. At base the two backup-worker timing tests also failed. They are flaky on both sides: rerun alone, head failed 1, 1 and 0 of 18 and B 0, 1 and 2.
  • 10 base test names are absent at head. All were renamed or converted, as listed before: the exit-rule tests, the pinned-tab table, the headless create cases, two surface-reply tests and one summary test.
  • Proof the switch was on:
    • every run's log prints owner=main or owner=;
    • at the head, switch-on skips 59 and switch-off skips 40;
    • 21 tests that pass with the switch off are skipped with it on, and 2 tests pass only with it on. For example, runtime-graph-standing-contracts.test.ts "terminal inventory after a pane is dropped keeps a pane main's layout still binds attached …" and orca-runtime.test.ts "returns the exact pre-minted leaf for concurrent renderer-backed splits, each started by main".

Targeted switch-on runs against later mains (pinned Bun, owner=main logged):

The six tests the real runs found. Each verdict was checked by an Opus reviewer asked "is this conversion hiding a bug?". The answer was no for every one, so none became it.fails.

  • terminal-intentional-stop-exit.test.ts "never reads the exit of a later process on the same id as the stop": before, the later process registered (registerPty) and then its pane binding was saved; now the binding is saved first and the process registers after it. The assertions are unchanged: the later process's exit retires the pane and reaches the renderer as code 0 for the later incarnation. This is correct because production saves the spawn's pane binding before it registers the terminal (src/main/ipc/pty/spawn-commit-assembly.ts:155 before :160), and with the switch on a registration ahead of its binding is the bind-first violation pane_unbound_at_registration (src/main/runtime/terminal/lifecycle/bind-first-registration.ts:15). No it.fails.
  • orca-runtime-terminal-split-authority.test.ts "rejects a persisted-only source incarnation change during spawn" and "preserves the split error and takes back the pane when kill and retirement throw": before, both modes seeded the source pane's saved incarnation as persisted-before while the live source terminal carried none; now, with the switch on only, the source terminal registers as persisted-before, so the pane and its terminal agree. The assertions are unchanged: a saved-only change to persisted-after during the spawn rejects the split as terminal_split_source_not_found, stops or kills the new terminal, retires it, and takes the pane back. This is correct because main stamps a pane with its spawning terminal's incarnation (src/main/persistence/loading-store/pty-binding-session-update.ts:52), and main's lookup holds a pane only for the terminal whose incarnation matches that stamp (src/main/runtime/terminal/surface/terminal-surface-index.ts:354). The old switch-on precondition, a pane stamped for a different process, cannot arise. Main correctly answered "stale handle" before the spawn even began, so the test never reached the change it exists to check. Switch-off is unchanged. No it.fails.
  • graph-sync-live-daemon-pty-tab-preservation.test.ts "a real paired close de-persists the CLI terminal and stops preserving it": before, the fake stopAndWait returned true and delivered no exit; now it calls runtime.onPtyExit(ptyId, 0) and then returns true. The assertions are unchanged: the tab is de-persisted, runtimeSessionOwned goes false, and the tab is not preserved after the next sync. This is correct because the real stopAndWait returns true after the exit has been delivered or waited for: a synthetic exit at src/main/ipc/pty/runtime/kill.ts:319, or a wait for the observed exit record at :324 (bounded by the close deadline, so on SSH it can return before the exit arrives; the exit then clears ownership on arrival), before return true at :326. That exit is what clears ownership (src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts:250). At B the switch-on run never bound the CLI pane, so main's close (src/main/runtime/session-lifecycle/close/close-mobile-row-in-main-layout.ts:26) never ran and the window-era headless close cleared the flag instead. Switch-off does not call stopAndWait on this path. No it.fails.
  • orca-runtime-codex-idle-title-chat-address.test.ts (5 tests; 2 failed with the switch on): before, the runtime had no store (null) and a fake spawn that bound no pane; now, with the switch on only, it gets a minimal store, and the spawn binds the pane through the spawn-commit stand-in. The assertions are unchanged: Codex's idle title outranks the older hook state, and a shell title retires the pane. This is correct because, with the switch on, a terminal's pane comes only from main's layout (src/main/runtime/terminal/surface/pty-pane-query.ts:38-41), and production always builds the runtime with a store (src/main/startup/main-process-runtime-service.ts:88, src/main/orcad/orcad-entry.ts:223). With no store, main owns no pane, so the title facts had no pane to reach. Switch-off is unchanged. No it.fails.
  • Tracked for f1, not this PR, from that review:
    • L320: a terminal record with an unknown incarnation loses its stamped pane until it re-registers.
    • L321: a paired close whose stop is unconfirmed has no switch-on test. Main's row close leaves runtimeSessionOwned set until the exit, where the window-era close clears it at once.

Expected failures with the switch on.

Census:

  • type-aware: pnpm test src/main/runtime/terminal/surface/pty-pane-copy-census.test.ts;
  • bind-first: pnpm test src/main/runtime/terminal/lifecycle/bind-first-registration-census.test.ts. It now follows the single spawn-commit step src/main/ipc/pty/spawn-commit-assembly.ts that refactor(pty): one commit step for both terminal start lanes #31596 introduced;
  • tables and live-edit: pnpm test src/main/persistence/closed-terminal-panes-registration.test.ts.

Server specs, on the merge with 24f5c57 (tree c5fcc66a067d) vs 24f5c57. These ran in hidden windows on the switch-on build, with one worker:

  • paired-mobile-desktop-tab-composition, paired-desktop-server-layout-frames, headless-serve-focused-terminal-create and live-background-terminal-mount-authority: 4/4 passed on both sides;
  • paired-desktop-server-layout-frames repeated 6 times: 6/6 on both sides.

Static gate:

  • pnpm tc passes;
  • ci-static-gate passes;
  • check:code-quality:changed reports 0 new findings;
  • the layout-writer ratchet passes at every file's baseline, with no bump.

Why the pinned Bun: an older local Bun (1.3.14) cannot load node:sqlite, so 55–65 files ran no tests under it. Every comparison here has no file that ran zero tests.

Merge of main

origin/main B = 4dd97f0 merged once (a0c75cb, no rebase); the branch's base was 3b02945. Conflicts, each checked against both parents:

  • src/shared/workspace-layout/workspace-layout-command-types.ts: both sides' new optional fields kept (this branch's droppedLeafReason; main's isBindingLive, retiresBinding).
  • src/main/runtime/terminal/surface/terminal-surface-index.ts: imports; main moved bindingOf to pane-live-facts, this branch's other imports kept. bind-first-registration.test.ts now imports bindingOf from there too.
  • src/main/runtime/session-lifecycle/projection/apply-mobile-session-tab-navigation.ts: imports; main's findPaneSleepingRecord and top-level switch import kept, this branch's duplicate import dropped, the unused worktreeIdsEqual dropped as main did.
  • src/main/runtime/terminal/launch/mobile-terminal-chat-fork.test.ts: both sides' imports.
  • src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.ts: main's version. This branch had copied A phone keeps a desktop's untitled markdown tab read-only (dark, layout-owner build only) #31667's fixture and marked its three untitled cases expected-to-fail until A phone keeps a desktop's untitled markdown tab read-only (dark, layout-owner build only) #31667 arrived; main has it, so they are plain tests and pass.

After the merge two files went over the line limit; b9bc689 moves this branch's additions into helpers (paneHoldsSession in main-terminal-surfaces.ts, and one parent-class method for a closed tab's live terminals), behaviour unchanged. An Opus review of the resolution found nothing: no lost side, and none of main's new code reads a terminal record's pane fields directly, registers before binding, or relies on a pane existing as proof its terminal runs.

Second merge: B = f8aa685 (#31924), merged as ef7b85c (no rebase).

  • main-layout-session-tab-move.ts: both sides' methods are kept.
  • mobile-session-tabs-headless-chat-rebuild.spec.ts: main's version is taken, so main's L283 test is a plain test.
  • L288's it.fails marks are dropped, because its cases pass.
  • Follow-up e04678e (test only):
    • refactor(pty): one commit step for both terminal start lanes #31596 moved every spawn commit into one step, src/main/ipc/pty/spawn-commit-assembly.ts, so the bind-first census follows that step, with savePtySpawnPaneBinding( and adopted.owner as its binds;
    • the test that registers a terminal unbound opts its controller out of the suites' stand-in commit (leaveSpawnsUncommitted).
  • An Opus delta review of this merge's resolution found nothing.

AI Disclosure

Review

  • Opus review of the branch, and delta reviews of every fix after it. Findings fixed: the closed-pane entry left in its own session write (now inside the exit's retirement write), the reused-id unbind's own writes (now folded into applyPtyBinding), and the recovery handle lookup that had moved ahead of the cheap guards and so ran with the switch off on a refused recovery.
  • A finding from the review: a reused terminal id kept the earlier process's exit code, so with the switch on an exit wait on the new process could settle at once during a host listing gap. Fixed: a new incarnation clears the code (switch-on only), with a test that fails without the fix. A delta review of that fix and the last test conversions found nothing blocking.
  • Commit 3764776, the six switch-on test conversions: an Opus delta review and a separate "is this conversion hiding a bug?" review both found no hidden bug. Their two low notes are L320 and L321, tracked for f1.
  • Merge of main: an Opus review of the resolution found nothing (see "Merge of main"); an Opus classification of the switch-off bundle against B found no behaviour change.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Wire: no new fields or opcodes; replies keep today's shapes. The handle's issue-time pane stays on the handle record and never goes on the wire. The new session field closedTerminalPanesByPaneKey is optional; older builds drop it.
  • SSH: an SSH terminal whose relay did not answer stays unverifiable; an SSH pane whose host confirmed its shell ended keeps its leaf. Paired-server (runtime:<env>) workspaces are that server's layout and are not indexed.
  • Folder workspaces: main's index routes them by the same owner partitions as git worktrees.

Switch-off bundle diff. Built with the switch off from the merge with 24f5c57 (tree c5fcc66a067d) and from 24f5c57 itself. Chunk hashes and short minified names are normalized. Counts are the same as against the older main, except Rename-only, which is 106 here (105 before) because one more minified name shifted. The renderer differs only by the build's commit stamp and the closedTerminalPanesByPaneKey entry in two field-ownership tables, which act only when that field is present; switch-off never writes it. Every one of the 263 hunks of main/index.js has a class:

Class Hunks Why switch-off is identical
Rename-only 106 Minifier renames from two new exports, checked against the export definitions.
Pane reads via paneOfPty / paneOf 74 With the switch off it returns the record's own tabId, paneKey and stamp (pty-pane-query.ts); records always hold a string or null there, so the ?? never fires.
Folded switch points 29 Exit settling, liveness, the closed-pane lookup (null), stop targets (an empty loop), the own-handle rule, the handle stamp and the exit-code clear all fold to base behaviour; setPtyConnected's extra call is a pure read.
Main's surface publisher and index 15 Unreachable: the publisher is only made from switch-on paths.
Closed-pane field and dropped-leaf step 12 The step folds to returning the model; the rest acts only when the field is present.
applyPtyBinding 9 The unbind is null, so the writes reassign the same objects.
Moved methods 7 hasLiveTerminalForPaneKey, liveTerminalsOfClosedTab, paneHoldsSession: same logic.
Surface-topology helpers 4 Same writes; ?? 0 matches the existing constant.
paneOfPty's home 4 Returns the record copy.
Recovery handle check 2 handleNamesRecoveredPane folds to getPaneKeyForTerminalHandle(handle) === paneKey after the same guards.
Commit stamp 1 The commit id.

Chunks: orcad-migration-source-retention, 22 hunks (20 renames; 2 closed-pane field code that acts only when the field is present); ssh-renderer-broadcast, 5 hunks (the closed-pane schema and helpers, the optional session field, a field-ownership entry, 2 unused export getters).

Hunks that run with the switch off and do more than pass a value through, each identical: a dead endVouched read is gone (pty-exit-lifecycle.ts); the holder check re-reads the PTY list per pane (perform-mobile-session-pty-records-refresh.ts), with no side effects; workspace-removal-target.ts reads a tab id once instead of twice, and the call between only rewrites session rows; the layout command context calls Date.now(); the retirement's closedPane is always undefined. One theoretical difference: a saved session that already holds closedTerminalPanesByPaneKey (only switch-on builds write it) keeps the field where base drops it on load.

Every non-rename hunk was checked by hand against the source delta; renames by pattern, with the export shift verified.

Checklist

  • This PR is small and focused (it is not: every reader of a terminal's pane moves in one step so the two answers cannot diverge; the shipped-build change is the bundle diff above)
  • 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)

…eOfPty (L80)

With the layout-owner switch on, main's layout answers which tab and pane hold a terminal, and
nothing reads or writes the PTY record's tabId/paneKey copies or their graph stamp. Switch-off
reads the copies exactly as before.
…raph

A headless host never installs a window graph, so the query asked a publisher that did not exist
and every terminal read as paneless. The index is now made on first query; it publishes only once a
graph is installed, as before.
… as the spawn commit does (L80)

Also, with the switch on: skip the bind-first check for a paired server's workspace, release a
closed tab's terminal ownership once main has dropped the pane, and publish a pane's agent status
from the terminal main's layout binds it to.
…ires (switch-on only, L80 Q2)

Main's layout write records every pane it drops whose terminal no pane holds any more, in a new
optional session field closedTerminalPanesByPaneKey (same TTL and cap as closed-tab records).
Exit cleanup reads main's layout first, then that record by terminal id and incarnation, and
removes the entry it used. Older builds ignore the field.
…switch-on only, L80 Q2)

The step receives each dropped pane (host, worktree, tab, leaf, terminal, incarnation), computed
across the whole layout so a moved pane is not dropped, and runs only for a commit that declares a
live edit. Today it records the closed-pane entries; a drop is recorded once per terminal.
…its live terminals after main's layout drops the panes (switch-on only, L80)

The headless close reads each row's live terminal before main's close drops the panes it is found
by, and a renderer-retired tab releases the owned terminal main left in no pane, as the explicit
close already did. Close tests now commit through main's layout and bind panes first.
…r's partition is main's pane (switch-on only, L257)

Older builds could save a local worktree's tab rows into a runtime partition (#18202); its terminals
are local, so main's index takes those tabs for workspaces the router homes locally. A tab or
terminal the local partition also holds is indexed once, from there; SSH and server-owned
workspaces are skipped as before.
…minal_not_found in layout-owner builds (L80 #7)

Main's layout no longer holds the pane, so there is no pane to answer for; window-owned builds keep
the disconnected stub from the exited terminal's record.
…e and spawn commit do (L80)

Fake PTY spawns commit the binding into the pane the runtime wrote, stores list their partitions,
and SSH sessions sit in their ssh:<conn> partition; terminals registered directly bind first.
…kspace and stamped incarnation match (switch-on only, L80)

A record made before its adoption registers (a host restart) or a local id reused after one
matched a saved binding by id alone, so a phone or paired desktop could be handed a second handle
for the pane before the terminal's own handle arrived and stay on it.
…nd no local record rescues a paired server's tab (L80)
… production does (L80)

A recoverable pane is one the host inventory dropped with no exit, live terminals register
rather than appear only in the window graph, and SSH stores route as the real Store does.
# Conflicts:
#	src/main/runtime/orca-runtime-cold-restore-terminal-membership.test.ts
#	src/main/runtime/orca-runtime-terminal-cwd.test.ts
#	src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-08.spec.ts
#	src/main/runtime/session-tabs/session-tabs-inventory.ts
#	src/main/runtime/terminal/query/pty-terminal-summary.ts
#	src/main/runtime/terminal/surface/terminal-surface-index.ts
#	src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.ts
#	src/main/runtime/workspaces/workspace-removal-target.ts
…tion does; PR-1's main-layout closes in the part-10 and part-11 close tests (L80)
…ofile does; PR-1's own closes in the part-05, part-08 and UUID-leaf close tests (L80)
…eeping bind-first under the line limit (L80)
… layout closes with the switch on (#31571), in the no-widening and surface-close tables (L80)
…he other pane that held the session (layout-owner build, L80 P1)
… with no registered terminal, under the line limit (L80 P1)
…nbinds it from the saved pane of the older process (layout-owner build, L80 P2)
…leaf ids per pane, and a window that draws main's own panes (layout-owner build, L80)
…t was resolved for that pane, its own terminal ended, and the replacement is connected there now (layout-owner build, L80)
…main's layout order rules); headless phone tab order is L283
…55, L256, L259a, L259b); a same-id respawn's commit stamps its incarnation; the crossing terminal binds first
…ace fence (L256 switch-on variant); the placement test's tabs are main's saved layout
…tamp on the handle record, not a second map; moved-pane, restart and single-reader tests (layout-owner build, L80)
…n's rename, and a mobile-created tab's live shell is the one its commit registers (layout-owner build, L80)
…rkspace and incarnation), and any exit event settles a later wait (review)
… that retires the pane, and an unbind folds into the binding write (layout-owner build, L80)

The exit used to remove main's closed-pane entry in a session write of its own, before the
retirement write. It now reads the entry, and the retirement write for that pane drops it,
re-checked by terminal id and incarnation. An exit that keeps the surface (relay contact lost,
intentional stop) keeps the entry until a confirmed exit or its TTL.

A reused terminal id's unbind is now a pure computation that applyPtyBinding applies through
its existing writes. Two split-pane tests still expected a -1 exit to close the pane; they now
follow the ruling that any negative code keeps it. Static-gate fixes: test fixtures and tests
use typed member access instead of Reflect, and no longer use type assertions.
…and the L283 store lists its partitions, as a profile Store does; L289's test passes on that store (layout-owner build, L80)

The fixture store bindPaneFirst fills now tells write listeners of every session write, direct or
by a layout command, so main's post-commit merge runs as it does on a real Store. The notice is
not enumerable, so a test's own `{ ...store }` copy, which keeps its writes elsewhere, does not
inherit a subscription it would never fire. With it, the targeted split-group create (L289) passes
at this head, so its it.fails mark goes. L283's test runs on a store that names its partitions and
stays it.fails("L283").
…ards again, so the switch-off build re-issues no handle on a refused recovery (layout-owner build, L80)

The stale-handle switch point had moved the handle lookup ahead of the pane, terminal and
workspace checks. That lookup can re-issue a handle, so a switch-off recovery refused on those
checks gained a side effect base never had. The lookup runs after them again, and the switch-on
replacement check lives in one method.
…e binding before main registers the terminal, as the host does (L80 switch-on variant)

The window-tab start test came in with the main merge after bind-first; its fake spawn returned
a terminal no pane was bound to, so registration refused it. The fixture's spawn now binds the
pane first, as every other bind-first fixture does.
…o exit code, so an exit wait on it cannot settle on the old process's code (layout-owner build, L80)

The record of a reused id kept the earlier process's lastExitCode, and with the switch on an exit
wait settles on any recorded code once the terminal reads disconnected. A new incarnation now
clears the code and cause. Also drops the L283 test's partition-list option: the fixture store
already lists its partitions.
…ever loaded (L80)

- A restored pane's host lists the terminal it started; a pane main owns vouches for none.
- The other pane holding a slept session is in main's layout, so an unverifiable holder blocks
  the resume as it does through a window.
- Main sleeps a workspace whose panes it lists itself, even with a renderer attached (#31571).
- A graph sync no longer reconnects a disconnected terminal of main's pane; the inventory decides.
…store, and the untitled cases wait on L268 with the switch on

The window's tab uses main's id (the file path), and the store lists its partitions and saves each
open editor's unified tab and group, as the window does (the fixture from #31667). With the
switch on, the three untitled cases fail on L268, main's row merge dropping the untitled flag,
which #31667 fixes; they are it.fails until A1b's history includes it.
…ane-of-pty

# Conflicts:
#	src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.ts
#	src/main/runtime/session-lifecycle/projection/apply-mobile-session-tab-navigation.ts
#	src/main/runtime/terminal/launch/mobile-terminal-chat-fork.test.ts
#	src/main/runtime/terminal/surface/terminal-surface-index.ts
#	src/shared/workspace-layout/workspace-layout-command-types.ts
…ing A1b's additions to their helpers (L80)

After the main merge, the holder-pane check and a closed tab's live-terminal lookup pushed two
files past the line limit. The holder check is now paneHoldsSession (main-terminal-surfaces.ts)
behind one method, and the closed tab's lookup is one parent-class method. Behaviour unchanged.
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7825ee76-6faf-49e8-90ac-e7615a05cf1d
📥 Commits

Reviewing files that changed from the base of the PR and between 3764776 and dc3dde2.

📒 Files selected for processing: 2
  • src/main/runtime/graph-sync-live-daemon-pty-tab-preservation.test.ts
  • src/main/runtime/orca-runtime-codex-idle-title-chat-address.test.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.

📝 Walkthrough

The change adds closed-terminal-pane records to workspace-session persistence and layout-drop processing. Main-owned layouts resolve pane identity from the layout, enforce bind-before-register behavior, track liveness from host inventory, preserve recovery state, and reconcile exited terminals. Runtime tests and fixtures update spawn, registration, close, recovery, and ownership scenarios for both layout-owner modes.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to dc3dd

Stale pane records and duplicate session resumes remain possible; resolve these terminal-lifecycle issues before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 97 functions across 71 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: routing terminal-pane ownership questions through main's layout. It is specific and related to the changeset.
Description check Passed The description is detailed, on-topic, and covers the required change summary, rationale, testing, review, compatibility, and checklist sections. The Linked Issue section does not include an actual is…
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.
Full details: Description check

Explanation

The description is detailed, on-topic, and covers the required change summary, rationale, testing, review, compatibility, and checklist sections. The Linked Issue section does not include an actual issue link or Fixes reference, and the Testing checkboxes remain unchecked despite detailed test results.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 75cef880-a272-4bd8-9cb5-05fe96112c71
📥 Commits

Reviewing files that changed from the base of the PR and between 4dd97f0 and 2b14a66.

📒 Files selected for processing: 230
  • src/main/orca-profiles/profile-project-session-field-disposition.ts
  • src/main/persistence/closed-terminal-panes-registration.test.ts
  • src/main/persistence/loading-store/pty-binding-session-update.ts
  • src/main/persistence/loading-store/pty-spawn-exit-durability.test.ts
  • src/main/persistence/loading-store/reused-terminal-id-unbind.test.ts
  • src/main/persistence/loading-store/reused-terminal-id-unbind.ts
  • src/main/persistence/restoring-sessions/session-owner-removal.ts
  • src/main/persistence/restoring-sessions/session-worktree-ownership.ts
  • src/main/persistence/terminal-topology/layout-owner-written-session-golden.test.ts
  • src/main/persistence/terminal-topology/terminal-layout-pane-ops.test.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/persistence/terminal-topology/unshown-live-terminal-placement-restart.test.ts
  • src/main/persistence/tracking-repos/worktree-identity-migration-field-coverage.test.ts
  • src/main/persistence/tracking-repos/worktree-identity-migration.ts
  • src/main/runtime/__fixtures__/main-layout-close-fixture.ts
  • src/main/runtime/__fixtures__/orca-runtime-terminal-close-continuity-fixtures.ts
  • src/main/runtime/agent-transcript-pane-test-harness.ts
  • src/main/runtime/bind-first-pane.test-fixture.ts
  • src/main/runtime/construction/runtime-construction-services.ts
  • src/main/runtime/construction/runtime-identity-state.ts
  • src/main/runtime/construction/runtime-service-state.ts
  • src/main/runtime/exited-split-pane-layout-close.test.ts
  • src/main/runtime/floating-terminal-inventory-ownership.test.ts
  • src/main/runtime/graph-sync-live-daemon-pty-tab-preservation.test.ts
  • src/main/runtime/headless-create-terminal-handle-main.test.ts
  • src/main/runtime/headless-placeholder-graph-surface-standing.spec.ts
  • src/main/runtime/held-pane-reopen-layout-owner.test.ts
  • src/main/runtime/host-sleep-resume-record.test.ts
  • src/main/runtime/mobile-session-resume-identity.test.ts
  • src/main/runtime/omp-user-bubble-launch-authority.test.ts
  • src/main/runtime/opencode-finished-session-authority.test.ts
  • src/main/runtime/orca-runtime-cold-restore-terminal-membership.test.ts
  • src/main/runtime/orca-runtime-default-tab-agent-status.test.ts
  • src/main/runtime/orca-runtime-default-tabs-layout-owner.test.ts
  • src/main/runtime/orca-runtime-exited-split-pane-close.test.ts
  • src/main/runtime/orca-runtime-failed-start-pane-layout-owner.test.ts
  • src/main/runtime/orca-runtime-get-status.ts
  • src/main/runtime/orca-runtime-hook-agent-status-projection.test.ts
  • src/main/runtime/orca-runtime-layout-owner-start-fixture.ts
  • src/main/runtime/orca-runtime-mobile-agent-status-ordering.test.ts
  • src/main/runtime/orca-runtime-mobile-close-preserved-resurrection.test.ts
  • src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.ts
  • src/main/runtime/orca-runtime-provider-reattach-launch-identity.test.ts
  • src/main/runtime/orca-runtime-session-tabs-path-alias.test.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-create-replay-after-close.test.ts
  • src/main/runtime/orca-runtime-terminal-cwd.test.ts
  • src/main/runtime/orca-runtime-terminal-handle-incarnation.test.ts
  • src/main/runtime/orca-runtime-terminal-rename-retention.test.ts
  • src/main/runtime/orca-runtime-terminal-split-authority.test.ts
  • src/main/runtime/orca-runtime-terminal-surface-close.test.ts
  • src/main/runtime/orca-runtime-test-fixtures.spec.ts
  • src/main/runtime/orca-runtime-test-lifecycle.spec.ts
  • src/main/runtime/orca-runtime-tests/agent-status-and-waits.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-creation-and-orchestration-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-creation-and-orchestration.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-headless-chat-rebuild.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-04.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-05.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-06.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-07.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-08.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-09.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-10.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-11.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-12.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-13.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-shell-selection.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-summaries-part-02.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-summaries-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/program-status-osc.spec.ts
  • src/main/runtime/orca-runtime-tests/split-placement-session.test-fixture.ts
  • src/main/runtime/orca-runtime-tests/targeting-and-resilience.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-02.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-05.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-08.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-handles-and-agent-status-part-04.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-handles-and-agent-status-part-05.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-handles-and-agent-status.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-handles-part-02.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-handles.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery-part-02.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery-part-06.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-output-and-worker-recovery.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-side-effect-facts.spec.ts
  • src/main/runtime/orca-runtime-tests/terminal-sleep-and-teardown.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-ps-agent-row-dismissal.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-terminal-close-reattached-relay.spec.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration-mailbox-notification-consistency.test.ts
  • src/main/runtime/orchestration-mailbox-notification-test-harness.ts
  • src/main/runtime/orchestration/db/hot-path-statement-compilation.test.ts
  • src/main/runtime/orchestration/terminal-authority/verify-orchestration-compatibility-caller.ts
  • src/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.ts
  • src/main/runtime/orchestration/terminal-pane-mail-routing.ts
  • src/main/runtime/owned-session-teardown-policy.test.ts
  • src/main/runtime/paired-close-retirement-proof-publication-order.spec.ts
  • src/main/runtime/paired-host-terminal-close.test.ts
  • src/main/runtime/profile-session-store.test-fixture.ts
  • src/main/runtime/pty-exit-agent-status-reconciliation.spec.ts
  • src/main/runtime/pty-inventory-lifecycle-fixture.ts
  • src/main/runtime/pty-inventory-liveness-verdict.spec.ts
  • src/main/runtime/pty-recorded-surface-topology.test.ts
  • src/main/runtime/pty-recorded-surface-topology.ts
  • src/main/runtime/qoder-independent-spawn-review.test.ts
  • src/main/runtime/qoder-mobile-resume-adoption.test.ts
  • src/main/runtime/restored-pane-start-cli-handles.test.ts
  • src/main/runtime/restored-pane-start-layout-owner.test.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation-liveness-verdict.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-mobile-report.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release-runtime-incarnation.spec.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-release.test-support.ts
  • src/main/runtime/rpc/methods/structured-agent-session-adoption-replay.test.ts
  • src/main/runtime/rpc/orchestration-runtime-update-settlement.test.ts
  • src/main/runtime/runtime-agent-orchestration-projection.ts
  • src/main/runtime/runtime-created-worktree-terminal-target.test.ts
  • src/main/runtime/runtime-graph-mirror-capture.test.ts
  • src/main/runtime/runtime-mobile-session-projection.ts
  • src/main/runtime/runtime-owned-terminal-publication-lineage.test.ts
  • src/main/runtime/runtime-rpc-mobile-terminal-streaming.test.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/runtime-terminal-orphan-adoption-duplicate-pty.test.ts
  • src/main/runtime/runtime-terminal-orphan-adoption-plan.ts
  • src/main/runtime/runtime-terminal-orphan-adoption-rollback.test.ts
  • src/main/runtime/runtime-terminal-state-records.ts
  • src/main/runtime/runtime-worktree-ps-activity.ts
  • src/main/runtime/session-graph/session-graph-promotion.ts
  • src/main/runtime/session-graph/session-window-graph.ts
  • src/main/runtime/session-lifecycle/close/closed-tab-terminal.ts
  • src/main/runtime/session-lifecycle/close/has-live-or-persisted-serve-or-ssh-owned-pty-binding.ts
  • src/main/runtime/session-lifecycle/projection/apply-mobile-session-tab-navigation.ts
  • src/main/runtime/session-lifecycle/projection/prune-mobile-session-tab-group-layout.ts
  • src/main/runtime/session-lifecycle/projection/reconcile-headless-mobile-session-browser-tabs.ts
  • src/main/runtime/session-tabs-inventory-publication.test.ts
  • src/main/runtime/session-tabs/explicit-terminal-close-stops.ts
  • src/main/runtime/session-tabs/headless-terminal-tab-close.ts
  • src/main/runtime/session-tabs/main-layout-agent-launch-tabs.ts
  • src/main/runtime/session-tabs/mobile-session-membership.ts
  • src/main/runtime/session-tabs/mobile-session-preservation.ts
  • src/main/runtime/session-tabs/renderer-session-terminal-rescue.ts
  • src/main/runtime/session-tabs/session-tabs-inventory.ts
  • src/main/runtime/session-tabs/terminal-surface-retirements.ts
  • src/main/runtime/stale-title-display-surfaces.test.ts
  • src/main/runtime/structured-agent-cli-writers.test.ts
  • src/main/runtime/terminal-list-pending-pty-registration.test.ts
  • src/main/runtime/terminal-list-surface-lost-orphan.spec.ts
  • src/main/runtime/terminal-pane-recovery-liveness-gate.test.ts
  • src/main/runtime/terminal-restore-record-seed.test.ts
  • src/main/runtime/terminal-retirement-proof-emitted-frame.test.ts
  • src/main/runtime/terminal-retirement-proof-publication.test.ts
  • src/main/runtime/terminal-wait-name-only-idle.test.ts
  • src/main/runtime/terminal/adoption/adopt-terminal-orphans-from-inventory.ts
  • src/main/runtime/terminal/adoption/unshown-live-terminal-placement.ts
  • src/main/runtime/terminal/focus/focus-terminal.ts
  • src/main/runtime/terminal/identity/adopted-pane-handle-race-main.test.ts
  • src/main/runtime/terminal/identity/main-pane-record-arrival.test.ts
  • src/main/runtime/terminal/identity/pty-worktree-record.ts
  • src/main/runtime/terminal/identity/terminal-handle-bindings.ts
  • src/main/runtime/terminal/launch/mobile-terminal-chat-fork.test.ts
  • src/main/runtime/terminal/launch/mobile-terminal-create.ts
  • src/main/runtime/terminal/launch/mobile-terminal-owned-create.ts
  • src/main/runtime/terminal/launch/terminal-create-pane-last-grid.test.ts
  • src/main/runtime/terminal/launch/terminal-split-layout-owner.test.ts
  • src/main/runtime/terminal/launch/terminal-split-surface.ts
  • src/main/runtime/terminal/lifecycle/bind-first-registration-census.test.ts
  • src/main/runtime/terminal/lifecycle/bind-first-registration.test.ts
  • src/main/runtime/terminal/lifecycle/bind-first-registration.ts
  • src/main/runtime/terminal/lifecycle/closed-pane-of-exited-pty.ts
  • src/main/runtime/terminal/lifecycle/exited-split-pane-rule.test.ts
  • src/main/runtime/terminal/lifecycle/exited-split-pane-rule.ts
  • src/main/runtime/terminal/lifecycle/main-pane-liveness.test.ts
  • src/main/runtime/terminal/lifecycle/pty-controller-inventory-refresh.ts
  • src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts
  • src/main/runtime/terminal/lifecycle/pty-registration.ts
  • src/main/runtime/terminal/lifecycle/ssh-exit-code-pane-outcome.test.ts
  • src/main/runtime/terminal/output/headless-terminal-hydration.ts
  • src/main/runtime/terminal/output/terminal-derived-agent-facts.ts
  • src/main/runtime/terminal/output/terminal-orchestration-authority.ts
  • src/main/runtime/terminal/output/terminal-transient-facts.ts
  • src/main/runtime/terminal/query/pty-terminal-summary.ts
  • src/main/runtime/terminal/recovery/replaced-pane-handle-recovery.test.ts
  • src/main/runtime/terminal/recovery/resolve-terminal-pane.ts
  • src/main/runtime/terminal/stop/worktree-sleep-resume-recording.ts
  • src/main/runtime/terminal/stop/worktree-terminal-stop-targets.ts
  • src/main/runtime/terminal/stop/worktree-terminal-stop.ts
  • src/main/runtime/terminal/surface/closed-pane-exit-cleanup-main.test.ts
  • src/main/runtime/terminal/surface/main-pane-verdict.ts
  • src/main/runtime/terminal/surface/main-terminal-surfaces.ts
  • src/main/runtime/terminal/surface/pty-pane-copies-untouched-main.test.ts
  • src/main/runtime/terminal/surface/pty-pane-copy-census.test.ts
  • src/main/runtime/terminal/surface/pty-pane-query.ts
  • src/main/runtime/terminal/surface/terminal-surface-index-spill.test.ts
  • src/main/runtime/terminal/surface/terminal-surface-index.ts
  • src/main/runtime/terminal/surface/terminal-surface-replies-main.test.ts
  • src/main/runtime/terminal/view/mobile-terminal-surface.ts
  • src/main/runtime/terminal/wait/terminal-wait-permission.ts
  • src/main/runtime/terminal/wait/terminal-wait.ts
  • src/main/runtime/tui-idle-delivery-and-quiescence.test.ts
  • src/main/runtime/tui-idle-wait-test-harness.ts
  • src/main/runtime/workspaces/known-workspace-file-target.ts
  • src/main/runtime/workspaces/persisted-surfaces/automation-operations.ts
  • src/main/runtime/workspaces/persisted-surfaces/has-exact-persisted-terminal-surface-identity.ts
  • src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.ts
  • src/main/runtime/workspaces/startup/workspace-terminal-provisioning.ts
  • src/main/runtime/workspaces/workspace-process-listing.ts
  • src/main/runtime/workspaces/workspace-removal-target.ts
  • src/main/runtime/worktree-agent-first-surface.test.ts
  • src/shared/__fixtures__/layout-owner-written-session.json
  • src/shared/closed-terminal-panes.ts
  • src/shared/closed-terminal-tab-tombstones.ts
  • src/shared/workspace-layout/workspace-layout-beside.ts
  • src/shared/workspace-layout/workspace-layout-command-types.ts
  • src/shared/workspace-layout/workspace-layout-commands.ts
  • src/shared/workspace-layout/workspace-layout-disk-fields.ts
  • src/shared/workspace-layout/workspace-layout-dropped-leaves.test.ts
  • src/shared/workspace-layout/workspace-layout-dropped-leaves.ts
  • src/shared/workspace-layout/workspace-layout-load.ts
  • src/shared/workspace-layout/workspace-layout-model.ts
  • src/shared/workspace-layout/workspace-layout-profile.test-fixture.ts
  • src/shared/workspace-layout/workspace-layout-save.ts
  • src/shared/workspace-session-host-field-ownership.ts
  • src/shared/workspace-session-schema-field-coverage.test.ts
  • src/shared/workspace-session-schema.ts
  • src/shared/workspace-session-state-types.ts
  • src/shared/wsl-move/wsl-move-dispositions.ts
💤 Files with no reviewable changes: 1
  • src/main/runtime/orca-runtime.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Comment on lines +61 to +65
const retired = retireTerminalSurfaceFromPersistence(current, surface)
const next =
retired !== current && closedPane?.paneKey === `${surface.parentTabId}:${surface.leafId}`
? forgetClosedPaneOfExit(retired, closedPane)
: retired

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
# Check whether retireTerminalSurfaceFromPersistence can return its input unchanged.
ast-grep run --pattern 'export function retireTerminalSurfaceFromPersistence($$$) { $$$ }' --lang typescript src
rg -nP -C3 'return\s+session\b|return\s+current\b' $(rg -l 'function retireTerminalSurfaceFromPersistence' src)

Repository: stablyai/orca

Length of output: 960


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- terminal-surface-retirements.ts ---'
nl -ba src/main/runtime/session-tabs/terminal-surface-retirements.ts | sed -n '1,240p'
printf '%s\n' '--- references ---'
rg -n -F --glob '*.ts' -e 'retireTerminalSurfaceFromPersistence' -e 'forgetClosedPaneOfExit' -e 'closedTerminalPanesByPaneKey' src/main
printf '%s\n' '--- relevant diff ---'
git diff --no-ext-diff --unified=30 3b02945afe35db12fe5a3b0c3c96c16983d81a4c 2b14a668ec2c27110ca3880617b5e62d82007d69 -- src/main/runtime/session-tabs src/main | sed -n '1,420p'

Repository: stablyai/orca

Length of output: 38516


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- persistence retirement ---'
nl -ba src/main/runtime/mobile-session-terminal-persistence-retirement.ts | sed -n '1,290p'
printf '%s\n' '--- closed-pane helper ---'
nl -ba src/main/runtime/terminal/lifecycle/closed-pane-of-exited-pty.ts | sed -n '1,100p'
printf '%s\n' '--- cleanup test ---'
nl -ba src/main/runtime/terminal/surface/closed-pane-exit-cleanup-main.test.ts | sed -n '1,220p'
printf '%s\n' '--- stage callers ---'
rg -n -C5 -F --glob '*.ts' -e 'stageTerminalSurfaceRetirements(' -e 'retireMobileSessionSurfacesForPty(' src/main/runtime src/main/terminal src/main/ipc

Repository: stablyai/orca

Length of output: 27181


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- exit lifecycle ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts | sed -n '210,325p'
printf '%s\n' '--- closed-pane writes and lookup ---'
rg -n -C6 -F --glob '*.ts' -e 'closedTerminalPanesByPaneKey =' -e 'closedTerminalPanesByPaneKey:' -e 'closedTerminalPaneOf(' -e 'ClosedPaneOfExit' src/main
printf '%s\n' '--- focused tests for unchanged retirement and reuse ---'
rg -n -C8 -F --glob '*.test.ts' -e 'returns the same' -e 'later incarnation' -e 'reused' -e 'pty mismatch' -e 'closed-pane' src/main/runtime src/main/persistence | sed -n '1,320p'

Repository: stablyai/orca

Length of output: 41246


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- closed-pane exit caller ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts | sed -n '35,75p'
printf '%s\n' '--- delayed-incarnation retirement test ---'
nl -ba src/main/runtime/orca-runtime-terminal-retirement.test.ts | sed -n '450,535p'

Repository: stablyai/orca

Length of output: 5622


Remove the closed-pane record independently of persistence retirement.

retireTerminalSurfaceFromPersistence can return current when the bound incarnation or layout PTY does not match. In that case, the current condition skips forgetClosedPaneOfExit, so a matching closed-pane record can remain persisted. forgetClosedPaneOfExit already checks the PTY and incarnation before deletion.

🐛 Suggested fix
--- "a/src/main/runtime/session-tabs/terminal-surface-retirements.ts"
+++ "b/src/main/runtime/session-tabs/terminal-surface-retirements.ts"
@@ -58,11 +58,11 @@
         kept.push(surface)
         continue
       }
       const retired = retireTerminalSurfaceFromPersistence(current, surface)
       const next =
-        retired !== current && closedPane?.paneKey === `${surface.parentTabId}:${surface.leafId}`
+        closedPane?.paneKey === `${surface.parentTabId}:${surface.leafId}`
           ? forgetClosedPaneOfExit(retired, closedPane)
           : retired
       if (next === current) {
         continue
       }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const retired = retireTerminalSurfaceFromPersistence(current, surface)
const next =
retired !== current && closedPane?.paneKey === `${surface.parentTabId}:${surface.leafId}`
? forgetClosedPaneOfExit(retired, closedPane)
: retired
const retired = retireTerminalSurfaceFromPersistence(current, surface)
const next =
closedPane?.paneKey === `${surface.parentTabId}:${surface.leafId}`
? forgetClosedPaneOfExit(retired, closedPane)
: retired

…ath, as every product path does; L283 stays it.fails for the main-owned reorder

openChat recorded the chat only in the runtime's snapshot, so main's layout never held it and the
phone's reorder was refused as an unknown tab. On the publish path main's layout holds it; the
reorder is accepted but does not survive the row rebuild after a close (L283, reopened).
… L288 pass, so their expected-failure marks go

- main-layout-session-tab-move.ts: both sides' methods and imports kept.
- mobile-session-tabs-headless-chat-rebuild.spec.ts: main's L283 test (its realistic store and
  publish path) as a plain test; this branch's publish-path openChat kept.
- mobile-session-tabs-part-03.spec.ts: the L288 placement cases are one plain it.each.

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81e61f98-66f3-47bb-8c39-ce58b8d710b0
📥 Commits

Reviewing files that changed from the base of the PR and between 2b14a66 and 53b44d7.

📒 Files selected for processing: 19
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/runtime/orca-runtime-layout-owner-start-fixture.ts
  • src/main/runtime/orca-runtime-test-fixtures.spec.ts
  • src/main/runtime/orca-runtime-test-lifecycle.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-headless-chat-rebuild.spec.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/session-lifecycle/projection/apply-mobile-session-tab-navigation.ts
  • src/main/runtime/session-lifecycle/projection/perform-mobile-session-pty-records-refresh.ts
  • src/main/runtime/session-tabs/headless-terminal-tab-close.ts
  • src/main/runtime/session-tabs/main-layout-session-tab-move.ts
  • src/main/runtime/terminal/launch/mobile-terminal-chat-fork.test.ts
  • src/main/runtime/terminal/launch/mobile-terminal-owned-create.ts
  • src/main/runtime/terminal/lifecycle/bind-first-registration.test.ts
  • src/main/runtime/terminal/output/terminal-orchestration-authority.ts
  • src/main/runtime/terminal/query/pty-terminal-summary.ts
  • src/main/runtime/terminal/surface/main-terminal-surfaces.ts
  • src/main/runtime/terminal/surface/terminal-surface-index.ts
  • src/shared/workspace-layout/workspace-layout-command-types.ts
💤 Files with no reviewable changes: 1
  • src/main/runtime/orca-runtime.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment on lines +291 to +292
const panePtyIds = [...this.ptysById.values()].flatMap((pty) =>
this.paneOfPty(pty).paneKey === paneKey ? [pty.ptyId] : []

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '185,255p' src/main/runtime/session-lifecycle/projection/apply-mobile-session-tab-navigation.ts
sed -n '275,305p' src/main/runtime/session-lifecycle/projection/perform-mobile-session-pty-records-refresh.ts
rg -n 'closedTerminalPanesByPaneKey|isProviderSessionLiveInAnotherPane|resolveMobileSessionResumeCommand' src/main/runtime/session-lifecycle src/main/runtime/terminal src/shared/workspace-layout

Repository: stablyai/orca

Length of output: 8170


🏁 Script executed:

set -o pipefail
rg -n -F --glob '*.ts' \
  -e 'getAgentProviderSessionSnapshotFn' \
  -e 'getAgentProviderSessionRowsForPaneFn' \
  -e 'paneHoldsSession(' \
  -e 'closedTerminalPanesByPaneKey' \
  -e 'closedTerminalPaneOf' \
  -e 'onPtyExit' \
  src/main/runtime src/shared/workspace-layout
printf '\n--- session holder helper ---\n'
rg -n -F --glob '*.ts' -e 'function paneHoldsSession' -e 'const paneHoldsSession' src/main
printf '\n--- relevant helper and lifecycle blocks ---\n'
sed -n '1,150p' src/main/runtime/terminal/lifecycle/closed-pane-of-exited-pty.ts
sed -n '330,410p' src/main/runtime/terminal/surface/main-terminal-surfaces.ts
sed -n '1,150p' src/shared/workspace-layout/workspace-layout-dropped-leaves.ts
sed -n '1,130p' src/shared/workspace-layout/workspace-layout-model.ts

Repository: stablyai/orca

Length of output: 42156


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- snapshot and row bindings ---'
rg -n -F --glob '*.ts' \
  -e 'getAgentProviderSessionSnapshot' \
  -e 'getAgentProviderSessionRowsForPane' \
  -e 'AgentProviderSessionRow' \
  -e 'providerSession' \
  src/main/runtime/agent-status src/main/runtime/session-lifecycle src/main/runtime/terminal src/main/runtime/construction src/shared \
  | head -n 500
printf '%s\n' '--- host-service declarations and construction ---'
sed -n '95,160p' src/main/runtime/construction/runtime-host-services.ts
sed -n '190,225p' src/main/runtime/construction/runtime-construction.ts
printf '%s\n' '--- exact onPtyExit lifecycle ---'
sed -n '1,150p' src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts
printf '%s\n' '--- closed-pane type and record helper ---'
sed -n '1,180p' src/shared/closed-terminal-panes.ts

Repository: stablyai/orca

Length of output: 42302


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- concrete callback bindings ---'
rg -n -F --glob '*.ts' \
  -e 'getAgentProviderSessionSnapshot:' \
  -e 'getAgentProviderSessionRowsForPane:' \
  -e 'getAgentStatusSnapshot:' \
  -e 'getAgentStatusSnapshotForPane:' \
  -e 'reconcileAgentStatusForEndedProcess:' \
  -e 'dropAgentStatusForRemovedWorktree:' \
  -e 'reconcileAgentStatusForEndedProcess' \
  -e 'getAgentProviderSessionSnapshot' \
  src
printf '%s\n' '--- status store and row lifecycle declarations ---'
rg -n -F --glob '*.ts' \
  -e 'class AgentStatus' \
  -e 'AgentStatusStore' \
  -e 'snapshot()' \
  -e 'removePane' \
  -e 'remove.*pane' \
  -e 'drop.*pane' \
  -e 'ended process' \
  src/shared src/main

Repository: stablyai/orca

Length of output: 41248


🏁 Script executed:

set -o pipefail
sed -n '1,80p' src/main/agent-hooks/agent-hook-runtime-deps.ts
rg -n -F --glob '*.ts' \
  -e 'getStatusSnapshot()' \
  -e 'getStatusSnapshotForPane' \
  -e 'reconcileAgentStatusForEndedProcess' \
  -e 'class AgentHookServer' \
  -e 'class AgentStatusServer' \
  src/main src/shared
printf '%s\n' '--- server declarations and reconciliation blocks ---'
rg -n -F --glob '*.ts' -e 'export class AgentHookServer' -e 'class AgentHookServer' src

Repository: stablyai/orca

Length of output: 41610


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- snapshot methods ---'
sed -n '205,255p' src/main/agent-hooks/server/server-listeners.ts
printf '%s\n' '--- exact reconciliation references ---'
rg -n -F --glob '*.ts' \
  -e 'reconcileEndedProcessForPaneKeys' \
  -e 'reconcileEndedProcess' \
  -e 'forgetAgentExit' \
  -e 'checkAgentPresenceSince' \
  src/main/agent-hooks
printf '%s\n' '--- candidate implementation blocks ---'
rg -n -F --glob '*.ts' \
  -e 'reconcileEndedProcessForPaneKeys(' \
  -e 'function reconcileEndedProcessForPaneKeys' \
  -e 'private reconcileEndedProcessForPaneKeys' \
  -e 'protected reconcileEndedProcessForPaneKeys' \
  src/main

Repository: stablyai/orca

Length of output: 12643


🏁 Script executed:

set -o pipefail
sed -n '100,175p' src/main/agent-hooks/server/server-cleanup.ts
sed -n '285,325p' src/main/agent-hooks/server/server-state.ts
rg -n -F --glob '*.ts' \
  -e 'combinedStatusEntries' \
  -e 'preserveResumeIdentity' \
  -e 'delete.*status' \
  -e 'remove.*status' \
  src/main/agent-hooks/server src/main/agent-hooks/ended-process-reconciliation.test.ts
sed -n '55,175p' src/main/agent-hooks/ended-process-reconciliation.test.ts

Repository: stablyai/orca

Length of output: 10549


Include the dropped pane’s closed PTY in paneHoldsSession.

A main-owned live-edit drop records the pane in closedTerminalPanesByPaneKey, but it does not reconcile the provider-session row. The row can therefore remain until PTY-exit reconciliation. During that interval, paneOfPty(pty) omits the dropped pane’s PTY, so paneHoldsSession returns false. isProviderSessionLiveInAnotherPane then skips the hook-presence check, and navigation can call resolveMobileSessionResumeCommand for the same provider session while its original PTY is still running.

Include the matching closed-pane PTY binding when collecting panePtyIds. Keep the existing PTY exit checks and closed-record TTL/cleanup behavior.

…31596); the unbound-registration test keeps its spawn from the suites' stand-in commit

After the main merge both start lanes register in spawn-commit-assembly.ts, after
savePtySpawnPaneBinding (or, adopted, on the live owner's pane); the census lists that file. A
phone create now writes its pane before the spawn, so the suites' stand-in spawn commit bound it
and the test of a path that registers unbound passed for the wrong reason; that test's controller
now opts out of the stand-in commit.
Real switch-on runs showed four files whose fakes registered terminals unbound
or confirmed a stop without its exit. Bind first, stamp the source as main
does, and deliver the exit a confirmed stop delivers. Switch-off unchanged.

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

🔇 Additional comments: 10
src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts: 1

315-336: LGTM!

src/main/runtime/orca-runtime-terminal-split-authority.test.ts: 1

20-27: LGTM!

src/main/runtime/orca-runtime-tests/mobile-session-tabs-headless-chat-rebuild.spec.ts: 1

125-126: LGTM!

Also applies to: 228-245

src/main/runtime/session-tabs/main-layout-session-tab-move.ts: 1

26-36: LGTM!

src/main/runtime/terminal-intentional-stop-exit.test.ts: 1

260-274: LGTM!

src/main/runtime/terminal/lifecycle/bind-first-registration.test.ts: 1

1-128: LGTM!

src/main/runtime/bind-first-pane.test-fixture.ts: 1

1-335: LGTM!

src/main/runtime/graph-sync-live-daemon-pty-tab-preservation.test.ts: 1

135-162: LGTM!

src/main/runtime/orca-runtime-codex-idle-title-chat-address.test.ts: 1

57-68: LGTM!

Also applies to: 81-82

src/main/runtime/terminal/lifecycle/bind-first-registration-census.test.ts: 1

74-75: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Skip the TypeScript parse for files that cannot contain a registration call.

registrations runs ts.createSourceFile on every production .ts file under src/main. The unlisted filter at Line 118 calls it for each file that is not in CREATE_PATHS. This parses the whole src/main tree in one test. The test uses the default Vitest timeout, so it can time out on slow CI machines.

Add a cheap text pre-check before parsing. The AST walk then runs only for the few files that mention a registration call.

♻️ Proposed pre-check
   const text = readFileSync(path.join(ROOT, file), 'utf8')
+  if (!text.includes('registerPty') && !text.includes('registerPersistedPtySpawn')) {
+    return []
+  }
   const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true)

ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b84d91b3-50aa-4a14-9889-b8941b7453c1
📥 Commits

Reviewing files that changed from the base of the PR and between 53b44d7 and 3764776.

📒 Files selected for processing: 10
  • src/main/runtime/bind-first-pane.test-fixture.ts
  • src/main/runtime/graph-sync-live-daemon-pty-tab-preservation.test.ts
  • src/main/runtime/orca-runtime-codex-idle-title-chat-address.test.ts
  • src/main/runtime/orca-runtime-terminal-split-authority.test.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-headless-chat-rebuild.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts
  • src/main/runtime/session-tabs/main-layout-session-tab-move.ts
  • src/main/runtime/terminal-intentional-stop-exit.test.ts
  • src/main/runtime/terminal/lifecycle/bind-first-registration-census.test.ts
  • src/main/runtime/terminal/lifecycle/bind-first-registration.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

The PTY controller fake now takes the controller's optional pane fields, and the
switch-on store is a typed RuntimeStore, so neither needs an assertion.
@Jinwoo-H
Jinwoo-H merged commit 7cabd3a into main Oct 22, 2026
60 checks passed
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