Skip to content

fix(runtime): a server with no window answers its first terminal create, not 'handle stale' (switch-on builds only) - #31391

Merged
Jinwoo-H merged 5 commits into
mainfrom
fd/headless-create-handle-stale
Oct 21, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
fd/headless-create-handle-stale

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​45

ELI5

In the new layout build (switched off in every shipped build), a server with no window open (orca serve) failed the first terminal a phone or paired desktop created on it: the terminal started, but the create answered "terminal handle stale". This PR makes the create answer with the running terminal.

What Changed

Behind the ORCA_LAYOUT_OWNER build switch, off in shipped builds; switch-off behaviour is unchanged.

  • Before: on a switch-on server with no window, session.tabs.createTerminal (and the other runtime-owned creates) threw terminal_handle_stale though its terminal was running. Paired-desktop and phone flows on such a server broke at their first create.
  • After: the create answers with the running terminal under the handle it was created with, and later calls on that handle (split, send, read, close) work as they did before Layout-owner build: main answers terminal questions from its own layout (A1, dark) #31187 on a server with no window.
  • Mechanism: since A1 (Layout-owner build: main answers terminal questions from its own layout (A1, dark) #31187), main lists its own panes even with no window and republishes when a new terminal's pane binding lands. The new pane then adopts the terminal's own (pre-allocated) handle, which turns that handle's record into a pane record. getLivePtyForHandle only took runtime terminal records, so the create found nothing, and a split on the handle took the pane path, which waits for a window to start the pane and timed out. Now, with the switch on and no window (the graph authority is the headless runtime, also after a window closed), getLivePtyForHandle also accepts the terminal's own handle when the pane main's layout binds that terminal adopted it: the same answer that handle gave before Layout-owner build: main answers terminal questions from its own layout (A1, dark) #31187, when no window meant no panes.
  • With a window, nothing changes: the adopted handle is the pane's, as a window graph's adoption made it before.

Why

Fixed where the miss happens, in the one lookup every caller uses, and limited to what changed in #31187 (no window, main's own panes), so it restores the old answer instead of inventing a new one. Alternatives tried: accepting any pane handle main binds changed windowed replies (A1's cross-version goldens); a separate lookup only for callers with no pane path fixed the create but left a split on the same handle waiting for a window that does not exist; keeping the adopted record a runtime terminal record inside the adoption would move every windowed pane handle off the pane path.

Linked Issue

Regression from A1 (#31187), found by the switch-on server e2e specs. Bisect: the unit repro below fails at #31187 (c335070) with terminal_handle_stale and passes the no-window case at its parent, #31171 and #31130.

Visual Proof

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

Testing

  • headless-create-terminal-handle-main.test.ts (switch on): on a host that never had a window, and one whose window closed, a phone's terminal create answers ready. Fails at base with terminal_handle_stale (both cases), passes at head. The fixture's binding write now tells its write listeners, as the Store does, and offers bindPane so a mock spawn binds its pane like the PTY host's spawn commit.
  • Server specs: see below.
  • Switch-on comparison, src/main/runtime + src/main/persistence, base b99552c vs head b91ceba in clean worktrees: 11 vs 11 failing, none fails only at head. Switch-off: 2 vs 2, none only at head.
  • Switch-off bundle (unminified main, base vs head): the only difference is the new windowlessOwnHandle check, which folds to return false, and its call in getLivePtyForHandle's guard; switch-off behaviour is identical. Renderer: manifest entry order only.

Server specs: switch-on, fresh build:electron-vite:parallel --mode e2e + build:cli at each commit, through run-slot.sh app.

  • base b99552c: 1 passed, 2 failed (paired-mobile-desktop-tab-composition: session.tabs.createTerminal terminal_handle_stale; paired-desktop-server-layout-frames: runtime timeout on terminal.split); headless-serve-focused-terminal-create passed.

  • head b91ceba: 3 passed (paired-mobile-desktop-tab-composition, paired-desktop-server-layout-frames, headless-serve-focused-terminal-create).

  • head 50473fb (with origin/main merged, including D1b-1 Layout groundwork (switched off): main starts every split and new pane, the window only attaches #31258): 3 passed. The layout-frames runtime timeout on a windowless split, also seen at base, is gone at head: it was a downstream symptom of the same handle adoption.

  • I manually tested these changes locally

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

AI Disclosure

Review

Reviews:

  • Opus round 1 (4607dbd, any own handle a pane adopted took the terminal path): not blocking, but windowed switch-on builds changed split, focus, show and send for pre-allocated handles. Reworked.
  • Delta (92f0f66, a separate lookup for callers with no pane path): nothing blocking, but a split on the same handle on a windowless server still waited for a window (the layout-frames spec's timeout), and the tab-close authority had the same gap. Reworked.
  • Whole-fix review (b91ceba, the windowless-only condition): nothing blocking. Traced: a window attaching later (the condition stops as the window becomes the graph authority; the handle re-mints as a terminal record during its reload, then becomes the window's pane handle), a window closing (main takes the graph back and the condition applies again), windowed replies untouched, switch-off inert, close and split back on their pre-Layout-owner build: main answers terminal questions from its own layout (A1, dark) #31187 path.

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 change; replies keep their shapes.
  • SSH: SSH panes main owns use the same lookup.
  • Why no switch-on CI leg caught it: the switch-on e2e workflow (layout-owner-e2e.yml) runs only on manual dispatch; no PR trigger runs these specs with the switch on.

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)

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e91cea35-3405-49fe-8954-29ce47dc0fe6
📥 Commits

Reviewing files that changed from the base of the PR and between 6d33f91 and 50473fb.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

The change allows getLivePtyForHandle to accept handles that match a headless main-layout terminal’s PTY mapping and active pane identity. It also adds a fixture helper for persisting pane bindings and a regression test for terminal creation when the host has no window or its window is unavailable.

Priority: ⚪ Pending latest changes

Merge Risk: 🔵 Low · up to 6d33f

Headless terminal creation is covered, but a follow-up operation with its handle is not. Add that check for stronger regression protection; no current runtime failure was established.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the headless-server terminal creation regression and the switch-on scope. It is specific and related to the primary change.
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 1 functions across 3 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.
Description check Passed The description is complete and follows the repository template. It explains the user impact, scope, mechanism, rationale, testing, review history, compatibility considerations, and checklist status. …
Full details: Description check

Explanation

The description is complete and follows the repository template. It explains the user impact, scope, mechanism, rationale, testing, review history, compatibility considerations, and checklist status. The Linked Issue section references regression PR #31187 but does not provide a conventional issue link or Fixes # reference.

✨ 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.

@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.

🧹 Nitpick comments: 1
src/main/runtime/headless-create-terminal-handle-main.test.ts: 1

1-67: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Exercise a follow-up operation with the created handle.

The test validates the handle lookup that occurs during creation, but it does not validate a later terminal operation. Add a read using created.tab.terminal so a stale-handle regression after creation fails both headless cases.

Suggested fix
     expect(created.tab).toMatchObject({ status: 'ready' })
+    const handle = created.tab.terminal!
+    await expect(runtime.readTerminal(handle)).resolves.toMatchObject({ handle })

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40139bf9-1669-432d-9b12-78dfdce37dc6
📥 Commits

Reviewing files that changed from the base of the PR and between ce71535 and 6d33f91.

📒 Files selected for processing: 3
  • src/main/runtime/headless-create-terminal-handle-main.test.ts
  • src/main/runtime/terminal/query/pty-terminal-summary.ts
  • src/main/runtime/terminal/surface/terminal-surface-replies.test-fixture.ts

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

@Jinwoo-H
Jinwoo-H merged commit 87fe842 into main Oct 21, 2026
39 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