Skip to content

Layout-owner build: main answers terminal questions from its own layout (A1, dark) - #31187

Merged
Jinwoo-H merged 63 commits into
mainfrom
fd/a1-main-terminal-surfaces-v2
Oct 20, 2026
Merged

Jinwoo-H merged 63 commits into
mainfrom
fd/a1-main-terminal-surfaces-v2

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​937 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​904
Prod 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1278 $\color{#cf222e}{\Huge{\mathbf{−}}}$​250 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1028

ELI5

In the new layout build (still switched off in every shipped build), Orca's main process holds the one copy of every workspace's tabs and panes. Until now it still answered questions about terminals ("which terminals exist?", "close this one") from a list the window sent it. This PR makes main answer from its own copy, so the answers are right even when no window is open or when the window has not drawn a pane yet.

What Changed

All behaviour changes are behind the ORCA_LAYOUT_OWNER build switch, which is off in shipped builds. With the switch off, every reply is byte-identical (see Testing).

With the switch on, for workspaces main owns (local and SSH; paired-server runtime: workspaces are still mirrored from the window as before):

  • Terminal list, handles, show, wait, focus, stop, split and rename answer from main's own panes and its record of which terminal each pane holds, instead of the window's list. The window now sends only what it has on screen for those workspaces (mountedLeaves: which panes are mounted, their on-screen id and title).
  • Close by handle (terminal close / close tab from the CLI or a phone) closes the pane in main's layout, records the close and stops the terminals it ends. Before, main asked the window to re-list panes at close time; that relist (layout-owner-close-relisting.ts and its branch in resolvePtyTabCloseSurfaceAuthority) is deleted.
  • A terminal's recorded pane: when a caller names a tab or pane for a terminal and main's layout binds that terminal elsewhere, main's binding wins (ledger L80, first step).
  • After the window closes, main keeps answering for the workspaces it owns (the graph stays ready under main's own authority) and starts terminals itself; before, terminal questions failed as "runtime unavailable" until a window came back. A worktree stop also names every terminal main's layout binds, registered or not, so a saved SSH terminal that has not re-registered since a restart is stopped rather than left behind. Stops fenced to one SSH connection still skip such an unregistered id, exactly as the window-owned build does.
  • User-visible: terminal.list lists every saved pane of a workspace main owns, including a pane whose terminal has not started, even when the workspace has other live terminals. Before, such a pane was hidden while its workspace had a live terminal.
  • New optional verdict field on each terminal.list row (live / unverifiable / exited, the existing liveness words). connected keeps its old meaning for older readers. A pane with a status (a start in flight or failed, or a sleeping agent) is reported connected: false and is never live. exited needs the host's own answer (its inventory, or an exit the host reported); losing contact is unverifiable. Orca's worker observation now reads verdict instead of treating connected: false as exited. CLI text output is unchanged.
  • Dragging a pane out to a new tab (L127): main moves the terminal its own layout binds; the window's claim about which terminal is in the pane is no longer consulted. Main refuses to move the last pane of the workspace's home copy of a tab. One allowance stays on purpose: legacy SSH relay data can hold the same tab in both the local and the SSH partition, and the stray copy there may have only the moved pane, so the stray copy may still move its last pane along with the home copy (test: "a window drag-out of an SSH pane held by both partitions").

Why

Main is now the only writer of the layout (D1a), but it still trusted the window's view of terminals. That view lags (a pane split by the CLI before any window draws it, a window that closed, a respawn), which is why the close-time relist and the window's terminal override existed. Answering from main's own copy removes those patches instead of adding more. Alternatives considered: keeping the window's list and widening the relist (more round trips, still wrong with no window), or a second index of panes kept in main (a second copy that can drift); this PR reads the one projection main already publishes (E1's readPartition and onLayoutOperationCommitted).

Not in this PR (by plan): the full deletion of the terminal record's tab/pane copies and their freshness stamp (L80) and main-side adoption of live terminals (L113) are A1b, stacked on this PR. L31 and L58 are untouched (annotated in the ledger).

Linked Issue

Part of the terminal layout final design (A1). No separate issue.

Visual Proof

N/A: no UI change in shipped builds (the switch is off); with the switch on the window draws the same panes. Behaviour is proven by the reply tests below.

Testing

  • Reply shapes: terminal-surface-replies-window.test.ts records the CLI / paired-desktop / orcad replies (list, show, status) from today's window-owned build; terminal-surface-replies-main.test.ts proves the switch-on build gives the same bytes (with the new optional verdict ignored, and asserted separately).

  • Switch-on proofs: listing saved panes with no window and after the window closes; a split made before any window shows it; close tab / close one pane by handle with no session row from the window; close a tab by a starting pane's handle stops the tab's other terminals; a stale pane claim is overridden; every pane status (starting, failed, sleeping) never lists live; a remote host's exited / unverifiable / live answers pass through; the drag-out cases above.

  • Converted (not dropped) switch-on tests: sync-runtime-graph-parked-leaf, sync-runtime-graph-automation-leaf, close-by-split-handle-layout-owner, the cold-restore membership table (runs in both builds), and the two drag-out tests in terminal-window-pane-detach.test.ts.

  • Pure move: stopExplicitlyClosedTabPtys moved unchanged to explicit-terminal-close-pty-stops.ts (its own commit) to keep explicit-terminal-close-stops.ts under the line cap.

  • Pure move: a worktree stop's terminal collection moved unchanged to terminal/stop/worktree-pty-collection.ts (its own commit) to keep worktree-terminal-stop.ts under the line cap; the switch-on call sites then add main's bound terminals.

  • Gates: ci-static-gate (every static step of pr.yml) passes. Switch-off: the related unit set (603 files) passes except two folder-import tests in orca-runtime.test.ts that fail the same way on the D1a base. Switch-on src/main/runtime + src/main/persistence in clean worktrees, D1a head 6b8c37f vs this head: 25 failing tests at both, the same 25; no test fails only at this head. Tests converted for this: window-authority.spec.ts (main keeps answering after the window closes), mobile-session-tabs-part-03.spec.ts (a create after the window closes starts in main and sends nothing to the closed window), mobile-session-tabs-part-06.spec.ts (session reads stay per sync, not per workspace), orca-runtime-terminal-retirement-host-partition.spec.ts (the right pane's terminal registers as the window's attach registers it).

  • Latency (oracle latency spec, 40 samples x 3 runs per build, hidden windows, in-app drawn p95, switch on minus off): split +2/+0/+3 ms, rename +4/+5/+2 ms, new tab -30/-70/-42 ms (idle/output flood/title flood). Rename under output flood is AT THE LIMIT (+5 ms); it is re-measured at A2. Against D1a's own on-vs-off runs, A1 adds no measurable cost; close pane p95 is noisy in both builds (off 76-132 ms).

  • Switch-off bundle (unminified main and renderer, D1a head vs this head): the renderer is identical apart from chunk hashes. Main differs only by code the switch-off build does not reach or that gives the same result:

    • modules only switch-on code calls are bundled (terminal/surface/*, pane-start-statuses bindingOf, the projectRuntimeSurfaces split); the only code they run at load is one WeakMap construction;
    • withMainSurfaces exists on the runtime class but is only called behind the switch;
    • graph = graph (the folded switch point in syncWindowGraph) and && true in the terminal list skip (folded switch);
    • the drag-out holders carry hostId and pane count, and look up the home holder; the switch-off choice of terminal and refusals are unchanged;
    • the pure method move above adds one class to the runtime's chain; the method body is byte-identical.
    • the worktree stop collection is now a module function with the same body; with the switch off its callers pass the same leaves and records as before.
  • Platforms: macOS locally (unit, e2e latency with hidden windows). SSH covered by unit tests of the two-partition and remote-verdict cases.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

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: the new verdict field is optional and emitted only with the switch on; old CLIs, paired desktops and orcad ignore it. mountedLeaves travels window to main only.
  • SSH: remote terminals are never declared exited from this machine's inventory; the remote host's own answer passes through.
  • Folder workspaces: handled like worktrees (keyed by workspace id).

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)

E2E Test added 30 commits October 20, 2026 10:17
… starts them, window or none (dark; twin e)
… starts them, window or none (dark; twin e)
…nt fails to start; no window takes over (dark)
…ne; a terminal close stands after a failed write (dark)
…abs start once; a tab's last pane keeps its card (dark)
E2E Test and others added 15 commits October 20, 2026 11:46
…g live; remote host answers pass through (dark)
…e copy's last pane; the window's terminal claim is not consulted (L127, dark)
…terminals; a starting pane is never exited on the inventory alone; terminal.list lists every saved pane main owns; the pane claim lookup leaves the output path (dark)
…ayout switch on

An exited pane closes through the legacy retirement unless the keep rule holds; the
default tab's title and color still reach the window and the phone's live tabs.
…vouched -1

Main's taken and closed-id guard now runs where every pane write goes, so a runtime create
replayed after its tab closed is refused before it spawns. An exit code nothing vouches for
keeps the pane, as the window does; a kept pane sends the phone no retirement. Converts the
switch-on tests that asserted the deleted window hand-off and title bridge.
… checks on client commands

A paired host starts each pane of a client's tab as a create under the tab's id, so a held tab
id is refused only for a client's own layout command.
Only a requested stop or a host-confirmed death closes a pane on a negative exit code. Pins that
the closed-tab guard never fires in the shipped build.
…itions hold, the fence reads ownership once, a legacy pane keeps its claim; switch-on tests assert main's answers after a window closes (dark)
…ged to its own module, for the file's line cap
… does, re-reading routing only on a write or a terminal registration; a worktree stop names every terminal main binds; a starting pane is unverifiable (dark)
@Jinwoo-H
Jinwoo-H changed the base branch from fd/d1-terminal-main-first to main October 20, 2026 19:11
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9aa0a52f-20d3-4fbf-b446-a1e06acfce42
📥 Commits

Reviewing files that changed from the base of the PR and between 014b248 and 397e02f.

📒 Files selected for processing: 2
  • src/main/runtime/terminal/surface/main-terminal-surfaces.ts
  • src/main/runtime/terminal/surface/terminal-surface-verdict-main.test.ts

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

📝 Walkthrough

The changes add main-owned workspace layout projection and publish mounted and parked panes through runtime and renderer graphs. Terminal summaries and worker observations now use pane liveness verdicts. Main-owned close operations apply layout commands and stop affected PTYs. Worktree stopping and pane detachment use shared collection and layout-aware checks. Tests cover graph publication, terminal replies, pane verdicts, close behavior, and layout-owner configurations.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 397e0

An ambiguous workspace owner can receive inconsistent split-pane close handling. This is a bounded risk behind a build switch that is off in shipped builds; confirm pane removal before enabling it.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 55.93% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 59 functions across 52 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 primary change: main answers terminal questions from its own layout in the layout-owner build.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, testing, compatibility, performance, and checklist items. It does not provide the required linked issue and leaves th…
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 and covers the user impact, implementation, rationale, testing, compatibility, performance, and checklist items. It does not provide the required linked issue and leaves the small-and-focused checklist item unchecked, but these omissions do not make the description largely incomplete.

✨ 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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 100e303d-91ba-4686-ab0f-ca665007eea4
📥 Commits

Reviewing files that changed from the base of the PR and between 997d34b and 75fa7fa.

📒 Files selected for processing: 114
  • config/scripts/check-id-only-store-write-ratchet.mjs
  • config/scripts/check-id-only-store-write-ratchet.test.mjs
  • src/main/ipc/pty/provider/bind-listeners.ts
  • src/main/ipc/pty/provider/local-configure.ts
  • src/main/persistence/loading-store/store-domain-composition.ts
  • src/main/persistence/loading-store/terminal-close-async-durability.test.ts
  • src/main/persistence/terminal-topology/layout-command-persistence.ts
  • src/main/persistence/terminal-topology/terminal-close-write-failure-store.test.ts
  • src/main/persistence/terminal-topology/terminal-close-write-failure-switch-off.test.ts
  • src/main/persistence/terminal-topology/terminal-close-write-failure.test.ts
  • src/main/persistence/terminal-topology/terminal-close-write-failure.ts
  • src/main/persistence/terminal-topology/terminal-layout-create-resend.test.ts
  • src/main/persistence/terminal-topology/terminal-layout-create.test.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission-taken-ids-switch-off.test.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission-taken-ids.test.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/persistence/terminal-topology/terminal-window-pane-detach.test.ts
  • src/main/persistence/terminal-topology/window-pane-detach.ts
  • src/main/runtime/construction/runtime-service-state.ts
  • src/main/runtime/exited-split-pane-layout-close.test.ts
  • src/main/runtime/exited-split-pane-layout-close.ts
  • src/main/runtime/orca-runtime-cold-restore-terminal-membership-layout-owner.test.ts
  • src/main/runtime/orca-runtime-create-terminal-dependencies.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-layout-owner-start-fixture.ts
  • src/main/runtime/orca-runtime-terminal-create-replay-after-close.test.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-06.spec.ts
  • src/main/runtime/orca-runtime-tests/window-authority.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-03.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-04.spec.ts
  • src/main/runtime/orca-runtime-tests/worktree-setup-single-creator.spec.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration/terminal-authority/write-orchestration-pointer-pty.ts
  • src/main/runtime/pane-start-statuses.test.ts
  • src/main/runtime/pane-start-statuses.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-observation-layout-owner.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-observation.ts
  • src/main/runtime/runtime-folder-worktree-create-layout-owner.test.ts
  • src/main/runtime/runtime-folder-worktree-create.ts
  • src/main/runtime/runtime-layout-apply.test.ts
  • src/main/runtime/runtime-layout-apply.ts
  • src/main/runtime/runtime-leaf-record-projection.ts
  • src/main/runtime/runtime-local-worktree-terminal-startup-layout-owner.test.ts
  • src/main/runtime/runtime-local-worktree-terminal-startup.test.ts
  • src/main/runtime/runtime-local-worktree-terminal-startup.ts
  • src/main/runtime/runtime-pane-admission.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/runtime-terminal-list.ts
  • src/main/runtime/runtime-worktree-default-tabs-layout-owner.test.ts
  • src/main/runtime/runtime-worktree-terminal-provisioning.ts
  • src/main/runtime/session-graph/session-graph-authority.ts
  • src/main/runtime/session-graph/session-graph-reload-lifecycle.ts
  • src/main/runtime/session-graph/session-window-graph.ts
  • src/main/runtime/session-lifecycle/close/close-by-split-handle-layout-owner.test.ts
  • src/main/runtime/session-tabs/explicit-terminal-close-pty-stops.ts
  • src/main/runtime/session-tabs/explicit-terminal-close-stops.ts
  • src/main/runtime/session-tabs/main-handle-close.ts
  • src/main/runtime/session-tabs/mobile-session-membership.ts
  • src/main/runtime/session-tabs/session-tabs-inventory.ts
  • src/main/runtime/session-tabs/terminal-surface-retirements.ts
  • src/main/runtime/terminal-intentional-stop-exit.test.ts
  • src/main/runtime/terminal/identity/pty-worktree-record.ts
  • src/main/runtime/terminal/launch/failed-start-pane.ts
  • src/main/runtime/terminal/launch/mobile-terminal-create.ts
  • src/main/runtime/terminal/launch/terminal-create.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/pty-exit-lifecycle.ts
  • src/main/runtime/terminal/lifecycle/pty-registration.ts
  • src/main/runtime/terminal/stop/worktree-pty-collection.ts
  • src/main/runtime/terminal/stop/worktree-terminal-stop.ts
  • src/main/runtime/terminal/surface/__fixtures__/terminal-surface-replies-desktop.json
  • src/main/runtime/terminal/surface/__fixtures__/terminal-surface-replies-headless.json
  • src/main/runtime/terminal/surface/main-pane-verdict.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/terminal-surface-index.ts
  • src/main/runtime/terminal/surface/terminal-surface-replies-main.test.ts
  • src/main/runtime/terminal/surface/terminal-surface-replies-window.test.ts
  • src/main/runtime/terminal/surface/terminal-surface-replies.test-fixture.ts
  • src/main/runtime/terminal/surface/terminal-surface-verdict-main.test.ts
  • src/main/runtime/terminal/view/layout-owner-close-relisting.ts
  • src/main/runtime/terminal/view/mobile-terminal-surface.ts
  • src/main/runtime/workspace-layout-stream.ts
  • src/main/runtime/workspaces/startup/workspace-terminal-provisioning.ts
  • src/renderer/src/components/terminal-pane/layout-owner-pane-close-command.ts
  • src/renderer/src/components/terminal-pane/pending-pane-close-confirmation.test.ts
  • src/renderer/src/components/terminal-pane/pending-split-close-test-fixture.ts
  • src/renderer/src/components/terminal-pane/pending-split-close.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/exited-split-pane-close.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/exited-split-pane-close.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/runtime/layout-apply-send.ts
  • src/renderer/src/runtime/sync-runtime-graph-automation-leaf.test.ts
  • src/renderer/src/runtime/sync-runtime-graph-main-listed-panes.test.ts
  • src/renderer/src/runtime/sync-runtime-graph-parked-leaf.test.ts
  • src/renderer/src/runtime/sync-runtime-graph/graph-publication.ts
  • src/renderer/src/runtime/sync-runtime-graph/main-owned-terminal-list.ts
  • src/renderer/src/store/terminals/terminal-tab-close-intent.test.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/rpc-contract/workspace-layout-terminal-tab-params.ts
  • src/shared/runtime-session-contracts.ts
  • src/shared/runtime-terminal-contracts.ts
  • src/shared/runtime-types.ts
  • src/shared/workspace-layout/workspace-layout-command-types.ts
  • src/shared/workspace-layout/workspace-layout-commands.ts
  • src/shared/workspace-layout/workspace-layout-default-tabs.test.ts
  • src/shared/workspace-layout/workspace-layout-default-tabs.ts
  • src/shared/workspace-layout/workspace-layout-published.ts
  • src/shared/workspace-layout/workspace-layout-records.ts
💤 Files with no reviewable changes: 3
  • src/main/runtime/runtime-layout-apply.test.ts
  • src/main/runtime/terminal/view/layout-owner-close-relisting.ts
  • src/main/runtime/terminal/view/mobile-terminal-surface.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 +15 to +18
if (
!pane.leafId ||
runtimeEnvironmentIdUnlessTwin(useAppStore.getState(), pane.worktreeId) !== null
) {

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:

rg -n 'export function runtimeEnvironmentIdUnlessTwin' -A 30 src/renderer
sed -n '1,70p' src/renderer/src/runtime/sync-runtime-graph/main-owned-terminal-list.ts
sed -n '1,30p' src/renderer/src/components/terminal-pane/pty-connection/exited-split-pane-close.ts
sed -n '340,380p' src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts

Repository: stablyai/orca

Length of output: 7530


🏁 Script executed:

set -e
printf '%s\n' '--- retirement logic ---'
rg -n -F --glob '*.ts' -e 'terminal-surface-retirements' -e 'runtime:' -e 'mainListsWorkspaceTerminals' -e 'expectExitedSplitPaneClose' src/renderer/src src/main 2>/dev/null || true
printf '%s\n' '--- retirement file candidates ---'
rg --files | rg 'terminal-surface-retirements|pty-exit-hibernate|resolve-owner|runtime.*graph|terminal-surface'
printf '%s\n' '--- owner resolution declarations and state fields ---'
rg -n -F --glob '*.ts' -e 'runtimeEnvironmentIdForWorkspaceOwner' -e 'kind: .resolved' -e 'kind: .unresolved' -e 'ownerHydrat' -e 'hydrated' src/renderer/src | head -240
printf '%s\n' '--- relevant tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'expectExitedSplitPaneClose' -e 'unclear owner' -e 'unresolved' -e 'runtime:' -e 'PTY exit' src/renderer/src | head -300

Repository: stablyai/orca

Length of output: 45667


🏁 Script executed:

set -e
printf '%s\n' '--- exact files ---'
find src -type f \( -name '*terminal-surface-retirements*' -o -name '*pty-exit-hibernate*' \) -print
printf '%s\n' '--- retirement references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -- 'terminal-surface-retirements' src || true
rg -n -F --glob '*.ts' --glob '*.tsx' -- 'partition' src/renderer/src/runtime src/renderer/src/main 2>/dev/null | rg 'terminal|retire|surface|runtime:' | head -100 || true
printf '%s\n' '--- owner resolver and unresolved-state tests ---'
rg -n -F --glob '*.ts' -- 'function runtimeEnvironmentIdForWorkspaceOwner' src/renderer/src/lib/resolve-owner.ts
rg -n -F --glob '*.{ts,tsx}' -e 'owner.kind === .unresolved.' -e 'kind: .unresolved.' -e 'runtimeEnvironmentIdUnlessTwin' -e 'owner hydration' -e 'hydration' src/renderer/src/lib src/renderer/src/runtime src/renderer/src/components/terminal-pane | head -220
printf '%s\n' '--- exit-close tests and lifecycle callers ---'
rg -n -F --glob '*.{ts,tsx}' -e 'expectExitedSplitPaneClose' -e 'onPtyExitRef' -e 'pty-exit-hibernate' src/renderer/src | head -180

Repository: stablyai/orca

Length of output: 38982


🏁 Script executed:

set -e
printf '%s\n' '--- main retirement implementation ---'
nl -ba src/main/runtime/session-tabs/terminal-surface-retirements.ts | sed -n '1,260p'
printf '%s\n' '--- owner resolver ---'
nl -ba src/renderer/src/lib/resolve-owner.ts | sed -n '150,235p'
printf '%s\n' '--- owner-resolution tests around unresolved/pre-hydration cases ---'
nl -ba src/renderer/src/lib/workspace-terminal-host-authority.test.ts | sed -n '260,335p'
nl -ba src/renderer/src/lib/resolve-owner.test.ts | sed -n '350,390p'
printf '%s\n' '--- exit helper tests ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/exited-split-pane-close.test.ts | sed -n '1,120p'
printf '%s\n' '--- PTY exit control flow ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts | sed -n '300,380p'

Repository: stablyai/orca

Length of output: 24874


🏁 Script executed:

set -e
printf '%s\n' '--- owner resolution and ambiguity construction ---'
nl -ba src/renderer/src/lib/resolve-owner.ts | sed -n '1,155p'
rg -n -F --glob '*.ts' --glob '*.tsx' -e "kind: 'ambiguous'" -e "owner.kind === 'ambiguous'" -e 'resolveOwner(' src/renderer/src/lib/resolve-owner.ts src/renderer/src/lib/*test.ts | head -160
printf '%s\n' '--- exit rule ---'
nl -ba src/main/runtime/exited-split-pane-layout-close.ts | sed -n '1,220p'
nl -ba src/main/runtime/terminal/lifecycle/exited-split-pane-rule.ts | sed -n '1,220p'
printf '%s\n' '--- retirement caller and frame publication ---'
rg -n -F --glob '*.ts' -e 'retireMobileSessionSurfacesForPty' -e 'stageTerminalSurfaceRetirements' -e 'keepsExitedPane' src/main | head -160

Repository: stablyai/orca

Length of output: 16604


🏁 Script executed:

set -e
printf '%s\n' '--- PTY ownership acceptance ---'
nl -ba src/renderer/src/lib/terminal-pty-owner-acceptance.ts | sed -n '1,220p'
nl -ba src/renderer/src/lib/terminal-pty-owner-acceptance.test.ts | sed -n '1,125p'
printf '%s\n' '--- PTY bind/exit ownership callers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'resolveTerminalPtyOwner' -e 'terminalPtyOwner' -e 'ownerAcceptance' -e 'isTwinWorkspace' src/renderer/src/components/terminal-pane src/renderer/src/lib | head -180
printf '%s\n' '--- main PTY exit lifecycle around retirement ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts | sed -n '220,290p'

Repository: stablyai/orca

Length of output: 12996


🏁 Script executed:

set -e
printf '%s\n' '--- terminal owner resolver and route guards ---'
nl -ba src/renderer/src/lib/terminal-worktree-route.ts | sed -n '120,190p'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'resolveTerminalPtyOwner(' -e 'resolveTerminalHostOwnership(' -e 'owner changes' -e 'ownership changes' -e 'ambiguous.*exit' -e 'exit.*ambiguous' -e 'twin.*pty' -e 'pty.*twin' src/renderer/src | head -220
printf '%s\n' '--- workspace owner state transitions relevant to hydration ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'runtimeEnvironmentCatalogHydrated' -e 'worktreesByRepo' -e 'folderWorkspaces' src/renderer/src/store src/renderer/src/lib | head -220
printf '%s\n' '--- PTY connect path ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'connectPanePty' -e 'runtimeEnvironmentId' src/renderer/src/components/terminal-pane/pty-connection | head -160

Repository: stablyai/orca

Length of output: 41846


🏁 Script executed:

set -e
printf '%s\n' '--- teardown behavior for owner changes ---'
nl -ba src/renderer/src/lib/terminal-worktree-route.test.ts | sed -n '70,115p'
nl -ba src/renderer/src/components/dashboard/dashboard-card-terminal-input.test.ts | sed -n '170,215p'
printf '%s\n' '--- terminal retirement ownership decisions ---'
nl -ba src/renderer/src/store/slices/terminal-tab-retirement.ts | sed -n '45,90p'
nl -ba src/renderer/src/store/slices/terminal-tab-retirement.ts | sed -n '195,235p'
printf '%s\n' '--- close admission ownership transition tests ---'
nl -ba src/renderer/src/components/terminal-pane/terminal-pane-close-admission.ts | sed -n '1,85p'
rg -n -F --glob '*.test.ts' --glob '*.test.tsx' -e 'live.*owner changes' -e 'owner changes.*live' -e 'twin' src/renderer/src/components/terminal-pane src/renderer/src/store | head -100

Repository: stablyai/orca

Length of output: 26524


Use the graph publication ownership rule for exit handling.

runtimeEnvironmentIdUnlessTwin returns null for an ambiguous owner, but mainListsWorkspaceTerminals returns false. The exit helper therefore records an 'exit' intent and skips the renderer close when ownership is ambiguous.

Use mainListsWorkspaceTerminals for this check. This keeps ambiguous ownership with the window, as the graph publication does.

🐛 Suggested fix
-import { runtimeEnvironmentIdUnlessTwin } from '@/lib/resolve-owner'
+import { mainListsWorkspaceTerminals } from '@/runtime/sync-runtime-graph/main-owned-terminal-list'
 import { expectPaneToClose } from '@/runtime/layout-owner-pane-intents'
 import { useAppStore } from '@/store'
@@
-  if (
-    !pane.leafId ||
-    runtimeEnvironmentIdUnlessTwin(useAppStore.getState(), pane.worktreeId) !== null
-  ) {
+  if (!pane.leafId || !mainListsWorkspaceTerminals(useAppStore.getState(), pane.worktreeId)) {
     return false
   }

@Jinwoo-H
Jinwoo-H merged commit c335070 into main Oct 20, 2026
57 of 58 checks passed
brennanb2025 added a commit that referenced this pull request Oct 20, 2026
Main's layout-owner groundwork (#31130, #31171, #31187, dark) and the binding
fast lane (#31033) touched the same files. Binding retirement keeps this
branch's incarnation fence and uses main's dirty marking; a failed start keeps
its pane for main's keep-on-failure starts and for owner contention; the fresh
launch path takes main's pane start status arguments.
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