Skip to content

fix(runtime): headless terminal create --focus without renderer window - #10370

Closed
innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:fix/headless-terminal-create-focus-fallback
Closed

innocarpe wants to merge 1 commit into
stablyai:mainfrom
innocarpe:fix/headless-terminal-create-focus-fallback

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Root cause

shouldCreateInBackground only covered headless when rendererBacked === true (or when focus was not required). Focus-requested creates still called getAuthoritativeWindow(), which throws on serve with no windows.

Test plan

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/terminal-create-background-decision.test.ts
  • On headless remote: orca --environment <remote> terminal create --worktree <wt> --command "echo test" --focus --json returns ok (background surface) instead of runtime_error
  • Mac UI + → agent on headless remote server creates a usable terminal handle

ELI5

Launching an agent or terminal create --focus on headless orca serve crashed with No renderer window available. Headless creates now use the background spawn path when there is no UI window.

Mac UI agent launch and `terminal create --focus` requested focus even on
headless `orca serve`, which has no BrowserWindow and threw
"No renderer window available". Fall back to the existing background spawn
path whenever there is no authoritative window, matching the rendererBacked
headless behavior.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Terminal background-spawn selection is extracted from the runtime into shouldCreateTerminalInBackground. The helper evaluates worktree selection, agent session claims, renderer focus requirements, renderer-backed creation, and authoritative window availability. A Vitest suite covers the decision combinations, including headless focus and renderer-backed fallbacks. The runtime now imports the helper and uses its result for terminal creation.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes summary and test plan, but it omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections and fill them with the requested details, including screenshots or "No visual change" and the required review and audit notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses #10333 by routing focus/headless terminal creation to background when no authoritative window exists and adds tests for the matrix.
Out of Scope Changes check ✅ Passed The changes are narrowly focused on terminal creation decision logic and tests, with no unrelated code paths introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly matches the main fix: headless terminal creation with --focus when no renderer window exists.

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/terminal-create-background-decision.ts (1)

1-8: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Condense the explanatory comments.

The function and conditions already convey most of this behavior; keep only a short headless-fallback rationale.

Also applies to: 28-29

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e3f3afb-800f-4d48-be16-58337e719f66

📥 Commits

Reviewing files that changed from the base of the PR and between 1bd36ce and 644a5db.

📒 Files selected for processing (3)
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/terminal-create-background-decision.test.ts
  • src/main/runtime/terminal-create-background-decision.ts

@Jinwoo-H

Jinwoo-H commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and for the diagnosis — it was correct, and it made the fix straightforward to confirm.

We reproduced #10333 against a real headless orca serve host (not a mock) and it fails exactly where you identified: a focus-requested create falls through to getAuthoritativeWindow() and throws. That part of your analysis held up completely.

We've opened #12791 with the fix. Two reasons we went with a separate PR rather than merging here, both about test coverage rather than your diagnosis:

  • fix(runtime): headless terminal create --focus without renderer window #10370 — the production change is logically equivalent to ours. But reverting the orca-runtime.ts call site while keeping the extracted helper leaves all 7 tests passing, because they only exercise the pure function's own truth table; nothing constructs a runtime, calls createTerminal, or observes the throw. So the tests can't catch a regression in the thing being fixed.
  • fix(runtime): degrade focused terminal create on headless serve #10557 — the one-clause change is correct. But the tests never wire the headless-serve state (no syncWindowGraph/attachWindow), so graphStatus stays 'unavailable'. Replicating that test shape against unfixed main gives Error: runtime_unavailable, not No renderer window available — it goes red on main for a different reason, so it never demonstrates the reported bug.

One thing worth knowing that neither PR could have anticipated: the Mac UI + half of this issue no longer reproduces on current main. #9687 and #10193 landed after the original report and now send presentation: 'background' for paired clients. So the surviving defect is the CLI/RPC path only — which is what #12791 closes at the runtime layer, since it stays reachable for any caller without a clientKind.

Genuinely appreciate the work here; the fix in #12791 is the shape you both proposed. Closing these in favour of it, but the credit for finding it is yours.

@innocarpe

innocarpe commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

@Jinwoo-H thanks for digging into this — and for running it on a real headless orca serve host instead of trusting the unit suite.

You're right that this PR's tests mostly exercise the helper, not the call site that actually throws. I don't want to ship something that stays green after the fix is reverted. Closing in favor of #12791; glad the diagnosis held up on your side.

@innocarpe

innocarpe commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #12791.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terminal create --focus throws "No renderer window available" on headless orca serve — Mac UI + button cannot launch agents on remote servers

4 participants