Skip to content

Main starts each restored terminal pane once, at its last size, and names sleeping and held panes (layout-owner build only) - #31171

Merged
Jinwoo-H merged 65 commits into
mainfrom
fd/c1b-main-starts-panes
Oct 20, 2026
Merged

Jinwoo-H merged 65 commits into
mainfrom
fd/c1b-main-starts-panes

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1681 $\color{#cf222e}{\Huge{\mathbf{−}}}$​281 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1400
Prod 40 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1128 $\color{#cf222e}{\Huge{\mathbf{−}}}$​191 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​937

ELI5

When Orca restarts, the main process now decides how each saved terminal pane comes back, but only in the build where main owns the layout. Released builds are unchanged. It starts each pane once, at the size it last had. It also says plainly when a pane's terminal is gone ("sleeping") or is still held by a newer Orca ("held").

What Changed

All of this applies only in the layout-owner build (ORCA_LAYOUT_OWNER_IS_MAIN). The released build behaves exactly as before.

  • One start per restored pane. Main has one starter, ensureRestoredPaneStarted in restored-pane-materialize.ts.
    • Today it has one production caller: a phone or paired client's first view of a pane with no live terminal.
    • CLI and orchestration send, wait, read and wake get wired to it when A1's pane handles land; whichever of A1 and this PR merges second does the wiring.
    • Triggers that arrive together share one start. Window-versus-runtime dedupe stays on the existing spawn join, and a three-way race test covers the dedupe contract.
    • The starter returns the terminal its own start registered. It does not re-read the saved layout, whose write can still be in flight.
    • It never resolves to a live terminal another workspace owns.
    • A first view of a pane main has since dropped is refused with tab_not_found, the code older phones already handle.
  • No extra shell beside a live terminal. A workspace's first tab (initial create) now waits for main's placement pass that is running when it arrives, for at most 500 ms.
    • Before: a window activating a workspace whose live terminal the pass had not placed yet got a fresh shell tab, and then the live terminal's tab beside it.

    • If the pass takes longer than 500 ms, the first tab is admitted anyway, and an extra tab may appear next to the restored terminal (owner-visible row 21).

    • At startup the window already waits for the pass. The cap covers passes started by a client attach or a terminal-service rebind.

    • A pass that starts after the first tab was admitted can likewise add a tab beside it. That needs a live terminal with no pane to appear after startup.

    • Measured in the desktop app (layout-owner dev build, hidden window, macOS, through the window's own layout.apply IPC, 3 runs each):

      Case First-tab time Pass time
      No pass running 2.0, 3.5, 11.3 ms none
      Typical pass (nothing to place) 2.2, 2.2, 5.4 ms 0.9-1.3 ms
      Pass placing 20 live terminals 6.3, 70.6, 105.3 ms 71-151 ms
    • A headless server on a fresh profile showed passes of 0.9-24 ms.

  • Bounded quit step. The pane-grid write is capped at 1 s, and a grid it misses only restarts at the default size. A write that loses the race is refused by the store once the final save has started.
    • It runs before the SSH shutdown starts (desktop and serve quit), so nothing is awaited between the SSH shutdown and the final save.
    • In orcad it runs before the final save.
    • With the switch off no grid is ever recorded, so the step is null and nothing is awaited.
    • A test proves that a hung grid write can't hold the quit past the cap.
  • Last size. Main records each pane's last grid (lastGridsByLeafId) beside its title on the saved tab layout. A resize is written at most once per second per pane, and quit flushes any pending write. The grid is never published to clients. A restarted pane opens at this size: a size the caller measured wins, then the last grid, then the group's size, then 120x40.
  • Pane status. A status means "the terminal to restore from", not a live terminal, even on a bound pane. A pane with no status and a bound terminal is live.
    • sleeping: the host's census answered and the pane's local terminal is gone.
    • held: a newer build's terminal service may still be running it.
    • starting / resuming / failed: as before.
    • Relay and paired-server terminals are never marked sleeping by this host.
    • A window treats a status-only frame as a binding change, so it rebuilds nothing.
  • Another workspace's terminal. A pane bound to a terminal minted for another workspace is released through a new main-only command, releasePaneTerminal, and starts fresh. This is the window's existing rule. SSH ids name a connection, not a workspace, so they keep reattaching over the relay.
  • Cold-restore acknowledgement stays where it is. It only frees the daemon's in-memory restore cache; history across restarts lives in the checkpoint. A new test, "keeps restored history across two restarts of the host with no client acking it", guards this. It passes before and after this change; it is a guard, not a fail-first test. See daemon-pty-session-control.ts and daemon-pty-spawn-result.ts. Moving the acknowledgement into main is C1c's job.
  • Stale tests converted, none dropped. The activation-gate and worktree-reopen tests now assert the same behaviour through main's command and frame. The old window-owned versions run only with the switch off.

Why

  • Today each trigger restores a pane its own way. That can start two shells, open a pane at a default size, or show a dead terminal as failed.
  • One starter in main, with one status vocabulary, gives every client the same answer, including over SSH and for paired servers.
  • The grid is stored on the existing tab layout, not in a new store, so it shares that layout's save, migration and quit flush.
  • held is a separate status because today's window already shows something distinct for it:
    • daemon-router-newer-daemon-hold.ts:13-34 holds the spawn;
    • newer-daemon-hold-pane.ts:28 disables input and :49-57 reads the held screen;
    • TerminalPaneRuntimePortals.tsx:76 shows the NewerDaemonHoldBanner.

Ledger rows owned by later steps:

  • L236 (C1c): there are two scrollback sources. Measured restore depth: the daemon keeps 5039 rows in every line shape. The window buffer, capped at 512 KiB, keeps 5039 rows for plain 80-column lines, 2595 for 200-column lines and 2089 for coloured lines. Retiring the window buffer therefore deepens history. C1c carries a first-paint timing gate.
  • L237 (C1c): the desktop window keeps restoring by id until C1c.

Linked Issue

Part of the terminal-layout final design (C1b). Stacked on #31130.

Visual Proof

N/A. This is dark behind the layout-owner build switch, and nothing changes in released builds.

Testing

  • Automated tests added/updated
  • New unit tests cover the starter, the race, the last grid with its quit flush, sleeping and held, the foreign-workspace release and the SSH exemption, the window's status-only frame, and the two-restart history guard.
  • ci-static-gate --with-slow passes on the head, along with the census, routing and stub tests and every unit test that imports a changed file.
  • I ran the switch-on runtime and persistence suites (ORCA_LAYOUT_OWNER=main) at the head and at the merge-base in a clean worktree. Every file that fails at the head but not at the base also fails at Layout groundwork (switched off): main creates, starts and closes terminal tabs and panes itself #31130's head 6b8c37f5f05 with the same tests, so this PR adds no switch-on regressions. Two regressions this PR introduced were fixed:
    • an SSH pane started fresh instead of reattaching;
    • the starter re-read a layout write still in flight.
  • macOS only locally; CI covers Linux and Windows.

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

  • Cross-platform: no platform-specific code.
  • SSH: SSH ids are exempt from the foreign-workspace rule and the sleeping verdict.
    • Matching an SSH id to the workspace's own connection is not done here; it matches the switch-off path. C1d owns SSH redial.
  • Mobile: the phone's first view goes through the starter, and the wire is unchanged. The grid is never published, and the new status values sit on an existing optional field.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A with reason for visuals
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Local gate passes

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)
…ts binding generation (dark, layout-owner build only)
…taches or the terminal service is replaced (dark, layout-owner build only)

Headless servers had no retry: a terminal the startup pass declined stayed tabless until the
next restart. The pass now also runs when a client authenticates and after the local terminal
provider is installed or replaced, one pass at a time. A terminal whose pane record fails to
save after main bound it is no longer reported as left without a pane.
…rk, layout-owner build only)

A new main-only setPaneGrid command records the grid a pane's terminal was last sized to, on
its leaf. It is saved as the layout's optional lastGridsByLeafId, which older builds drop on
read, so a downgrade loses only the hint. It moves with its pane.
…d starts the pane at it (dark, layout-owner build only)

Each accepted resize, from a window or a client, is written once per burst as the pane's last
grid. A pane main holds starts at that grid, after a size the caller measured and before its
group's size, then 120x40.
…rid change publishes nothing (dark, layout-owner build only)

The desktop and serve quit and orcad's shutdown write any grid still inside its one-second
burst before the final store flush; a quit with none waiting adds no await. A grid is main's
own record: it is not in a published pane, so a resize burst sends no layout frame, and its
write patches only the pane's tab.
…what a status on a bound pane means (dark, layout-owner build only)
…pace's terminal (dark, layout-owner build only)

The window's restore rule, now in main for every host: a pane whose stored terminal id was
minted for another workspace is unbound, so it starts fresh, and that terminal, if live, is
placed in its own workspace. The id check moves to shared, which the window now imports.
… may still run the pane shows it held, not failed (dark, layout-owner build only)
E2E Test and others added 23 commits October 20, 2026 12:25
…estore starter returns the terminal it started (layout-owner build)

An SSH terminal id names its connection, not a workspace, so the rule that drops another
workspace's terminal no longer releases it or starts the pane fresh. The starter now resolves
to the id its start registered instead of re-reading the stored layout, whose bind write can
still be in flight, and a tab saved with no layout counts as one held pane.
…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.
…s live terminals, so activation opens no extra shell beside one (layout-owner build)

A window activating a workspace before main's placement pass had read the host census found no
tab and asked main for the first one; main admitted it into the still-empty workspace, then the
pass added the live terminal's own tab beside it. An initial create now waits out a pass in flight.
…s live terminal, and a first view of a pane main dropped is refused (layout-owner build)
…and keeps the runtime file under the line limit
…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.
… pass running when it arrives, and the switch-off build applies commands as before
… 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.
…econd, and orcad awaits nothing for them when none wait

The grid flush before the final save (desktop and serve quit, orcad stop) is now raced against a
1 s budget; a grid it misses only means that pane restarts at the default size. With the switch
off no grid is ever recorded, so the flush is null and orcad no longer awaits even that.
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.
… budget timer live, and the quit's no-await note names it
…, and a workspace's first tab waits at most 0.5 s for main's placement pass

The quit's grid flush (still capped at 1 s) now runs before beginSshShutdown, so nothing is awaited
between it and the final save; with no grid waiting, both start synchronously as before. A first tab
waits for the running placement pass at most 500 ms, then is admitted. The quit test's SSH mock now
names the module the quit imports.
…turn as the SSH shutdown, in order after the PTY kill
# Conflicts:
#	src/renderer/src/runtime/workspace-layout-frame-binding.test.ts
#	src/renderer/src/runtime/workspace-layout-frame-changes.ts
@Jinwoo-H
Jinwoo-H changed the base branch from fd/d1-terminal-main-first to main October 20, 2026 19:11
# Conflicts:
#	src/main/persistence/terminal-topology/layout-command-persistence.ts
#	src/main/runtime/orca-runtime-failed-start-pane-layout-owner.test.ts
#	src/main/runtime/pane-start-statuses.ts
#	src/main/runtime/runtime-pane-admission.ts
#	src/main/runtime/terminal/launch/failed-start-pane.ts
#	src/shared/workspace-layout/workspace-layout-published.ts
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds main-owned layout commands for default tabs, pane grids, and terminal bindings. It adds persistence for pane dimensions and terminal-close writes, and it updates startup provisioning to track pane status and retain selected failed starts. Restored-pane startup and live-terminal placement now account for workspace ownership and concurrent calls. PTY exit handling uses visibility and termination facts when deciding whether to retain panes. Renderer paths and tests cover main-owned layout behavior alongside existing ownership modes.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 3f4d7

Merge Risk: 🟡 Moderate · up to 3f4d7

These issues affect only builds where the main process owns terminal layout; released builds are unchanged. In those builds, a pane can lose its own terminal during restore when workspace keys are spelled differently, and a legacy pane ID can block a pane from starting at all. Smaller issues: saved pane sizes may not persist, an exited split pane can stay on screen after layout updates stop, and a removed pane may be started again. Fix the two restore issues before enabling the switch.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 46.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 56 functions across 50 files. (70 skipped… 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 describes the main change: main-owned restored-pane startup, saved sizing, and pane statuses. It is lengthy but specific and relevant.
Description check Passed The description covers the required explanation, changes, rationale, linked work, visual proof, testing, and compatibility notes. The blank Review section and AI Disclosure do not make it incomplete; …
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 covers the required explanation, changes, rationale, linked work, visual proof, testing, and compatibility notes. The blank Review section and AI Disclosure do not make it incomplete; the template exempts internal contributors from AI Disclosure.

Full details: Docstring Coverage

Explanation

Docstring coverage is 46.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 56 functions across 50 files. (70 skipped: 70 over the file limit.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch fd/c1b-main-starts-panes
  • 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: 5


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40b45e74-2495-4119-af64-afa3271aa0f6
📥 Commits

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

📒 Files selected for processing: 121
  • config/scripts/check-id-only-store-write-ratchet.mjs
  • config/scripts/check-id-only-store-write-ratchet.test.mjs
  • src/main/daemon/daemon-pty-adapter-cold-restore-reanchor.test.ts
  • src/main/ipc/pty-launch-race-parity.test.ts
  • src/main/ipc/pty/provider/bind-listeners.ts
  • src/main/ipc/pty/provider/listener-lifecycle.ts
  • src/main/ipc/pty/provider/local-configure.ts
  • src/main/ipc/pty/provider/local-provider-rebound.test.ts
  • src/main/ipc/pty/provider/local-provider-rebound.ts
  • src/main/ipc/pty/pty-first-size.ts
  • src/main/orcad/orcad-duplicate-pty-repair-startup.test.ts
  • src/main/orcad/orcad-entry.ts
  • src/main/orcad/orcad-push-startup.test.ts
  • src/main/persistence/loading-store/pty-binding-generations.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-binding-generations.ts
  • src/main/persistence/terminal-topology/layout-command-persistence.ts
  • src/main/persistence/terminal-topology/pane-last-grid.test.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/unshown-live-terminal-placement-restart.test.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-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/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/pane-start-statuses.test.ts
  • src/main/runtime/pane-start-statuses.ts
  • src/main/runtime/restored-pane-start-layout-owner.test.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-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-rpc-client-attach-placement.test.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-lifecycle.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/runtime-worktree-default-tabs-layout-owner.test.ts
  • src/main/runtime/runtime-worktree-terminal-provisioning.ts
  • src/main/runtime/session-lifecycle/projection/perform-mobile-session-pty-records-refresh.ts
  • src/main/runtime/session-lifecycle/projection/restored-pane-materialize.ts
  • src/main/runtime/session-tabs/terminal-surface-retirements.ts
  • src/main/runtime/terminal-intentional-stop-exit.test.ts
  • src/main/runtime/terminal/adoption/unshown-live-terminal-placement.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-pane-last-grid.test.ts
  • src/main/runtime/terminal/launch/terminal-create.ts
  • src/main/runtime/terminal/layout/pane-grid-recording.test.ts
  • src/main/runtime/terminal/layout/pane-grid-recording.ts
  • src/main/runtime/terminal/layout/terminal-display-mode.ts
  • src/main/runtime/terminal/layout/terminal-layout-application.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/recovery/foreign-pane-bindings.ts
  • src/main/runtime/terminal/recovery/restored-pane-start.test.ts
  • src/main/runtime/terminal/recovery/restored-pane-start.ts
  • src/main/runtime/workspace-layout-stream.test.ts
  • src/main/runtime/workspace-layout-stream.ts
  • src/main/runtime/workspaces/persisted-surfaces/live-terminal-placement-before-initial-tab.test.ts
  • src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.test.ts
  • src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.ts
  • src/main/runtime/workspaces/startup/workspace-terminal-provisioning.ts
  • src/main/startup/main-process-ipc-bootstrap.ts
  • src/main/startup/main-process-quit-pending-writer.test.ts
  • src/main/startup/main-process-quit.ts
  • src/main/startup/main-process-runtime-launch.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/paired-parked-terminal-restore.ts
  • src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts
  • src/renderer/src/lib/worktree-agent-activation-gate-layout-owner.test.ts
  • src/renderer/src/lib/worktree-agent-activation-gate.test-fixture.ts
  • src/renderer/src/lib/worktree-agent-activation-gate.test.ts
  • src/renderer/src/lib/worktree-reactivation-tab-forkbomb.test.ts
  • src/renderer/src/runtime/layout-apply-send.ts
  • src/renderer/src/runtime/workspace-layout-frame-binding.test.ts
  • src/renderer/src/store/terminals/terminal-tab-close-intent.test.ts
  • src/shared/pty-session-id-format.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/rpc-contract/workspace-layout-terminal-tab-params.ts
  • src/shared/terminal-layout-snapshot-schema.ts
  • src/shared/terminal-tab-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-disk-fields.ts
  • src/shared/workspace-layout/workspace-layout-fact-locations.test.ts
  • src/shared/workspace-layout/workspace-layout-load-bindings.ts
  • src/shared/workspace-layout/workspace-layout-model.ts
  • src/shared/workspace-layout/workspace-layout-pane-commands.ts
  • src/shared/workspace-layout/workspace-layout-published.ts
  • src/shared/workspace-layout/workspace-layout-records.ts
  • src/shared/workspace-layout/workspace-layout-round-trip-check.ts
  • src/shared/workspace-layout/workspace-layout-save-tabs.ts
  • src/shared/workspace-session-schema.ts
💤 Files with no reviewable changes: 1
  • src/main/runtime/runtime-layout-apply.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.

Comment on lines +83 to +85
const layout = session?.terminalLayoutsByTabId?.[tabId]
// Why: a tab saved with no layout is one pane, the one the projection lists for it.
return layout ? layout.ptyIdsByLeafId?.[leafId] : (row.ptyId ?? undefined)

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

Return null when the layout no longer contains the leaf.

The doc comment says storedPaneBinding returns null "once main no longer holds it". The code only checks the tab row. If the tab row and layout still exist but the user closed this split leaf, layout.ptyIdsByLeafId?.[leafId] is undefined. RestoredPaneStarter then treats the pane as unbound and calls start. Whether that start succeeds depends on mobileSessionTabsByWorktree still listing the leaf. A non-forced hydrate can leave a stale snapshot. The result can be a PTY started for a pane that is no longer in the layout, or a misleading error instead of tab_not_found.

Check the layout tree itself. Do not rely on ptyIdsByLeafId, because a live but unbound leaf has no entry there.

Proposed fix
--- "a/src/main/runtime/session-lifecycle/projection/restored-pane-materialize.ts"
+++ "b/src/main/runtime/session-lifecycle/projection/restored-pane-materialize.ts"
@@ -80,9 +80,12 @@
     if (!row) {
       return null
     }
     const layout = session?.terminalLayoutsByTabId?.[tabId]
+    if (layout && !collectLeafIds(layout.root).includes(leafId)) {
+      return null
+    }
     // Why: a tab saved with no layout is one pane, the one the projection lists for it.
     return layout ? layout.ptyIdsByLeafId?.[leafId] : (row.ptyId ?? undefined)
   }
 
   /** Starts a pending terminal row in its own pane, resuming the agent the host recorded there. */
import { collectLeafIds } from '../../../../shared/terminal-pane-layout-tree'

Comment on lines +15 to +29
export function paneShowingTerminal(
session: WorkspaceSessionState,
ptyId: string
): ShownPane | null {
for (const [workspace, rows] of Object.entries(session.tabsByWorktree ?? {})) {
for (const row of rows) {
const bindings = session.terminalLayoutsByTabId?.[row.id]?.ptyIdsByLeafId ?? {}
const leafId = Object.keys(bindings).find((leaf) => bindings[leaf] === ptyId)
if (leafId) {
return { workspace, tabId: row.id, leafId }
}
}
}
return 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:

#!/bin/bash
rg -nP -C6 'export function findTerminal\s*\(' --type=ts
rg -nP -C3 'getWorkspaceSessionHostIdsForTab\s*\(' --type=ts -g '!**/*.test.ts' | head -60
rg -nP -C3 'entityId:\s' src/shared/workspace-layout --type=ts | head -80

Repository: stablyai/orca

Length of output: 14189


🏁 Script executed:

#!/bin/bash
printf '%s\n' '--- pane-grid-recording.ts ---'
nl -ba src/main/runtime/terminal/layout/pane-grid-recording.ts | sed -n '1,150p'

printf '%s\n' '--- setPaneGrid and paneTab bindings ---'
rg -n -C5 -F -e 'setPaneGrid' -e 'paneTab' src/shared/workspace-layout src/main/runtime || test "$?" -eq 1

printf '%s\n' '--- layout loading and terminal tab construction ---'
nl -ba src/shared/workspace-layout/workspace-layout-load-tabs.ts | sed -n '1,100p'
rg -n -C4 -F -e 'tabsByWorktree' -e 'type WorkspaceSessionState' -e 'interface WorkspaceSessionState' src/shared src/main/runtime | head -240

printf '%s\n' '--- terminal row type and row-to-layout projection ---'
rg -n -C5 -F -e 'interface TerminalRow' -e 'type TerminalRow' -e 'tabsByWorktree:' src || test "$?" -eq 1
rg -n -C5 -F -e 'terminalIdOf' src/main/runtime/terminal src/main/runtime || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 45668


🏁 Script executed:

#!/bin/bash
printf '%s\n' '--- terminalIdOf ---'
nl -ba src/main/runtime/runtime-layout-apply.ts | sed -n '205,250p'

printf '%s\n' '--- layout tab and terminal row declarations ---'
rg -n -C5 -F -e 'export type LayoutTerminalTab' -e 'export interface LayoutTerminalTab' -e 'export type TerminalTab' -e 'export interface TerminalTab' src/shared/workspace-layout src/shared/terminal-tab-types.ts src/shared/tab-types.ts
rg -n -C3 -F -e 'export type WorkspaceSessionState' -e 'export interface WorkspaceSessionState' src/shared/workspace-session-state-types.ts

printf '%s\n' '--- loadTerminalTab callers and identity mapping ---'
rg -n -C6 -F -e 'loadTerminalTab(' src/shared/workspace-layout
rg -n -C4 -F -e 'terminalIdOf(' src/main/runtime/runtime-layout-apply.ts

Repository: stablyai/orca

Length of output: 8790


🏁 Script executed:

#!/bin/bash
printf '%s\n' '--- workspace layout row-to-entry join ---'
nl -ba src/shared/workspace-layout/workspace-layout-load-workspace.ts | sed -n '65,135p'

printf '%s\n' '--- session unifiedTabs declaration ---'
nl -ba src/shared/workspace-session-state-types.ts | sed -n '35,125p'

printf '%s\n' '--- unified Tab declaration ---'
nl -ba src/shared/tab-types.ts | sed -n '1,95p'

printf '%s\n' '--- setPaneGrid lookup and refusal ---'
nl -ba src/shared/workspace-layout/workspace-layout-pane-commands.ts | sed -n '30,38p;155,180p'
nl -ba src/shared/workspace-layout/workspace-layout-command-steps.ts | sed -n '45,60p'

Repository: stablyai/orca

Length of output: 15665


Use the unified tab ID for setPaneGrid.

loadTabs joins a terminal row by entry.entityId, then builds the layout tab with entry.id. When those IDs differ, paneShowingTerminal passes the row ID to setPaneGrid. findTerminal looks up only LayoutTab.id, so the command returns tab_not_found. PaneGridRecorder.write ignores the result, and the grid is not saved. Resolve the matching terminal entry's ID before returning the pane.

🐛 Suggested fix
       const bindings = session.terminalLayoutsByTabId?.[row.id]?.ptyIdsByLeafId ?? {}
       const leafId = Object.keys(bindings).find((leaf) => bindings[leaf] === ptyId)
       if (leafId) {
-        return { workspace, tabId: row.id, leafId }
+        const tabId =
+          session.unifiedTabs?.[workspace]?.find(
+            (entry) => entry.contentType === 'terminal' && entry.entityId === row.id
+          )?.id ?? row.id
+        return { workspace, tabId, leafId }
       }
📝 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
export function paneShowingTerminal(
session: WorkspaceSessionState,
ptyId: string
): ShownPane | null {
for (const [workspace, rows] of Object.entries(session.tabsByWorktree ?? {})) {
for (const row of rows) {
const bindings = session.terminalLayoutsByTabId?.[row.id]?.ptyIdsByLeafId ?? {}
const leafId = Object.keys(bindings).find((leaf) => bindings[leaf] === ptyId)
if (leafId) {
return { workspace, tabId: row.id, leafId }
}
}
}
return null
}
export function paneShowingTerminal(
session: WorkspaceSessionState,
ptyId: string
): ShownPane | null {
for (const [workspace, rows] of Object.entries(session.tabsByWorktree ?? {})) {
for (const row of rows) {
const bindings = session.terminalLayoutsByTabId?.[row.id]?.ptyIdsByLeafId ?? {}
const leafId = Object.keys(bindings).find((leaf) => bindings[leaf] === ptyId)
if (leafId) {
const tabId =
session.unifiedTabs?.[workspace]?.find(
(entry) => entry.contentType === 'terminal' && entry.entityId === row.id
)?.id ?? row.id
return { workspace, tabId, leafId }
}
}
}
return null
}

Comment on lines +11 to +17
export function isPtyIdMintedForAnotherWorkspace(ptyId: string, worktreeId: string): boolean {
return (
!isRemoteRuntimePtyId(ptyId) &&
!parseAppSshPtyId(ptyId) &&
!isPtySessionIdOwnedByWorktree(ptyId, worktreeId)
)
}

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:

#!/bin/bash
fd -i 'deferred-session-reattach-choice' --exec sed -n '1,120p' {}
rg -nP -C3 '\bisPtySessionIdOwnedByWorktree\s*\(' --type=ts
rg -nP -C2 'legacy raw worktree|canonical WorkspaceKey|worktreeIdentityKey\s*\(' --type=ts -g '!**/*.test.ts' | head -60

Repository: stablyai/orca

Length of output: 12874


🏁 Script executed:

#!/bin/bash
set -u

printf '%s\\n' '--- foreign-pane-bindings.ts ---'
nl -ba src/main/runtime/terminal/recovery/foreign-pane-bindings.ts | sed -n '1,180p'

printf '%s\\n' '--- WorkspaceSessionState declarations and contract ---'
rg -n -F -- 'WorkspaceSessionState' src
rg -n -F -- 'legacy raw worktree' src
rg -n -F -- 'canonical WorkspaceKey' src

printf '%s\\n' '--- workspace identity helper ---'
rg -n -F -- 'function worktreeIdentityKey' src
rg -n -F -- 'const worktreeIdentityKey' src
rg -n -F -- 'export function worktreeIdentityKey' src

printf '%s\\n' '--- PTY session ID minting and ownership declarations ---'
nl -ba src/shared/pty-session-id-format.ts | sed -n '1,100p'
rg -n -F -- 'mintPtySessionId' src
rg -n -F -- 'createPtySessionId' src

printf '%s\\n' '--- placement and release flow ---'
nl -ba src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.ts | sed -n '145,195p'
rg -n -F -- 'panesBoundToAnotherWorkspace' src/main
rg -n -F -- 'releasePaneTerminal' src/main

Repository: stablyai/orca

Length of output: 42206


🏁 Script executed:

#!/bin/bash
set -u

printf '%s\\n' '--- session key type ---'
nl -ba src/shared/workspace-session-state-types.ts | sed -n '34,58p'

printf '%s\\n' '--- workspace identity helper ---'
nl -ba src/shared/worktree/id.ts | sed -n '1,100p'
printf '%s\\n' '--- workspace key parser ---'
rg -n -F -- 'export function parseWorkspaceKey' src/shared
rg -n -F -- 'export function' src/shared/workspace-scope.ts
nl -ba src/shared/workspace-scope.ts | sed -n '1,140p'

printf '%s\\n' '--- PTY ID minting ---'
nl -ba src/main/daemon/pty-session-id.ts | sed -n '1,70p'
nl -ba src/main/daemon/daemon-pty-session-spawn.ts | sed -n '25,48p'
nl -ba src/main/ipc/pty/ipc/spawn-preflight.ts | sed -n '1,90p'

printf '%s\\n' '--- window-side ownership helper ---'
rg -n -F -- 'function isSessionOwnedByWorktree' src/main/runtime/terminal
rg -n -F -- 'isSessionOwnedByWorktree' src/main/runtime/terminal
nl -ba src/main/runtime/terminal/recovery/paired-parked-terminal-restore.ts | sed -n '1,130p'

printf '%s\\n' '--- canonical-row hydration and worktree key handling ---'
nl -ba src/renderer/src/store/slices/terminals-hydration-canonical-rows.test.ts | sed -n '1,220p'
rg -n -F -- 'worktreeIdentityKey(' src/shared src/main src/renderer/src/store/slices | head -80

Repository: stablyai/orca

Length of output: 32209


🏁 Script executed:

#!/bin/bash
set -u

printf '%s\\n' '--- foreign ownership predicate consumers ---'
rg -n -F -- 'isPtyIdMintedForAnotherWorkspace' src
rg -n -F -- 'restoredPaneStartPlan' src/main
rg -n -F -- 'isOwnLive' src/main/runtime/workspaces src/main/runtime/terminal

printf '%s\\n' '--- release command declarations and consumers ---'
rg -n -F -- 'releasePaneTerminal' src/main src/shared src/renderer/src
rg -n -F -- 'releasePaneTerminal' src/main/runtime/workspaces/persisted-surfaces/restored-terminal-placement.test.ts

printf '%s\\n' '--- deferred window ownership check ---'
rg -n -F -- 'function isSessionOwnedByWorktree' src/main/runtime
rg -n -F -- 'isSessionOwnedByWorktree' src/main/runtime/terminal

Repository: stablyai/orca

Length of output: 3464


🏁 Script executed:

#!/bin/bash
set -u

printf '%s\\n' '--- restored pane startup decision ---'
nl -ba src/main/runtime/terminal/recovery/restored-pane-start.ts | sed -n '1,115p'

printf '%s\\n' '--- releasePaneTerminal behavior ---'
nl -ba src/shared/workspace-layout/workspace-layout-pane-commands.ts | sed -n '165,225p'
nl -ba src/shared/workspace-layout/workspace-layout-command-types.ts | sed -n '98,118p'

printf '%s\\n' '--- exact binding predicate and imports ---'
nl -ba src/main/runtime/terminal/recovery/foreign-pane-bindings.ts | sed -n '1,34p'

Repository: stablyai/orca

Length of output: 9929


Compare normalized workspace identities before releasing a pane’s PTY.

tabsByWorktree may use a canonical worktree: key, while mintPtySessionId preserves the raw worktree ID. The exact-string comparison can therefore classify a pane’s own PTY as foreign. Placement can then unbind the PTY, and the restored-pane start plan omits its sessionId, preventing reattachment through that path. releasePaneTerminal does not stop the PTY.

🐛 Suggested fix
--- "a/src/main/runtime/terminal/recovery/foreign-pane-bindings.ts"
+++ "b/src/main/runtime/terminal/recovery/foreign-pane-bindings.ts"
@@ -2,19 +2,28 @@
 // reattaches to a terminal another workspace owns (the window's rule,
 // deferred-session-reattach-choice.ts), and one whose local terminal is gone shows as sleeping.
 
-import { isPtySessionIdOwnedByWorktree } from '../../../../shared/pty-session-id-format'
+import { PTY_SESSION_ID_SEPARATOR } from '../../../../shared/pty-session-id-format'
 import { isRemoteRuntimePtyId } from '../../../../shared/remote-runtime-pty-id'
 import { parseAppSshPtyId } from '../../../../shared/ssh-pty-id'
+import { normalizeWorkspaceSessionKeyToWorkspaceId } from '../../../../shared/workspace-scope'
+import { worktreeIdsEqual } from '../../../../shared/worktree/id'
 import type { WorkspaceSessionState } from '../../../../shared/workspace-session-state-types'
 
 /** An SSH id names its connection, never a workspace, so only a local minted id can be foreign. */
 export function isPtyIdMintedForAnotherWorkspace(ptyId: string, worktreeId: string): boolean {
+  const separatorIdx = ptyId.lastIndexOf(PTY_SESSION_ID_SEPARATOR)
+  const sessionWorktreeId =
+    separatorIdx === -1 ? null : ptyId.slice(0, separatorIdx)
   return (
     !isRemoteRuntimePtyId(ptyId) &&
     !parseAppSshPtyId(ptyId) &&
-    !isPtySessionIdOwnedByWorktree(ptyId, worktreeId)
+    sessionWorktreeId !== null &&
+    !worktreeIdsEqual(
+      normalizeWorkspaceSessionKeyToWorkspaceId(sessionWorktreeId),
+      normalizeWorkspaceSessionKeyToWorkspaceId(worktreeId)
+    )
   )
 }
 
 export type PaneBinding = { worktreeId: string; tabId: string; leafId: string; ptyId: string }
 

* terminal, so every caller ends bound to the same one.
*/
ensureStarted(pane: RestoredPane, trigger: RestoredPaneTrigger = {}): Promise<string | null> {
const key = makePaneKey(pane.tabId, pane.leafId)

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 | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Is a non-UUID leaf ID still accepted or migrated anywhere in session loading or mobile tabs?
rg -nP -C3 '\bisTerminalLeafId\s*\(' --type=ts -g '!**/*.test.ts'
rg -nP -C3 'legacy.*leaf(Id)?|leafId.*legacy' --type=ts -g '!**/*.test.ts' | head -60

Repository: stablyai/orca

Length of output: 42318


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- changed file diff against supplied merge base ---'
git diff --no-ext-diff --unified=30 38034167e7aa0c2d5159d23e8d7cb4d765dcc6df b938d1db325db744ee13fc78ede1f27d7eb7409d -- src/main/runtime/terminal/recovery/restored-pane-start.ts
printf '%s\n' '--- restored starter source ---'
nl -ba src/main/runtime/terminal/recovery/restored-pane-start.ts | sed -n '1,180p'
printf '%s\n' '--- references to starter and activation ---'
rg -n -F --glob '*.ts' -e 'ensureRestoredPaneStarted' -e 'ensureStarted(' src/main
printf '%s\n' '--- mobile activation symbol locations ---'
rg -n -F --glob '*.ts' 'activateMobileSessionTab' src/main
printf '%s\n' '--- leaf ID contract ---'
nl -ba src/shared/stable-pane-id.ts | sed -n '1,65p'
printf '%s\n' '--- restoration normalization declaration and call references ---'
nl -ba src/main/persistence/restoring-sessions/terminal-layout-normalization.ts | sed -n '115,175p'
rg -n -F --glob '*.ts' -e 'normalizeTerminalLayout' -e 'terminal-layout-normalization' src/main/persistence src/main/runtime

Repository: stablyai/orca

Length of output: 29554


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- restored-pane materializer ---'
nl -ba src/main/runtime/session-lifecycle/projection/restored-pane-materialize.ts | sed -n '1,125p'
printf '%s\n' '--- activation and refresh caller ---'
nl -ba src/main/runtime/session-lifecycle/projection/perform-mobile-session-pty-records-refresh.ts | sed -n '105,225p'
printf '%s\n' '--- workspace pane normalization call path ---'
nl -ba src/main/persistence/restoring-sessions/workspace-pane-normalization.ts | sed -n '1,190p'
printf '%s\n' '--- callers of workspace normalization ---'
rg -n -F --glob '*.ts' 'normalizeWorkspacePane' src/main
printf '%s\n' '--- layout-owner starter binding and mobile projection wiring ---'
rg -n -F --glob '*.ts' -e 'RestoredPaneMaterializer' -e 'restoredPanes:' -e 'ensureRestoredPaneStarted:' src/main/runtime src/main

Repository: stablyai/orca

Length of output: 22226


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- mobile terminal projection ---'
nl -ba src/renderer/src/runtime/sync-runtime-graph/mobile-session-terminal-tabs.ts | sed -n '1,130p'
printf '%s\n' '--- hydration function and callers ---'
rg -n -F --glob '*.ts' 'hydrateHeadlessMobileSessionTabsFromWorkspaceSession' src/main
printf '%s\n' '--- hydration owner outline and surrounding declaration ---'
rg -n -F --glob '*.ts' -e 'hydrateHeadlessMobileSessionTabsFromWorkspaceSession' -e 'buildHeadlessMobileSession' src/main/runtime/session-lifecycle
printf '%s\n' '--- persisted identity normalization callers ---'
rg -n -F --glob '*.ts' -e 'normalizePersistedPaneIdentityState' -e 'normalizeWorkspaceSessionPaneIdentities' src
printf '%s\n' '--- remainder of persisted-state normalization ---'
nl -ba src/main/persistence/restoring-sessions/workspace-pane-normalization.ts | sed -n '177,275p'
printf '%s\n' '--- runtime projection tab type/use sites ---'
rg -n -F --glob '*.ts' -e 'RuntimeMobileSessionTerminalTab' -e 'parentLayout' src/main/runtime/session-lifecycle/projection/build-headless-mobile-session-browser-tabs.ts src/main/runtime/session-lifecycle/projection

Repository: stablyai/orca

Length of output: 30657


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- runtime leaf resolver ---'
rg -n -F --glob '*.ts' 'getRuntimeLeafIdsForTerminal' src/renderer/src/runtime
nl -ba src/renderer/src/runtime/sync-runtime-graph/mobile-session-surfaces.ts | sed -n '1,190p'
printf '%s\n' '--- terminal layout snapshot normalizer ---'
rg -n -F --glob '*.ts' 'function normalizeTerminalLayoutSnapshot' src/renderer/src
nl -ba src/renderer/src/components/terminal-pane/layout-serialization.ts | sed -n '1,190p'
printf '%s\n' '--- headless mobile session hydration ---'
nl -ba src/main/runtime/session-tabs/mobile-session-hydration.ts | sed -n '1,245p'

Repository: stablyai/orca

Length of output: 28169


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- headless terminal projection definitions ---'
rg -n -F --glob '*.ts' 'buildHeadlessMobileSessionTerminalTabs' src/main/runtime
nl -ba src/main/runtime/mobile-session-terminal-projection.ts | sed -n '1,270p'
printf '%s\n' '--- actual terminal layout snapshot normalizer ---'
nl -ba src/renderer/src/components/terminal-pane/terminal-layout-leaf-ids.ts | sed -n '180,285p'
printf '%s\n' '--- session snapshot publication normalization ---'
nl -ba src/main/persistence/loading-store/workspace-session-snapshot-publication.ts | sed -n '1,115p'
printf '%s\n' '--- persisted store loading normalization ---'
nl -ba src/main/persistence/loading-store/store.ts | sed -n '85,145p'

Repository: stablyai/orca

Length of output: 20194


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- persisted terminal leaf helper declarations ---'
rg -n -F --glob '*.ts' -e 'collectPersistedTerminalLeafIds' -e 'deriveHeadlessLegacyTerminalLeafId' src/main/runtime
nl -ba src/main/runtime/mobile-session-layout-projection.ts | sed -n '1,155p'

Repository: stablyai/orca

Length of output: 8204


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- mobile snapshot assignment and publication entrypoints ---'
rg -n -F --glob '*.ts' -e 'mobileSessionTabsByWorktree.set' -e 'mobileSessionTabsByWorktree =' -e 'setMobileSessionTabs' -e 'RuntimeMobileSessionTabsSnapshot' src/main
printf '%s\n' '--- mobile session snapshot RPC/input handlers ---'
rg -n -F --glob '*.ts' -e 'session.tabs' -e 'mobile-session-tabs' -e 'mobileSessionTabs' src/main/runtime/rpc src/main/ipc
printf '%s\n' '--- pane capture leaf ID source ---'
nl -ba src/renderer/src/runtime/sync-runtime-graph/mobile-session-capture.ts | sed -n '1,150p'

Repository: stablyai/orca

Length of output: 42174


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- graph sync source files ---'
rg --files src/main/runtime | rg 'graph-sync|runtime-identity-state'
printf '%s\n' '--- snapshot storage implementation ---'
nl -ba src/main/runtime/construction/runtime-identity-state.ts | sed -n '95,130p'
printf '%s\n' '--- graph-sync callers and snapshot fields ---'
rg -n -F --glob '*.ts' -e 'storeMobileSessionSnapshot' -e 'mobileSessionTabs:' -e 'syncWindowGraph' src/main/runtime
printf '%s\n' '--- mobile terminal tab type ---'
rg -n -F --glob '*.ts' -e 'type RuntimeMobileSessionTerminalTab' -e 'interface RuntimeMobileSessionTerminalTab' src/shared/runtime-types.ts src/shared

Repository: stablyai/orca

Length of output: 41911


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- syncWindowGraph implementation ---'
nl -ba src/main/runtime/session-graph/session-window-graph.ts | sed -n '35,90p'
nl -ba src/main/runtime/session-graph/session-window-graph.ts | sed -n '260,315p'
printf '%s\n' '--- mobile terminal tab contract ---'
nl -ba src/shared/runtime-mobile-session-tab-contracts.ts | sed -n '1,75p'
printf '%s\n' '--- graph sync mobile snapshot gating contract ---'
nl -ba src/main/runtime/runtime-mobile-session-projection-contract.ts | sed -n '1,90p'

Repository: stablyai/orca

Length of output: 12005


🏁 Script executed:

nl -ba src/main/runtime/session-graph/session-window-graph.ts | sed -n '308,355p'

Repository: stablyai/orca

Length of output: 2350


🏁 Script executed:

rg -n -C8 -F --glob '*.ts' 'graph.mobileSessionTabs' src/main/runtime/session-graph/session-window-graph.ts

Repository: stablyai/orca

Length of output: 1846


🏁 Script executed:

rg -n -C12 -F --glob '*.ts' 'syncMobileSessionTabs' src/main/runtime

Repository: stablyai/orca

Length of output: 26655


🏁 Script executed:

nl -ba src/main/runtime/session-tabs/mobile-session-reconciliation.ts | sed -n '40,190p'

Repository: stablyai/orca

Length of output: 8473


🏁 Script executed:

nl -ba src/main/runtime/session-tabs/mobile-session-reconciliation.ts | sed -n '188,285p'

Repository: stablyai/orca

Length of output: 4075


Use a non-validating key for restored-pane deduplication.

ensureStarted can receive a legacy leaf ID from an accepted mobile-session snapshot. Calling makePaneKey then throws before the pane can start.

🐛 Suggested fix
--- "a/src/main/runtime/terminal/recovery/restored-pane-start.ts"
+++ "b/src/main/runtime/terminal/recovery/restored-pane-start.ts"
@@ -53,7 +53,7 @@
    * terminal, so every caller ends bound to the same one.
    */
   ensureStarted(pane: RestoredPane, trigger: RestoredPaneTrigger = {}): Promise<string | null> {
-    const key = makePaneKey(pane.tabId, pane.leafId)
+    const key = `${pane.tabId}\0${pane.leafId}`
     const running = this.inFlight.get(key)
     if (running) {
       return running
📝 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 key = makePaneKey(pane.tabId, pane.leafId)
const key = `${pane.tabId}\0${pane.leafId}`

Comment on lines +15 to +22
if (
!pane.leafId ||
runtimeEnvironmentIdUnlessTwin(useAppStore.getState(), pane.worktreeId) !== null
) {
return false
}
const close = (): void => {
// Why the leaf check: main's answer can land after the pane already went.
if (manager.getLeafId(paneId) !== leafId) {
return
}
// A sibling went, or is going, while main answered: this pane is now the tab's last.
if (
panesLeftAfterPendingCloses(
args.tabId,
manager.getPanes().map((pane) => pane.leafId)
) <= 1
) {
args.closeTab()
return
}
manager.closePane(paneId)
}
// Main holds this pane alone while the window has more: its copy lags, so close as today.
return sendPaneCloseToLayoutOwner(
{ worktreeId: args.worktreeId, tabId: args.tabId, leafId, kind: 'exit' },
{ asToday: close, lastPane: close, closeHere: close }
)
expectPaneToClose(pane.tabId, pane.leafId, 'exit')
return true

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C3 '\blayoutFramesFlowing\s*\(' src/renderer
fd -i 'exited-split-pane-rule.ts' src/main --exec cat -n {}

Repository: stablyai/orca

Length of output: 12315


🏁 Script executed:

printf '%s\n' '--- helper ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/exited-split-pane-close.ts
printf '%s\n' '--- caller references ---'
rg -n -F -- 'expectExitedSplitPaneClose' src/renderer
printf '%s\n' '--- caller and close-intent definitions/usages ---'
rg -n -C 5 -F -e 'expectPaneToClose' -e "closing" src/renderer/src/components/terminal-pane/pty-connection src/renderer/src/components/terminal-pane
printf '%s\n' '--- frame stream lifecycle and snapshot handling ---'
nl -ba src/renderer/src/runtime/layout-frame-position.ts
rg -n -C 5 -F -e 'layoutSnapshotFrame' -e 'onFrame' -e 'stream.onFrame' src/renderer/src/runtime/workspace-layout-frame-sync.ts
printf '%s\n' '--- main exited-pane outcome consumers ---'
rg -n -C 6 -F -e 'exitedSplitPaneOutcome' -e 'closeExitedSplit' src/main src/renderer'

Repository: stablyai/orca

Length of output: 41683


🏁 Script executed:

printf '%s\n' '--- exit caller ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts | sed -n '330,390p'
printf '%s\n' '--- main rule references ---'
rg -n -F -- 'exitedSplitPaneOutcome(' src/main
printf '%s\n' '--- close intents declaration/consumer ---'
rg -n -F -e 'function expectPaneToClose' -e 'expectPaneToClose' -e 'exit' src/renderer/src/runtime/layout-owner-pane-intents.ts src/renderer/src/runtime
printf '%s\n' '--- layout sync definitions ---'
rg -n -F -e 'beginLayoutFramePositions' -e 'endLayoutFramePositions' -e 'noteLayoutFramePosition' src/renderer/src/runtime src/renderer/src/hooks
printf '%s\n' '--- relevant layout sync implementation ---'
rg --files src/main src/renderer | rg 'layout.*(frame|owner|intent|command)|frame.*layout' | head -80

Repository: stablyai/orca

Length of output: 22444


🏁 Script executed:

printf '%s\n' '--- main layout close rule consumer ---'
nl -ba src/main/runtime/exited-split-pane-layout-close.ts
rg -n -F -e 'closeExitedSplitPane' -e 'exitedSplitPaneLayout' -e 'exitedSplitPaneFacts' src/main
printf '%s\n' '--- renderer keep branches and close call ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts | sed -n '280,375p'
printf '%s\n' '--- pane intent implementation ---'
nl -ba src/renderer/src/runtime/layout-owner-pane-intents.ts
printf '%s\n' '--- renderer close intent consumer ---'
rg -n -F -e 'takePaneCloseIntent' -e 'planTerminalLiveLayoutRemovals' -e 'terminal-pane-frame-reconciliation' src/renderer/src
printf '%s\n' '--- frame stream subscription/open/reconnect ---'
nl -ba src/renderer/src/runtime/layout-frame-stream.ts
printf '%s\n' '--- main frame publish behavior ---'
rg -n -F -e 'publishWorkspaceLayout' -e 'layoutSnapshotFrame' -e 'subscribeWorkspaceLayout' src/main/runtime/workspace-layout-frame-observer.ts src/main/runtime

Repository: stablyai/orca

Length of output: 22678


🏁 Script executed:

printf '%s\n' '--- renderer exit path before close branch ---'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/pty-exit-hibernate.ts | sed -n '220,375p'
printf '%s\n' '--- main lifecycle exit facts and retirement ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts | sed -n '235,305p'
printf '%s\n' '--- owner resolution symbol ---'
rg -n -F -- 'runtimeEnvironmentIdUnlessTwin' src/renderer/src/lib
printf '%s\n' '--- main close decision caller ---'
rg -n -F -- 'keepsExitedPane(' src/main
printf '%s\n' '--- renderer frame reconciliation ---'
nl -ba src/renderer/src/components/terminal-pane/terminal-pane-frame-reconciliation.ts
printf '%s\n' '--- runtime layout stream subscription contract ---'
nl -ba src/main/runtime/rpc/methods/workspace-layout.ts | sed -n '1,100p'
nl -ba src/main/runtime/orca-runtime.ts | sed -n '245,290p'
printf '%s\n' '--- owner declaration excerpt ---'
rg -n -l -F -- 'function runtimeEnvironmentIdUnlessTwin' src/renderer/src/lib | xargs -r -n1 sh -c 'nl -ba "$0" | sed -n "1,180p"'

Repository: stablyai/orca

Length of output: 36343


🏁 Script executed:

printf '%s\n' '--- callback declarations and production bindings ---'
rg -n -F -- 'onPaneProcessDied' src/renderer/src
printf '%s\n' '--- exit handler wiring ---'
rg -n -F -e 'createPtyExitHibernate' -e 'pty-exit-hibernate' -e 'handlePtyExit' src/renderer/src/components/terminal-pane
printf '%s\n' '--- main lifecycle close decision ---'
nl -ba src/main/runtime/terminal/lifecycle/pty-exit-lifecycle.ts | sed -n '250,295p'
printf '%s\n' '--- main rule ---'
nl -ba src/main/runtime/terminal/lifecycle/exited-split-pane-rule.ts | sed -n '19,60p'

Repository: stablyai/orca

Length of output: 8426


Close the pane locally when layout frames stop.

For a previously used split pane that exits with code 0, main’s rule closes the pane. If the layout stream has ended, expectExitedSplitPaneClose still records an 'exit' intent and returns true. pty-exit-hibernate.ts then returns before session.manager.closePane(...). No frame can remove the dead pane while the stream is ended, and the intent can remain pending. Check layoutFramesFlowing() before recording the intent so the caller takes the local-close path.

Suggested fix
 import { runtimeEnvironmentIdUnlessTwin } from '@/lib/resolve-owner'
+import { layoutFramesFlowing } from '@/runtime/layout-frame-position'
 import { expectPaneToClose } from '@/runtime/layout-owner-pane-intents'
 import { useAppStore } from '@/store'
@@
   if (
     !pane.leafId ||
+    !layoutFramesFlowing() ||
     runtimeEnvironmentIdUnlessTwin(useAppStore.getState(), pane.worktreeId) !== null
   ) {

@Jinwoo-H
Jinwoo-H merged commit 94ebd4a into main Oct 20, 2026
59 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