Skip to content

fix(runtime): degrade focused terminal create on a windowless host (STA-2585) - #12791

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/sta-2585-headless-focus-create
Aug 6, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/sta-2585-headless-focus-create

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes GitHub #10333 / Linear STA-2585 (STA-2498 is its duplicate — one fix closes both).

Symptom

A focus-requested terminal create against a headless orca serve host throws "No renderer window available". P0, reported with no workaround.

Reproduction — red on origin/main (ae1ed5e886)

Against a real headless orca serve host, driving the exact RPC the remote CLI puts on the wire:

npx playwright test tests/e2e/headless-serve-focused-terminal-create.spec.ts \
  --config tests/playwright.config.ts --project=electron-headless --workers=1
✘ creates a focus-requested terminal against a headless serve host
  Error: No renderer window available
     at ../../src/cli/runtime/client.ts:130

In-process, same state (orca serve publishes a ready graph under HEADLESS_RUNTIME_WINDOW_ID = 0 with no BrowserWindow, src/main/index.ts:2862):

❯ OrcaRuntimeService.getAuthoritativeWindow src/main/runtime/orca-runtime.ts:34743:13
❯ OrcaRuntimeService.createTerminal       src/main/runtime/orca-runtime.ts:25395:40

Change — orca-runtime.ts:25056

Rather than bolt on a fourth clause, this collapses the window check, because rendererWindow === null was already availableAuthoritativeWindow === null in disguise (rendererWindow is itself gated on rendererBacked):

(opts.rendererBacked === true && rendererWindow === null)   // before
availableAuthoritativeWindow === null                       // after

That is provably the old clause plus exactly the missing focus case — the difference set is no window && !rendererBacked, where non-focus creates already went background via clause 2. So it removes a footgun at zero extra behavior change.

Focus is degraded in placement, not dropped: the background path already honors it, publishing with activate: presentation === 'focused' (:25336) and revealing with activate/presentation (:25360) — the in-tree precedent at :25757.

The reported Mac UI + half no longer reproduces — scoped out with evidence

Worth stating, because closing #10333 on a fix for the UI half would be wrong. On current main the desktop client never asks the host for focus, at two independent layers:

So the surviving P0 is the CLI/RPC half. The runtime-layer hole is still reachable by any caller with no clientKind (loopback CLI, orchestration internals), so it is closed at the runtime layer regardless.

On the two existing community PRs — neither should merge as-is

Both diagnose the bug correctly. Verified individually:

  • fix(runtime): headless terminal create --focus without renderer window #10370 — production change is logically equivalent to this one, but its tests are vacuous: they import only the extracted pure function and assert its own boolean truth table. Revert its orca-runtime.ts call site and keep the helper, and all 7 tests still pass. Nothing in it constructs a runtime, calls createTerminal, or observes the throw.
  • fix(runtime): degrade focused terminal create on headless serve #10557 — the one-clause production change is correct, but its tests never wire the headless-serve state (no syncWindowGraph/attachWindow), so graphStatus stays 'unavailable'. Replicating its test shape against unfixed main yields Error: runtime_unavailable, not No renderer window available — red on main for the wrong reason, never demonstrating the reported bug. It also has no headed-host regression test, which is the stated main risk.

Mutation evidence

  • Revert the clause → all 4 headless tests red, each Caused by: Error: No renderer window available; the E2E goes red with the same error over the wire. Restored by re-applying the edit.
  • Replace the clause with true (unconditional degrade) → the headed test keeps focus-requested terminal creates on the renderer when a window exists goes red, plus two pre-existing renderer-path tests. The headed guard is real, not decorative.

src/main/runtime suite: 241 files, 3694 tests green. pnpm typecheck clean, oxlint clean.

Risk

Headed desktop: none. The clause fires only when getAvailableAuthoritativeWindow() returns null; with a window the renderer IPC path is byte-identical, proven by the second mutation. Renderer reload is unaffected — the window still exists.

One deliberate behavior change beyond the bug: a headed host with all windows closed (macOS app alive) previously threw runtime_unavailable on a focused create and now spawns in background. That is correct rather than a regression — a non-focus create in that state already does exactly this, and persistWindowlessPtyBindingsForDesktopAttach (:5369) exists precisely because "a promoted serve can close and later reopen its window while new background PTYs keep arriving."

Pre-existing, deliberately not touched

The degraded create returns a misleading warning ("could not make it discoverable") even though the terminal is published to the session tabs; and terminal.create with no worktree still throws raw on a headless host — unreachable from the remote CLI, which hard-requires --worktree (src/cli/handlers/terminal.ts:130).

`orca serve` publishes a ready graph under HEADLESS_RUNTIME_WINDOW_ID with no
BrowserWindow behind it. `shouldCreateInBackground` only degraded when the
create was renderer-backed, so any focus-requested create fell through to
getAuthoritativeWindow() and threw "No renderer window available" — leaving
`terminal create --focus` with no workaround on a remote server (#10333).

With a worktree selector and no renderer window, a background spawn is the only
usable path, so collapse the renderer-backed window check into a plain
"no window" check. That is the existing rendererBacked clause plus exactly the
missing focus case, and it drops the confusing `rendererWindow === null`
indirection (rendererWindow is already gated on rendererBacked).

Focus is not lost by the degrade: the spawned pane is still published to the
session-tab model and revealed with `activate: true`, which is how a paired
client learns about it. Mirrors the in-tree precedent in
runCreateMobileSessionTerminal.

Headed hosts are unaffected — the clause only fires when no window exists.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dbf65fe2-f8dc-41b6-be00-1cd866a10456

📥 Commits

Reviewing files that changed from the base of the PR and between ae1ed5e and aee95c3.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • tests/e2e/headless-serve-focused-terminal-create.spec.ts

📝 Walkthrough

Walkthrough

The runtime now creates terminals in the background when no authoritative window exists. Headless focused terminal and agent-session creation preserves pane publication and activation behavior. Renderer-backed creation continues to request a focused tab without spawning a PTY. Runtime tests and an end-to-end test cover these cases through direct and RPC-based flows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug, fix, scope, risk, and test evidence, but it omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all required template sections, including explicit checklist results, cross-platform AI review coverage, security audit findings, screenshots status, and platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the runtime fix for focused terminal creation on a windowless host and includes the relevant tracking identifier.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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 aa64ac9 into main Aug 6, 2026
47 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix/sta-2585-headless-focus-create branch August 6, 2026 00:49
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ve (stablyai#12791)

`orca serve` publishes a ready graph under HEADLESS_RUNTIME_WINDOW_ID with no
BrowserWindow behind it. `shouldCreateInBackground` only degraded when the
create was renderer-backed, so any focus-requested create fell through to
getAuthoritativeWindow() and threw "No renderer window available" — leaving
`terminal create --focus` with no workaround on a remote server (stablyai#10333).

With a worktree selector and no renderer window, a background spawn is the only
usable path, so collapse the renderer-backed window check into a plain
"no window" check. That is the existing rendererBacked clause plus exactly the
missing focus case, and it drops the confusing `rendererWindow === null`
indirection (rendererWindow is already gated on rendererBacked).

Focus is not lost by the degrade: the spawned pane is still published to the
session-tab model and revealed with `activate: true`, which is how a paired
client learns about it. Mirrors the in-tree precedent in
runCreateMobileSessionTerminal.

Headed hosts are unaffected — the clause only fires when no window exists.

Co-authored-by: Jinwoo-H <[email protected]>
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