Skip to content

Layout groundwork (switched off): main starts every split and new pane, the window only attaches - #31258

Merged
Jinwoo-H merged 24 commits into
mainfrom
fd/d1b-window-main-first
Oct 21, 2026
Merged

Jinwoo-H merged 24 commits into
mainfrom
fd/d1b-window-main-first

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1980 $\color{#cf222e}{\Huge{\mathbf{−}}}$​892 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1088
Prod 32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​924 $\color{#cf222e}{\Huge{\mathbf{−}}}$​397 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​527

ELI5

This is groundwork for the layout rewrite, and it stays switched off in every build that ships. With the switch on, the main process now starts the terminal for every new split and for every pane it creates. The window only shows that terminal; it no longer starts one of its own. A pane whose start failed now shows why, instead of opening a plain shell. Nothing changes for users today.

What Changed

All of this happens only with the layout-owner build switch (ORCA_LAYOUT_OWNER=main) on:

  • Start status reaches the window. Main publishes each pane's start status (starting, failed, and from C1b sleeping, resuming, held) in its layout frames. The window keeps it in a new store field that is never saved. A frame that only changes a status rebuilds nothing, so the pane's view stays mounted.
  • Main marks every pane it starts as starting before it writes the pane, and clears the status when the terminal binds. So no frame ever shows main's new pane unbound with no status, which is what made the window start a second terminal.
  • One attach-only mount. A pane that main is starting waits, then attaches to the terminal main bound it to. A pane whose start failed shows "The terminal could not start: " and starts nothing. This fixes owner-visible row 15: before, a failed agent or setup start showed a plain shell tab with no message. Sleeping, resuming and held panes keep their current restore path; that moves in C1c (ledger L237, L241).
  • Splits start in main (twin d, F-b). The user's split, a startup split that runs a command, and a CLI split all go through main's terminal.split. Main writes the pane under the window's proposed pane id and starts its terminal there, in the source pane's folder and at half the source pane's grid. The window draws the new pane from main's frame and attaches. A startup split leaves focus on its source pane, as today. A window split whose start fails, even before main could start it, shows its pane as failed with the reason. A pane id another pane already holds is refused.
  • Every pane main's layout holds is mounted, even with no window intent (L174): a split main made for the CLI or another client shows in the window and attaches.
  • An exit that reports no code (the terminal's socket closed) keeps the pane, as lost contact, and an older terminal service's exit is judged by its code alone.
  • Deletes (switch-on only): the window's split wait and take-back (L163), the split appear intents (L170, partly; close intents and the tree hold stay), the queued-split mount skip and cancel (L176, L177). The e2e helper splits through the real split path (F-e).

Ids: the window keeps proposing pane ids (decision of 10-20 05:10; ledger L132/L167). The plan's F-c wording "an intent with no ids" is superseded by that decision.

Why

Under the final design main starts every terminal and every view only attaches, with or without a window. Before this, with the switch on, main wrote a split or a new pane and the window then started its own terminal into it, so two processes decided the same start. Reusing terminal.split keeps one entry point for the window, the CLI and paired clients; adding a start field to the layout command was the alternative, but it would have changed the shared frame and command types for no gain.

Linked Issue

N/A (internal design work).

Visual Proof

N/A: switched off in every shipped build, so nothing a user sees changes today. With the switch on, the behaviour is covered by the unit tests below.

Testing

  • ci-static-gate (typecheck, the type-aware lint baseline, code quality, the layout-writer and max-lines ratchets, the census, routing, stub and import-closure tests) passes.
  • New tests, each shown to fail without its change: a status-only frame patches one pane with no build; main shows starting before the pane is written; a pane waits and then attaches to main's terminal at its own grid, a split pane to its own terminal and not its tab's; a failed start shows its reason and spawns nothing; sleeping, resuming and held panes keep their path; main writes and starts every split; a split closed while it starts gets one answer and leaves nothing; a taken pane id is refused; a split that cannot start shows as failed; a startup split keeps focus on its source; an exit with no code keeps its pane.
  • Switch-on comparison against main (src/main/runtime, src/main/persistence, src/renderer/src/runtime, src/renderer/src/components/terminal-pane, ORCA_LAYOUT_OWNER=main, head vs main at 70b2197): no test fails on this branch that passes on main (10 shared failures fail the same way on main). The 25 tests that fail only on main are the converted ones listed next.
  • Switch-on red tests converted, never deleted:
    • returns the exact pre-minted leaf for concurrent renderer-backed splits: stale. It failed because the fixture store had no pane admission; with the switch on main splits itself. Now a switch-on/switch-off pair; the switch-on half asserts each concurrent split returns its own leaf, in main's layout, started under its own pane key.
    • terminal-pane-tab-detach (8) and terminal-pane-tab-detach-commit (8): stale; main mints the moved tab's id. Their switch-on twins in terminal-pane-tab-detach-main-move.test.ts and terminal-pane-tab-detach-main-commit.test.ts assert the command the window sends and the store after main's frame.
    • The 8 renderer exit tests D1a turned red (pty-connection-restore-and-resume: 5, pty-connection-visibility-and-exit: 3): stale; main closes an exited pane since Layout groundwork (switched off): main creates, starts and closes terminal tabs and panes itself #31130. Each now asserts the window does not close the pane and main's close removes it exactly once. "Liveness says the session is missing" is the provider's authoritative "no terminal" (pty:hasPty returns false only then), so main closes; tests 4 and 5 keep their once-only check.

Server specs: switch-on, built fresh at each commit (build:electron-vite:parallel --mode e2e plus build:cli), run through the app slot; head db46bc2, merge-base a1f2094.

  • headless-serve-focused-terminal-create: base pass, head pass.
  • paired-mobile-desktop-tab-composition: base fail, head fail. Both fail the same way: session.tabs.createTerminal returns terminal_handle_stale, the known regression on main.
  • paired-desktop-server-layout-frames: base fail, head fail. Base fails early: the CLI split on the server with no window times out. Head gets past the split, binding, typing and restart steps, then fails at session.tabs.createTerminal with the same terminal_handle_stale. Running this spec also found that a split main starts was missing from session.tabs, which is fixed here with a test.
  • paired-desktop-server-layout-intents: not on main or this branch, so not run.

Review

One independent review per head, plus a review of each fix delta. The review of the last main merge and the publication fix led to three more fixes, each with a test shown to fail without it:

  • a reconnect into a pane main already holds shows the pane starting, and shows why if it fails, like any other start;
  • a pane another owner won shows no failure, because the window attaches to the winner's terminal;
  • a split nobody asked to see (an agent team's) leaves the phones' active tab alone.

The review of those fixes found nothing at medium or above. Its one low finding is also fixed with a test: a create kept to show its failure, whose pane another owner won, no longer shows a failure. The first review's three medium findings are fixed with tests. The final delta review (taken-id check order, clearing a closed pane's status, the merge with main, one extraction) found nothing at medium or above; its one low gap (a pane main wrote and the user closed mid-start) now has a test.

Latency (switch on, this branch vs main)

Measured interleaved through the app slot: main, branch, main, branch; 40 samples per case; p50 in ms. A difference counts only if it has the same sign in both pairs, is larger than main's own run-to-run spread, and is at least 16 ms.

(the time until the change is drawn in the window)

case metric main 1 branch 1 main 2 branch 2 main spread delta 1 delta 2 counts
split (idle) inAppDrawn p50 45 44 49 50 4 -1 +1 no
close pane (idle) inAppDrawn p50 40 62 42 44 2 +22 +2 no
new tab (idle) inAppDrawn p50 21 21 23 24 2 +0 +1 no
rename (idle) inAppDrawn p50 15 16 14 13 1 +1 -1 no
tab reorder (idle) inAppDrawn p50 12 16 13 11 1 +4 -2 no
close tab (idle) inAppDrawn p50 12 12 15 15 3 +0 +0 no
split (flood) inAppDrawn p50 48 45 51 49 3 -3 -2 no
close pane (flood) inAppDrawn p50 43 41 142 76 99 -2 -66 no
new tab (flood) inAppDrawn p50 25 22 25 24 0 -3 -1 no
rename (flood) inAppDrawn p50 13 14 16 13 3 +1 -3 no
tab reorder (flood) inAppDrawn p50 13 11 14 13 1 -2 -1 no
close tab (flood) inAppDrawn p50 25 24 24 24 1 -1 +0 no
split (titles) inAppDrawn p50 48 52 53 52 5 +4 -1 no
close pane (titles) inAppDrawn p50 45 113 91 115 46 +68 +24 no
new tab (titles) inAppDrawn p50 24 27 29 28 5 +3 -1 no
rename (titles) inAppDrawn p50 20 23 27 24 7 +3 -3 no
tab reorder (titles) inAppDrawn p50 14 15 17 19 3 +1 +2 no
close tab (titles) inAppDrawn p50 36 43 46 38 10 +7 -8 no

Result: within run-to-run noise. No case counts. Closing a pane while titles stream is slower in both pairs (+68, +24), but main itself varied by 46 ms between its two runs, so it does not pass the rule.

The same check for D1a's close-pane case (main with the switch off vs on, at 34f0951, interleaved): close pane idle +25/+86 against a 130 ms switch-off spread, close pane with titles streaming +49/+37 against a 41 ms spread. Neither counts, so D1a's close-pane cost is also within run-to-run noise. The second pair's +37 sits just below the spread, so this case is the one to watch.

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

Code that runs with the switch off. The bundle diff compares this head with main at 70b2197; both were built from clean checkouts with the switch off and unminified, and cross-chunk import names were normalized. Preload is identical. The renderer differs in 3 chunks: the wait gate stub that returns false, the new store field's empty default, the deleted appear intents and queued-split code, one module moved between chunks, and the local split passing its folder object without copying it. Main differs in the items below:

  • The terminal.split request schema gains optional pane, newLeafId, cwd and initialSize. A request with a handle parses and fails exactly as before; a pane-named request is refused with host_not_owned. The window sends the pane-named form only to its own main process, so mixed-version peers are unaffected.
  • paneStartStatusArgs returns {}, so spawns take their existing path. The reworked start-in-pane function sets and clears a status only when given one, so with the switch off it starts the terminal exactly as before.
  • The e2e split helper now splits through the real split command in both builds (test code only).

SSH and paired servers: a tab main does not hold (a paired server's) is refused with host_not_owned and the window splits it as today. Folder workspaces take the same path as git worktrees.

Visible with the switch on, compared with the shipped build:

  • A failed agent, setup or split start (row 15). Shipped: the window retries the start in a tab or pane it makes. Switch on: the pane stays and shows "The terminal could not start: ".
  • A split while main's layout stream is down appears once the stream reopens.
  • A CLI split on a server with no window now works with the switch on. Before, it timed out because it waited for a window to start the pane.

Open owner question: a pane in starting shows nothing yet (no "starting" indicator), and this PR adds no UI for it. A start that hangs is bounded the same way in both builds. The terminal service's create request gives up after 30 s (about 90 s if the service is replaced meanwhile), and main's own starts go through the same request. With the switch off, the window's start fails and the pane shows the error toast. With the switch on, a window split's pane stays in starting until main's start fails at the same point, then shows the same error toast with "The terminal could not start: ". This was checked by reading the code and with the unit tests for a failed start; no live hung terminal service was run. The only unbounded waits are the folder checks before the terminal service is asked (folder-workspace-path-status.ts, spawn-cwd.ts), and both builds share them. A CLI split whose start fails leaves no pane, and the CLI hears why; that was already the switch-on behaviour before this PR. Ledger row L245.

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)

…yout-owner build)

A status-only frame changes one store entry and no pane tree, so the pane's view stays mounted.
…start shows why (layout-owner build)

Fixes owner-visible row 15: a failed agent or setup start no longer opens a plain shell.
These 8 have failed switch-on since #31130 moved the exit close to main.
…; the window attaches (layout-owner build)

The window's split, a startup split with its command, and a CLI split all go through main's
terminal.split; main's frame mounts the pane, with or without a window intent. Deletes the
window's split wait and withdraw, the split appear intents, and the queued-split skip and cancel.
The e2e helper uses the real split. A startup split leaves focus on its source pane.
…; a taken pane id is refused

Also restores the proof that a split closed while it starts gets one answer and leaves no
pane or start status behind.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

The change routes main-owned terminal splits through the main process and extends the split request contract to accept pane sources. It adds pane startup status tracking, defers renderer PTY attachment while startup is pending, and updates layout reconciliation and bootstrap splitting. It also changes split-pane exit handling and adds main-layout-owner detachment tests.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 5900f

With the main-owned layout switch enabled, a new pane can stay disconnected after main finishes starting it, the window can start its own terminal for an unbound pane, and concurrent splits can collide on one pane ID. Shipped builds are reported unchanged, but these issues should be resolved before the switch is relied on.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.65% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 68 functions across 56 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 summarizes the primary change: main starts splits and new panes while the window only attaches. It is specific and related to the changeset.
Description check Passed The description includes the required sections and gives detailed coverage of the behavior, rationale, testing, visual proof, compatibility, performance, and checklist status. The internal design work…
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 includes the required sections and gives detailed coverage of the behavior, rationale, testing, visual proof, compatibility, performance, and checklist status. The internal design work explains why no linked issue or visual proof is provided.

✨ 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: 2b561fa0-0912-475e-b31d-2940c32181b7
📥 Commits

Reviewing files that changed from the base of the PR and between ebc8b06 and 0abe700.

📒 Files selected for processing: 55
  • src/main/ipc/pty/pane/spawn-reservation.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-terminal-split-authority.test.ts
  • src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-05.spec.ts
  • src/main/runtime/rpc/methods/terminal/terminal-lifecycle-methods.ts
  • src/main/runtime/runtime-pane-admission.ts
  • src/main/runtime/terminal/launch/terminal-split-in-main.ts
  • src/main/runtime/terminal/launch/terminal-split-layout-owner.test.ts
  • src/main/runtime/terminal/launch/terminal-split-source-authority.ts
  • src/main/runtime/terminal/launch/terminal-split-surface.ts
  • src/main/runtime/terminal/launch/terminal-split.ts
  • src/main/runtime/terminal/lifecycle/exited-split-pane-rule.ts
  • src/renderer/src/components/terminal-pane/closed-terminal-leaf-notice-layout-owner.test.ts
  • src/renderer/src/components/terminal-pane/closed-terminal-leaf-notice.ts
  • src/renderer/src/components/terminal-pane/pty-connection-main-pane-start.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection-pty-exit-teardown.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-session-liveness.spec.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-exited-split-pane-close.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-store-fixtures.ts
  • src/renderer/src/components/terminal-pane/pty-connection-test-store-state.ts
  • src/renderer/src/components/terminal-pane/pty-connection/main-pane-start-wait.ts
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-in-main.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-in-main.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-record.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-record.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-frame-reconciliation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-frame-reconciliation.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-layout-restore.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-mount-bootstrap.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-mount-bootstrap.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-mount-events-layout-owner.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-in-main.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-in-main.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-request-routing.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-request-routing.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-with-inherited-cwd.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-with-inherited-cwd.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach-commit.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach-main-commit.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach-main-move.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach-main.test-fixture.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-mount-lifecycle.ts
  • src/renderer/src/runtime/layout-owner-pane-intents.test.ts
  • src/renderer/src/runtime/layout-owner-pane-intents.ts
  • src/renderer/src/runtime/workspace-layout-frame-binding.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-pane-starts.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/terminals/terminal-state.ts
  • src/shared/rpc-contract/terminal-unary-params.ts
  • tests/e2e/helpers/terminal-pane-operations.ts
  • tests/e2e/terminal-cli-split-closed-before-mount.spec.ts
💤 Files with no reviewable changes: 5
  • src/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-record.test.ts
  • src/main/ipc/pty/pane/spawn-reservation.ts
  • src/renderer/src/components/terminal-pane/closed-terminal-leaf-notice.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-record.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-split-request-routing.ts

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

Comment on lines +55 to +65
// Main's start ended: the pane is bound to its terminal now, or main took it back.
adoptMainBinding(session, state)
unsubscribe()
waiting.delete(session)
const index = session.waitTeardowns.indexOf(unsubscribe)
if (index !== -1) {
session.waitTeardowns.splice(index, 1)
}
if (!session.disposed) {
connect()
}

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

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C4 'runDeferredSessionAttach|startFreshSpawn' src/renderer/src/components/terminal-pane/pty-connection
rg -nP -C3 'showFramePaneStarts|showPaneTrees' src/renderer/src/runtime/workspace-layout-frame-sync.ts

Repository: stablyai/orca

Length of output: 21643


Do not connect when main’s start ends without a terminal binding.

When the gated status disappears, adoptMainBinding may find no terminal binding. The current code then still calls connect(), which can take the fresh-spawn path and start a second terminal for a pane that main already withdrew or closed.

Only unsubscribe and connect after adoptMainBinding succeeds. Otherwise, keep waiting for main’s binding or close notice.

Suggested fix
-    adoptMainBinding(session, state)
+    if (!adoptMainBinding(session, state)) {
+      return
+    }
     unsubscribe()

Make adoptMainBinding return false when ptyIdsByLeafId[leafId] has no binding, and return true after recording the binding.

@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: 64abe0bd-6f78-413a-9d83-f4e9fa4210de
📥 Commits

Reviewing files that changed from the base of the PR and between 0abe700 and f25aeb7.

📒 Files selected for processing: 10
  • src/main/runtime/pane-start-statuses.test.ts
  • src/main/runtime/runtime-pane-admission.ts
  • src/main/runtime/terminal/launch/terminal-split-in-main.ts
  • src/main/runtime/terminal/launch/terminal-split-layout-owner.test.ts
  • src/renderer/src/components/terminal-pane/fish-color-scheme-child-stdin.node-pty.test.ts
  • src/renderer/src/components/terminal-pane/remote-hidden-output-restore-outcomes.test.ts
  • src/renderer/src/components/terminal-pane/remote-hidden-output-restore-unavailable-banner.repro.test.ts
  • src/renderer/src/runtime/layout-owner-pane-intents.ts
  • src/renderer/src/runtime/workspace-layout-frame-bindings.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.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.

Comment on lines +90 to +93
// A named pane id another pane holds is refused: the start must not land in a live pane.
if (opts.newLeafId && this.holdsLeaf(source.worktreeId, leafId)) {
throw new Error('pane_exists')
}

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 | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Does split admission return 'exists' when newLeafId is already in the layout?
fd terminal-pane-admission.ts --exec sed -n '1,200p' {}
rg -nP -C5 "'exists'" --type=ts -g '*terminal-topology*'

Repository: stablyai/orca

Length of output: 9340


🏁 Script executed:

set -eu
printf '%s\n' '--- terminal-split-in-main.ts ---'
nl -ba src/main/runtime/terminal/launch/terminal-split-in-main.ts | sed -n '1,240p'
printf '%s\n' '--- runtime-pane-admission.ts ---'
nl -ba src/main/persistence/terminal-topology/runtime-pane-admission.ts | sed -n '1,240p'
printf '%s\n' '--- terminal-topology-commit.ts ---'
nl -ba src/main/persistence/terminal-topology/terminal-topology-commit.ts | sed -n '1,180p'
printf '%s\n' '--- spawnInAdmittedPane references ---'
rg -n -F -- 'spawnInAdmittedPane' src

Repository: stablyai/orca

Length of output: 17052


🏁 Script executed:

set -eu
printf '%s\n' '--- src/main/runtime/runtime-pane-admission.ts ---'
nl -ba src/main/runtime/runtime-pane-admission.ts | sed -n '1,240p'
printf '%s\n' '--- admission mutation references ---'
rg -n -F -- 'admitPane(' src/main | head -80
printf '%s\n' '--- store mutation implementation references ---'
rg -n -F -e 'terminal-topology' -e 'admitPane' src/main/runtime src/main/persistence | head -160

Repository: stablyai/orca

Length of output: 26257


🏁 Script executed:

set -eu
printf '%s\n' '--- terminal-split-surface.ts ---'
nl -ba src/main/runtime/terminal/launch/terminal-split-surface.ts | sed -n '35,125p'
printf '%s\n' '--- terminal-create.ts ---'
nl -ba src/main/runtime/terminal/launch/terminal-create.ts | sed -n '115,165p'
printf '%s\n' '--- runtime-pane-admission tests mentioning exists ---'
rg -n -C6 -F -- 'exists' src/main/runtime/*admission* src/main/runtime/terminal 2>/dev/null || true

Repository: stablyai/orca

Length of output: 34433


Reject an existing pane before spawning a named split.

holdsLeaf runs before an await, so concurrent requests with the same newLeafId can pass the fast check. Admission returns 'exists' for the later request, but spawnInAdmittedPane still calls controller.spawn!(spawnArgs). This can start two PTYs for one pane key.

Keep the existing 'exists' behavior for other callers. Reject it only for caller-named splits.

🐛 Suggested fix
 export type PaneStartArgs = { startStatus?: { sink: PaneStartStatusSink; keepOnFailure: boolean } }
+  & { rejectExisting?: boolean }
...
 export async function spawnInAdmittedPane(
   store: RuntimeStore | null | undefined,
   controller: Pick<RuntimePtyController, 'spawn'>,
-  { startStatus, ...args }: AdmittedSpawnArgs & PaneStartArgs
+  { startStatus, rejectExisting, ...args }: AdmittedSpawnArgs & PaneStartArgs
 ): ReturnType<Spawn> {
...
       hostIdOf(args),
       async (admitted) => {
+        if (admitted === 'exists' && rejectExisting) {
+          throw new Error('pane_exists')
+        }
         if (admitted !== undefined && admitted !== 'admitted' && admitted !== 'exists') {
       ...this.paneStartStatusArgs(
         opts.keepPaneOnStartFailure ? { keepPaneOnStartFailure: true } : {}
       )
+      rejectExisting: Boolean(opts.newLeafId && isTerminalLeafId(opts.newLeafId)),
     })

@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: 7c1605c8-9788-42ad-9729-c29dd83c6ad4
📥 Commits

Reviewing files that changed from the base of the PR and between db46bc2 and 5900fc4.

📒 Files selected for processing: 1
  • src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.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.

Comment on lines +137 to +140
session.cancelScheduledConnectFrame()
if (session.connectFallbackTimer !== null) {
clearTimeout(session.connectFallbackTimer)
session.connectFallbackTimer = 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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,200p' src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
sed -n '1,140p' src/renderer/src/components/terminal-pane/pty-connection/main-pane-start-wait.ts
rg -n 'connectFallbackTimer|runDeferredConnect|cancelScheduledConnectFrame|scheduleConnect' src/renderer/src/components/terminal-pane

Repository: stablyai/orca

Length of output: 16955


🏁 Script executed:

sed -n '200,245p' src/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.ts
sed -n '165,215p' src/renderer/src/components/terminal-pane/pty-connection/pty-resize-geometry.ts
sed -n '35,85p' src/renderer/src/components/terminal-pane/pty-connection/connect-pane-pty.ts
rg -n -F --glob '*.ts' -e 'installRunDeferredConnect' -e 'scheduleConnect' -e 'connectFallbackTimer =' -e 'runDeferredConnect()' src/renderer/src/components/terminal-pane/pty-connection

Repository: stablyai/orca

Length of output: 7301


Re-arm the fallback timer when main startup ends.

waitsForMainPaneStart() invokes session.runDeferredConnect() directly. After the wait branch clears connectFallbackTimer, a failed safeFit() schedules only requestAnimationFrame. If requestAnimationFrame is starved, the pane has no further connection attempt.

Do not only remove the timer cleanup. If the timer fires during the wait, it sets deadlinePassed, and the wake call can then bypass the safeFit() retry. Re-arm the fallback timer with the wake scheduling path instead.

@Jinwoo-H
Jinwoo-H merged commit ce71535 into main Oct 21, 2026
53 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