Repository navigation
fix(terminal): a slow window no longer makes orca terminal create fail and then duplicate - #28158
Conversation
…w window cannot duplicate them A focused or interactive-agent `orca terminal create` asked the window to make the terminal and reported failure after 10 s, while the window still made it later; a retry then made a second one. Main now starts every terminal that names a workspace and shows it in the window best-effort, as it already did for every other create.
|
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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
|
e2e results for head 66ba624 (base 4d1001f):
|
…ed pane size An unfocused CLI agent opens as an inactive tab that is not resized until the user opens it, so starting it at 120x40 left its output wrapped to 120 columns. Start it at the size of the pane active in the worktree's active group, where the new tab opens; fall back to 120x40 only when that worktree has no measured pane.
Hosts without #22384 leave a background-started agent's startup queries unanswered, so a new CLI talking to an old, still-running host must keep routing interactive agents to the window. Newer hosts ignore the flag.
…heir tab group The window publishes, on its graph sync to main only, the grid an unsplit terminal would get in each shown tab group, computed by one pure function that mirrors FitAddon.proposeDimensions and is pinned against it; a ResizeObserver on each group body republishes when that grid changes. Main starts a new terminal at the size of the group it opens in (the named group, else the active one) and falls back to 120x40 only when no window measured it. This replaces the active-pane lookup, which mis-sized split groups and could read a phone's fitted size.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/runtime/sync-runtime-graph.ts (1)
73-90: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueGrid-size observer can republish repeatedly while the last sync is unacknowledged or fails.
publishedTerminalGroupGridSizesKeyis set only aftersyncWindowGraphresolves (seegraph-publication.tsLine 199). During an in-flight sync or after a failed sync, everyResizeObservercallback sees a key mismatch and callsscheduleRuntimeGraphSync. During a window drag, this schedules a coalesced sync per resize burst. Each sync rebuilds the full graph. The cost is bounded by the coalesce timer and the in-flight flag, so the impact is small. Consider caching the measured key at call time to skip duplicates.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
732e8fc9-60dc-426d-8f35-bd607d3453fe
📒 Files selected for processing (13)
src/cli/handlers/terminal.tssrc/main/runtime/orca-runtime-create-terminal.tssrc/main/runtime/orca-runtime-sync-window-graph.tssrc/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-04.spec.tssrc/renderer/src/components/tab-group/TabGroupPanel.tsxsrc/renderer/src/lib/pane-manager/terminal-grid-size-for-box.test.tssrc/renderer/src/lib/pane-manager/terminal-grid-size-for-box.tssrc/renderer/src/runtime/sync-runtime-graph-terminal-group-grid-sizes.test.tssrc/renderer/src/runtime/sync-runtime-graph.tssrc/renderer/src/runtime/sync-runtime-graph/graph-publication.tssrc/renderer/src/runtime/sync-runtime-graph/graph-state.tssrc/renderer/src/runtime/sync-runtime-graph/terminal-group-grid-sizes.tssrc/shared/runtime-session-contracts.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/cli/handlers/terminal.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| if (graph.terminalGroupGridSizes) { | ||
| // Merged, not replaced: a group in a worktree the window is not showing keeps its last size. | ||
| this.terminalGroupGridSizes = { | ||
| ...this.terminalGroupGridSizes, | ||
| ...graph.terminalGroupGridSizes | ||
| } | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '60,90p' src/main/runtime/orca-runtime-sync-window-graph.ts
sed -n '20,75p' src/main/runtime/orca-runtime-create-terminal.ts
sed -n '115,140p' src/main/runtime/orca-runtime-create-terminal.ts
rg -n -m 8 'syncWindowGraph' src/main/runtime/rpc src/main/ipcRepository: stablyai/orca
Length of output: 7536
🏁 Script executed:
set -e
printf '%s\n' '--- IPC registration ---'
nl -ba src/main/ipc/runtime.ts | sed -n '1,75p'
printf '%s\n' '--- graph contract and size declarations ---'
rg -n -F --glob '*.ts' -e 'terminalGroupGridSizes' -e 'interface WindowGraph' -e 'type WindowGraph' -e 'syncWindowGraph' src/main src/shared src/renderer 2>/dev/null || true
printf '%s\n' '--- create-terminal relevant declarations and calls ---'
nl -ba src/main/runtime/orca-runtime-create-terminal.ts | sed -n '1,210p'
printf '%s\n' '--- PTY controller/admission definitions ---'
rg -n -F --glob '*.ts' -e 'adoptStablePane' -e 'spawnInAdmittedPane' -e 'RuntimePtyController' src/main src/shared 2>/dev/null || trueRepository: stablyai/orca
Length of output: 41653
🏁 Script executed:
set -e
printf '%s\n' '--- graph type ---'
nl -ba src/shared/runtime-session-contracts.ts | sed -n '145,180p'
rg -n -F --glob '*.ts' -e 'RuntimeRendererSyncWindowGraph' src/shared src/main | head -20
printf '%s\n' '--- runtime PTY contract ---'
nl -ba src/main/runtime/runtime-pty-controller-contract.ts | sed -n '1,85p'
printf '%s\n' '--- pane admission ---'
nl -ba src/main/runtime/runtime-pane-admission.ts | sed -n '1,125p'
printf '%s\n' '--- stable-pane adoption ---'
nl -ba src/main/ipc/pty/pane/adopt-stable.ts | sed -n '1,125p'
printf '%s\n' '--- size validation in relevant PTY/runtime code ---'
rg -n -S --glob '*.ts' '(Number\\.is(Integer|Finite)|cols\\s*[<>]=?|rows\\s*[<>]=?|validate.*(cols|rows)|(cols|rows).*validate)' src/main/ipc/pty src/main/runtime | head -120Repository: stablyai/orca
Length of output: 13617
🏁 Script executed:
set -e
printf '%s\n' '--- stable-pane owner attachment ---'
rg -n -F --glob '*.ts' -e 'function attachStablePaneOwner' -e 'const attachStablePaneOwner' src/main/ipc/pty
nl -ba src/main/ipc/pty/pane/stable-owner.ts | sed -n '1,180p'
printf '%s\n' '--- concrete PTY controller spawn ---'
nl -ba src/main/ipc/pty/runtime/controller.ts | sed -n '1,150p'
printf '%s\n' '--- provider spawn bindings ---'
rg -n -S --glob '*.ts' 'spawn\\s*\\(|spawnPty|cols|rows' src/main/ipc/pty/runtime src/main/providers/pty-provider* src/main/providers | head -180Repository: stablyai/orca
Length of output: 14417
🏁 Script executed:
set -e
printf '%s\n' '--- stable-pane attachment body ---'
nl -ba src/main/ipc/pty/pane/stable-owner.ts | sed -n '172,300p'
printf '%s\n' '--- runtime spawn implementation ---'
nl -ba src/main/ipc/pty/runtime/spawn.ts | sed -n '1,220p'
printf '%s\n' '--- provider contract and concrete spawn definitions ---'
rg -n -F --glob '*.ts' -e 'export type PtySpawnOptions' -e 'export interface IPtyProvider' -e 'spawn(opts' -e 'spawn(options' -e 'spawnPty' src/main/providers src/main/ipc/pty | head -160Repository: stablyai/orca
Length of output: 12127
🏁 Script executed:
set -e
printf '%s\n' '--- provider spawn contract ---'
nl -ba src/main/providers/pty-provider-contract.ts | sed -n '40,155p'
printf '%s\n' '--- runtime spawn option construction ---'
nl -ba src/main/ipc/pty/runtime/spawn-options.ts | sed -n '1,220p'
printf '%s\n' '--- runtime spawn execution ---'
nl -ba src/main/ipc/pty/runtime/spawn-execute.ts | sed -n '1,180p'Repository: stablyai/orca
Length of output: 28086
Validate renderer-supplied PTY dimensions before merging.
The IPC handler does not validate terminalGroupGridSizes. Invalid or extreme cols and rows can reach both stable-pane adoption and the PTY provider. Filter entries to finite integers in a bounded range before storing them.
🐛 Suggested fix
--- "a/src/main/runtime/orca-runtime-sync-window-graph.ts"
+++ "b/src/main/runtime/orca-runtime-sync-window-graph.ts"
@@ -70,13 +70,23 @@
this.rendererGeneration = null
}
if (graph.terminalGroupGridSizes) {
// Merged, not replaced: a group in a worktree the window is not showing keeps its last size.
- this.terminalGroupGridSizes = {
- ...this.terminalGroupGridSizes,
- ...graph.terminalGroupGridSizes
+ const valid = Object.create(null) as Record<string, { cols: number; rows: number }>
+ for (const [groupId, size] of Object.entries(graph.terminalGroupGridSizes)) {
+ if (
+ Number.isInteger(size?.cols) &&
+ Number.isInteger(size?.rows) &&
+ size.cols >= 1 &&
+ size.cols <= 1000 &&
+ size.rows >= 1 &&
+ size.rows <= 1000
+ ) {
+ valid[groupId] = { cols: size.cols, rows: size.rows }
+ }
}
+ this.terminalGroupGridSizes = { ...this.terminalGroupGridSizes, ...valid }
}
const graphWasReady = this.graphStatus === 'ready'
const previousTabs = this.tabs
const previousLeaves = this.leaves📝 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.
| if (graph.terminalGroupGridSizes) { | |
| // Merged, not replaced: a group in a worktree the window is not showing keeps its last size. | |
| this.terminalGroupGridSizes = { | |
| ...this.terminalGroupGridSizes, | |
| ...graph.terminalGroupGridSizes | |
| } | |
| } | |
| if (graph.terminalGroupGridSizes) { | |
| // Merged, not replaced: a group in a worktree the window is not showing keeps its last size. | |
| const valid = Object.create(null) as Record<string, { cols: number; rows: number }> | |
| for (const [groupId, size] of Object.entries(graph.terminalGroupGridSizes)) { | |
| if ( | |
| Number.isInteger(size?.cols) && | |
| Number.isInteger(size?.rows) && | |
| size.cols >= 1 && | |
| size.cols <= 1000 && | |
| size.rows >= 1 && | |
| size.rows <= 1000 | |
| ) { | |
| valid[groupId] = { cols: size.cols, rows: size.rows } | |
| } | |
| } | |
| this.terminalGroupGridSizes = { ...this.terminalGroupGridSizes, ...valid } | |
| } |
… and use the live active group A pane with a title or banner pushes its xterm host down, which skewed every group's row count; skip it like a zoomed pane. Size from the window's latest published active group, which is where its reveal places the tab, before the saved session's.
|
e2e results for head 4624292 (base 4d1001f):
|
Co-Authored-By: Claude <[email protected]>
… the content area Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
|
CI for 91288a4 (code head; eaa2a7b and bedc0ad are empty commits that refresh the merge with main after #28297 and #28301 fixed a main-side replay test):
|
ELI5
When you ran
orca terminal create --focus, or created a terminal that runs an interactive coding agent, Orca asked the window to make the terminal and gave the window 10 seconds. If the window was slow, the command said "failed" — but the window still made the terminal a moment later. Running the command again then gave you two terminals. Now Orca's background process starts the terminal itself and only asks the window to show it, so a slow window can only delay showing the tab, never turn a success into a failure.What Changed
Before (as a user sees it): with a busy or slow window,
orca terminal create --worktree <wt> --focus(or with--commandnaming an interactive coding agent) printedTerminal creation timed out, then the tab appeared anyway. A retry made a duplicate.After: the command prints the new terminal's handle as soon as the terminal is running. If the window has not shown it within 10 s, the reply carries the existing warning ("Terminal … is running, but Orca could not make it discoverable … run
orca terminal focus") instead of an error, and nothing runs twice.Size of a new terminal: a terminal started in Orca's background process now starts at the size of the tab group it will open in: the group the caller named, else the workspace's active group. The window measures that size and reports it to Orca's background process; when the tab is opened, the window fits it to its pane as before. Before this PR, every such terminal started at a fixed 120x40 (from #1707, May 2026) and was only resized when its tab was opened, so an agent that draws at startup kept output wrapped to the wrong width. That also applies to creates that were already started in the background on main, such as orchestration workers and agent launches: they now start at the group's real size too. A workspace not shown since Orca started has no group on screen to measure; if its saved layout has at most one group, the terminal starts at the size a single-group workspace gets, since every workspace shares the same content area. It still starts at 120x40 when there is no measurement to use: no window at all (a remote
orca serveor orcad host, as on main today), a workspace with two or more groups not shown since Orca started, or no terminal pane at the default font size mounted yet.How the size is measured: for each tab group on screen, the window computes the terminal grid an unsplit terminal would get there, using one small function that mirrors the terminal library's own fit calculation (pinned by a test against that library's result). It reads the cell size from any mounted pane at the default font size with no title strip or banner. It also sends the grid for a single-group workspace: the content area minus the space a lone group's tab row and border take, measured once on any shown single-group workspace (only group bodies inside the content area count, so the floating terminal panel and hidden workspaces do not). It sends the results on its existing window-to-main graph update, and sends it again when a group's grid changes (a resize observer on each group). The field is a separate part of that window-to-main update: it is never copied into the tab list that phones and paired clients receive, and the web client never sends it.
Mechanism:
createTerminalhad two paths. One (used by phones, orchestration workers, agent launches and plain CLI creates) starts the terminal in Orca's background process and then asks the window to show it, best-effort. The other asked the window to create and start the terminal, and gave up after 10 s with no way to cancel the request. That second path was taken for any focused create and for CLI creates flaggedrendererBacked(interactive coding-agent commands). Now every create that names a workspace takes the first path; the window-made path remains only for a create with no workspace, which lands in whatever workspace the window shows and so needs the window.Removed with it:
rendererBacked. The host has to stop honouring it, because that flag is exactly what sent interactive-agent creates down the window-made path. The CLI keeps sending it, as isolated compatibility code: hosts before v1.4.211 (fix(runtime): answer startup terminal queries for background-created terminals #22384) don't reply to a background-started agent's startup questions, so a new CLI talking to such a host (for example an app updated on disk but not yet restarted) still needs that host to start the agent in the window. Delete the CLI side once those hosts can no longer run alongside this CLI.Why
The alternative was to make the window acknowledge each request and let the background process cancel one that timed out. That is a new request/ack/cancel protocol between the background process and the window. The "start here, show best-effort" path already exists, is what every other caller uses, and has no request that can time out and still complete — so the duplicate cannot happen by construction.
The window-made path for these creates came from two older rules:
rendererBacked(Fix Codex terminal orchestration #2039, Fix CLI-launched agent terminal viewport #2561, May 2026): an interactive agent had to be "born in a renderer-backed terminal" because a terminal started in the background then could not reply to the agent's startup questions and started at the wrong size. Since fix(runtime): answer startup terminal queries for background-created terminals #22384 (v1.4.211) the background process replies to the agent's startup questions (cursor position, device type, colours), and this PR starts the terminal at a measured size (see "Size of a new terminal"). Orchestration workers and agent launches already start the same agents this way every day.activate/presentation: 'focused'on the reveal), which headless hosts already relied on.The 10 s give-up itself was added in #734 (CLI terminal create) and is kept for the no-workspace path, where the window really is the only one who can make the terminal.
Linked Issue
N/A (internal legacy-rule cleanup, rule 7).
Visual Proof
Real app, windows hidden, two tab groups with the active one split in two, then
orca terminal create --command <agent>without--focus, then open the new tab. The agent prints its starting size and draws a box and ruler as wide as its terminal:The new tab landed in the active (second) group in both builds; the window's own placement decides that.
Second probe: the same command into a new workspace that was never shown since Orca started (its groups are not on screen), then switch to it and open the tab:
Testing
New test
reports the running CLI terminal, not a failure, when the window is slow(terminal-creation-and-readiness-part-04.spec.ts), driven through the realterminal.createRPC with the two parameter shapes the CLI sends (--focus, and an interactive agent withrendererBacked). On main both cases fail withTerminal creation timed outafter the window was sentterminal:requestTabCreate; on this branch both return the running terminal with the reveal warning, spawn once, and never ask the window to create.New tests:
terminalGridSizeForBoxmatches the terminal library's fit result for five shapes; the group measurement skips zoomed and titled panes and leaves the field out when nothing is measurable; the window republishes only when a group grid changes; main uses the named group, else the window's latest active group, else the single-group size for a workspace with at most one saved group, else 120x40; a measured group beats the single-group size; the single-group size is learned only from a lone body inside the content area (a floating-panel body and a hidden body are ignored).pnpm vitest runoversrc/main/runtimeandsrc/cli(1297 files) pass;pnpm tc, oxlint andcheck:code-quality:changedpass.Full e2e suite on this head and on main at the same base, plus the layout-oracle and CLI terminal specs: no failure that only happens on this head reproduces on re-run (details in the comment below).
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
rendererBacked, and paired clients were already forced to background creates; SSH workspaces take the same background start as before.rendererBacked, which this host accepts and ignores, and which an older host (before v1.4.211) still routes on, so an old host keeps starting interactive agents in the window as it did. An older CLI against this host gets the background start.terminalModelQueryAuthorityorterminalHiddenDeliveryGateturned off, a focused agent started this way gets no startup replies (before, a focused create was started by the window, which replied itself).preAllocatedHandleand the spawn-commit callback that the window-made path dropped.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)