Skip to content

Layout-owner build: a CLI send, wait or read starts a saved pane that has no terminal yet (dark) - #31307

Merged
Jinwoo-H merged 70 commits into
mainfrom
fd/a1c-cli-restored-pane-start
Oct 21, 2026
Merged

Jinwoo-H merged 70 commits into
mainfrom
fd/a1c-cli-restored-pane-start

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

ELI5

After a restart, a saved terminal pane may not have its terminal running yet. Phones already start such a pane when they open it. In the new layout build (switched off in every shipped build), this PR does the same for a command-line or orchestration send, wait or read aimed at that pane, instead of failing with "not writable".

What Changed

Everything is behind the ORCA_LAYOUT_OWNER build switch, which is off in shipped builds. Switch-off behaviour is unchanged.

With the switch on, for a pane in a workspace main owns (local or SSH; paired-server workspaces still mirror their server):

  • Before / after: orca terminal send|wait|read (and orchestration message delivery) on a saved pane that has no terminal yet used to fail (terminal_not_writable, or an empty read). Now it starts the pane through main's one starter (ensureRestoredPaneStarted, the one phones use), then delivers, waits or reads on the started terminal.
  • Concurrent triggers (a phone opening the pane while a CLI send arrives) share the starter's single start.
  • A pane that cannot start fails the call with the start's error. A start that never finishes fails the call with runtime_timeout after the pending-terminal create bound (MOBILE_TERMINAL_SURFACE_TIMEOUT_MS, 10 s), for every entry point including a read and a tui-idle wait with no timeout. The caller's abort signal and a shorter wait deadline (timeout) also apply, and a wait keeps only the deadline the start left.
  • Replies keep the caller's handle. Until main's layout records the new binding, the call acts on the started terminal's own handle; once it lands, the caller's handle adopts the terminal through the existing first-terminal adoption (adoptFirstPtyForLeafHandle), so an open wait is not invalidated.

Mechanism: one new class layer, restored-handle-pane-start.ts (startRestoredHandlePane), called at the top of sendTerminal, sendTerminalAgentPrompt, readTerminal and waitForTerminal.

Why

The final design's restore starter (C1b) gave main one start for every trigger except the window's own restore; phones were wired, CLI and orchestration were not. Calling the existing starter from the four runtime entry points covers the RPC, the stream input path, plugins and orchestration in one place. Rewriting the caller's handle to point at the new terminal was considered and rejected: it is deleted when the pane's binding lands, which would fail open waits.

Linked Issue

Part of the terminal layout final design (A1 follow-up: CLI wiring for the C1b restore starter). Ledger L237 note.

Visual Proof

N/A: no change in shipped builds (the switch is off).

Testing

  • restored-pane-start-cli-handles.test.ts (switch on, windowless host, a saved pane with no terminal): a send starts the pane once and delivers, and a second send on the same handle reaches the same terminal; a terminal.send request does the same; a wait and a read do the same; a CLI send and a phone opening the pane together start it once; a failed start fails the send with its error; a wait survives main binding the pane later and answers under the caller's handle; a wait's timeout covers a start that never finishes; a read, and a tui-idle wait with no timeout, on a start that never finishes fail with runtime_timeout at the 10 s bound (fake timers).

  • Gates: ci-static-gate passes. Switch-on src/main/runtime + src/main/persistence in clean worktrees, main c335070 vs this head: 11 vs 11 failing, none fails only at this head. Only a handle whose saved pane needs a start goes async; every other send, wait and read keeps today's synchronous path, so existing wait-timing tests are unchanged.

  • I manually tested these changes locally

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

AI Disclosure

Review

Reviews:

  • Opus round 1 (34b5082): one blocker, the caller's handle was rewritten to name the started terminal, which the pane's later bind deleted, failing an open wait as stale; fixed by acting on the started terminal's own handle and letting the caller's handle adopt it through the existing first-terminal adoption. Also fixed: the start ignored the caller's abort and wait deadline; the terminal.send handler change altered some refusal replies (removed, that file is now unchanged).
  • Opus delta round (6ca700b): nothing blocking. Fixed: timer/listener cleanup on first settle, the wait deadline counted twice, weak late-bind and concurrent-trigger assertions. Its start-to-bind double start is fixed in the starter by C1c.
  • After the coordinator's ask, every start is capped at the create bound (runtime_timeout), and the switch-on comparison then caught all waits going async (5 timing tests); fixed so only a call that needs a start goes async.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Wire: no new fields; replies keep today's shapes and the caller's handle.
  • SSH: SSH panes main owns start through the same starter; paired-server (runtime:<env>) workspaces are not owned and keep today's path.
  • Performance: one handle lookup per call when the switch is on; nothing when off.
  • Switch-off bundle (unminified main, base c335070 vs this head): the only differences are the new OrcaRuntimeWithRestoredHandlePaneStart class in the runtime class chain (its method folds to return handle and nothing calls it with the switch off) and, at the four entry points, const target = handle; if (target !== handle) ..., a branch that can never run, so switch-off behaviour is identical. The renderer manifest differs only in entry order.
  • Reuse: the start is main's existing starter (ensureRestoredPaneStarted), and the handle hand-off uses the existing first-terminal adoption; no new state.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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

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

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

A paired host starts each pane of a client's tab as a create under the tab's id, so a held tab
id is refused only for a client's own layout command.
Only a requested stop or a host-confirmed death closes a pane on a negative exit code. Pins that
the closed-tab guard never fires in the shipped build.
…itions hold, the fence reads ownership once, a legacy pane keeps its claim; switch-on tests assert main's answers after a window closes (dark)
…ged to its own module, for the file's line cap
… does, re-reading routing only on a write or a terminal registration; a worktree stop names every terminal main binds; a starting pane is unverifiable (dark)
…ng live; a resuming pane is unverifiable like a starting one (dark)
…rts; terminal.send starts it before its checks (switch-on builds only)
…he pane; bound the start by the caller's abort and wait deadline (switch-on builds only)
…dline and cleans its bounds on first settle; tighter A1c tests
…al create bound for every CLI entry point (runtime_timeout)
…; every other send, wait and read stays synchronous as before
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c78ef48c-4d85-4db7-a3d9-aef82f87d012
📥 Commits

Reviewing files that changed from the base of the PR and between ecee346 and 7ac7f03.

📒 Files selected for processing: 5
  • src/main/runtime/restored-pane-start-cli-handles.test.ts
  • src/main/runtime/terminal/input/terminal-agent-prompt-render.ts
  • src/main/runtime/terminal/input/terminal-input-dispatch.ts
  • src/main/runtime/terminal/recovery/resolve-terminal-pane.ts
  • src/main/runtime/terminal/surface/restored-handle-pane-start.ts

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

📝 Walkthrough

The runtime now starts eligible main-owned restored panes before terminal sends, agent prompts, waits, and reads continue. Startup returns a target terminal handle while operations preserve the caller’s handle. Caller-facing startup can end with a timeout, an abort error, or the mobile startup timeout. Tests cover CLI and RPC sends, reads, waits, shared startup, late binding, and startup failures.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 7ac7f

The change starts saved panes that have no terminal when a CLI send, wait or read targets them. It only takes effect when the layout-owner flag is enabled, which shipped builds leave off. No blocking issue was found.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: CLI send, wait, and read operations start saved panes that do not yet have a terminal in the layout-owner build.
Description check Passed The description is complete and directly aligned with the template. It explains the user impact, implementation, rationale, testing, compatibility considerations, visual-proof status, and checklist co…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and directly aligned with the template. It explains the user impact, implementation, rationale, testing, compatibility considerations, visual-proof status, and checklist completion.

✨ Finishing Touches
📝 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.

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