Repository navigation
Layout groundwork (switched off): main starts every split and new pane, the window only attaches - #31258
Conversation
…yout-owner build) A status-only frame changes one store entry and no pane tree, so the pane's view stays mounted.
…t is written (layout-owner build)
…start shows why (layout-owner build) Fixes owner-visible row 15: a failed agent or setup start no longer opens a plain shell.
…ontact (layout-owner build)
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.
…d panes to their restore path
…; 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.
… failed, with why
|
Note Reviews pausedIt 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
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2b561fa0-0912-475e-b31d-2940c32181b7
📒 Files selected for processing: 55
src/main/ipc/pty/pane/spawn-reservation.tssrc/main/runtime/orca-runtime-exited-split-pane-close.test.tssrc/main/runtime/orca-runtime-failed-start-pane-layout-owner.test.tssrc/main/runtime/orca-runtime-terminal-split-authority.test.tssrc/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-05.spec.tssrc/main/runtime/rpc/methods/terminal/terminal-lifecycle-methods.tssrc/main/runtime/runtime-pane-admission.tssrc/main/runtime/terminal/launch/terminal-split-in-main.tssrc/main/runtime/terminal/launch/terminal-split-layout-owner.test.tssrc/main/runtime/terminal/launch/terminal-split-source-authority.tssrc/main/runtime/terminal/launch/terminal-split-surface.tssrc/main/runtime/terminal/launch/terminal-split.tssrc/main/runtime/terminal/lifecycle/exited-split-pane-rule.tssrc/renderer/src/components/terminal-pane/closed-terminal-leaf-notice-layout-owner.test.tssrc/renderer/src/components/terminal-pane/closed-terminal-leaf-notice.tssrc/renderer/src/components/terminal-pane/pty-connection-main-pane-start.test.tssrc/renderer/src/components/terminal-pane/pty-connection-pty-exit-teardown.spec.tssrc/renderer/src/components/terminal-pane/pty-connection-session-liveness.spec.tssrc/renderer/src/components/terminal-pane/pty-connection-test-exited-split-pane-close.tssrc/renderer/src/components/terminal-pane/pty-connection-test-store-fixtures.tssrc/renderer/src/components/terminal-pane/pty-connection-test-store-state.tssrc/renderer/src/components/terminal-pane/pty-connection/main-pane-start-wait.tssrc/renderer/src/components/terminal-pane/pty-connection/run-deferred-connect.tssrc/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-in-main.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-in-main.tssrc/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-record.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-bootstrap-split-record.tssrc/renderer/src/components/terminal-pane/terminal-pane-frame-reconciliation.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-frame-reconciliation.tssrc/renderer/src/components/terminal-pane/terminal-pane-layout-restore.tssrc/renderer/src/components/terminal-pane/terminal-pane-mount-bootstrap.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-mount-bootstrap.tssrc/renderer/src/components/terminal-pane/terminal-pane-mount-events-layout-owner.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-split-in-main.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-split-in-main.tssrc/renderer/src/components/terminal-pane/terminal-pane-split-request-routing.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-split-request-routing.tssrc/renderer/src/components/terminal-pane/terminal-pane-split-with-inherited-cwd.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-split-with-inherited-cwd.tssrc/renderer/src/components/terminal-pane/terminal-pane-tab-detach-commit.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-tab-detach-main-commit.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-tab-detach-main-move.test.tssrc/renderer/src/components/terminal-pane/terminal-pane-tab-detach-main.test-fixture.tssrc/renderer/src/components/terminal-pane/terminal-pane-tab-detach.test.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-mount-lifecycle.tssrc/renderer/src/runtime/layout-owner-pane-intents.test.tssrc/renderer/src/runtime/layout-owner-pane-intents.tssrc/renderer/src/runtime/workspace-layout-frame-binding.test.tssrc/renderer/src/runtime/workspace-layout-frame-pane-starts.tssrc/renderer/src/runtime/workspace-layout-frame-sync.tssrc/renderer/src/store/slices/terminals.tssrc/renderer/src/store/terminals/terminal-state.tssrc/shared/rpc-contract/terminal-unary-params.tstests/e2e/helpers/terminal-pane-operations.tstests/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.
| // 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() | ||
| } |
There was a problem hiding this comment.
🩺 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.tsRepository: 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.
…r, clear a gone pane's status Three test stores gain the pane-start field the window's store always has.
…written; a closed pane's failed start clears
… call in the bindings module
… its failed status
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
64abe0bd-6f78-413a-9d83-f4e9fa4210de
📒 Files selected for processing: 10
src/main/runtime/pane-start-statuses.test.tssrc/main/runtime/runtime-pane-admission.tssrc/main/runtime/terminal/launch/terminal-split-in-main.tssrc/main/runtime/terminal/launch/terminal-split-layout-owner.test.tssrc/renderer/src/components/terminal-pane/fish-color-scheme-child-stdin.node-pty.test.tssrc/renderer/src/components/terminal-pane/remote-hidden-output-restore-outcomes.test.tssrc/renderer/src/components/terminal-pane/remote-hidden-output-restore-unavailable-banner.repro.test.tssrc/renderer/src/runtime/layout-owner-pane-intents.tssrc/renderer/src/runtime/workspace-layout-frame-bindings.tssrc/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.
| // 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') | ||
| } |
There was a problem hiding this comment.
🗄️ 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' srcRepository: 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 -160Repository: 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 || trueRepository: 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)),
})…bs without a window's report
… a lost owner race shows no failure; a split no one asked to see keeps the phones' tab
…window attaches to the winner
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7c1605c8-9788-42ad-9729-c29dd83c6ad4
📒 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.
| session.cancelScheduledConnectFrame() | ||
| if (session.connectFallbackTimer !== null) { | ||
| clearTimeout(session.connectFallbackTimer) | ||
| session.connectFallbackTimer = null |
There was a problem hiding this comment.
🩺 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-paneRepository: 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-connectionRepository: 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.
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:starting,failed, and from C1bsleeping,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.startingbefore 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.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.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.splitkeeps 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.startingbefore 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.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.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) andterminal-pane-tab-detach-commit(8): stale; main mints the moved tab's id. Their switch-on twins interminal-pane-tab-detach-main-move.test.tsandterminal-pane-tab-detach-main-commit.test.tsassert the command the window sends and the store after main's frame.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:hasPtyreturns 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 e2eplusbuild: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.createTerminalreturnsterminal_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 atsession.tabs.createTerminalwith the sameterminal_handle_stale. Running this spec also found that a split main starts was missing fromsession.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:
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)
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
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:terminal.splitrequest schema gains optionalpane,newLeafId,cwdandinitialSize. A request with a handle parses and fails exactly as before; a pane-named request is refused withhost_not_owned. The window sends the pane-named form only to its own main process, so mixed-version peers are unaffected.paneStartStatusArgsreturns{}, 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.SSH and paired servers: a tab main does not hold (a paired server's) is refused with
host_not_ownedand 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:
Open owner question: a pane in
startingshows 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 instartinguntil 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)