Skip to content

fix(remote): create paired agent sessions without host focus - #10193

Merged
OrcaWin merged 7 commits into
stablyai:mainfrom
tozes:agent/fix-headless-agent-session
Jul 24, 2026
Merged

OrcaWin merged 7 commits into
stablyai:mainfrom
tozes:agent/fix-headless-agent-session

Conversation

@tozes

@tozes tozes commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • create paired structured agent sessions with background presentation on the execution host
  • keep activation and focus owned by the paired client through the existing focus-intent reconciliation
  • cover both fresh terminal.createAgentSession and resume terminal.ensureAgentSession requests

Fixes #10192.

Root cause

The remote renderer sent presentation: "focused" when an activated agent session was requested. A headless orca serve host has no authoritative renderer window, so terminal creation failed with No renderer window available before spawning a PTY.

Plain paired terminal creation already separates background host creation from caller-local focus. This change applies the same ownership boundary to structured agent sessions.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions

Focused validation:

  • vitest run --config config/vitest.config.ts src/renderer/src/runtime/web-runtime-session.test.ts — 37 passed
  • pnpm test:repro:remote-agent-session — passed: one spawn, retry adoption, durable exit retirement, no restart resurrection
  • pnpm typecheck — passed
  • pnpm lint — passed
  • oxfmt --check and focused oxlint — passed
  • git diff --check — passed
  • CLI and Electron Vite builds completed as part of the reproduction harness

The full test run completed 36,443 passing tests with two unrelated failures:

  • src/main/runtime/multi-client-navigation-isolation.integration.test.ts failed in the aggregate run and then passed in isolation (5/5).
  • src/relay/git-handler.test.ts expects not a git repository, while this temporary checkout returns Stopping at filesystem boundary; it remains reproducible in isolation and does not touch the changed renderer path.

The repository requests Node 24; local validation ran on Node 22.22.2 with pnpm 10.24.0 and emitted the engine warning.

AI Review Report

Reviewed the complete two-file diff for host/client focus ownership, legacy fallback behavior, duplicate-spawn risk, and fresh/resume parity. The change leaves legacy session.tabs.createTerminal behavior and the existing caller-local focus intent unchanged.

Cross-platform compatibility was checked for macOS, Linux, and Windows. The patch contains no platform-specific shortcuts, labels, paths, shell behavior, native modules, or Electron window APIs. It also preserves SSH and paired-runtime host ownership.

Security Audit

No new input handling, command execution, path handling, authentication, secrets, dependencies, permissions, or IPC methods are introduced. The only runtime change selects the existing background presentation enum for paired structured agent-session RPCs. Operation IDs, provider claims, compatibility fallback, and host-side authorization remain unchanged.

Notes

This is intentionally client-side and scoped to paired remote structured-agent launches. It does not change the server fallback for ordinary local focused terminal creation and does not mask local renderer startup failures.

@tozes
tozes marked this pull request as ready for review July 23, 2026 14:38
@coderabbitai

coderabbitai Bot commented Jul 23, 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: 7efc65bd-6c2d-4675-a602-268bd660fa46

📥 Commits

Reviewing files that changed from the base of the PR and between 0a7aae9 and ddb61cc.

📒 Files selected for processing (1)
  • config/scripts/remote-agent-session-authority-repro.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/scripts/remote-agent-session-authority-repro.mjs

📝 Walkthrough

Walkthrough

Structured web runtime session creation now sends presentation: 'background' for both agent-session ensuring and creation. Focus intent now preserves host tab and terminal leaf identity so mirrored snapshots can select the exact requested leaf. RPC tests, replay repro scripts, process cleanup, reliability gate coverage, and a headed Playwright scenario were added or updated for paired focus authority, stale publication, response-loss replay, and terminal lifecycle validation.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: paired agent sessions now avoid host focus.
Description check ✅ Passed The description matches the template and includes summary, screenshots, testing, AI review, security, and notes.
Linked Issues check ✅ Passed The changes address #10192 by using background presentation on the host while preserving client-side focus for both create and resume paths.
Out of Scope Changes check ✅ Passed The added scripts, tests, and focus-intent/runtime changes all support the paired agent-session fix and regression coverage.

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84d7a197-ace3-490e-9c36-4a9f53f5243a

📥 Commits

Reviewing files that changed from the base of the PR and between 8f40ddf and 1fcca9b.

📒 Files selected for processing (2)
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 028bb1d8-53bd-4962-9b8b-16db3a671918

📥 Commits

Reviewing files that changed from the base of the PR and between 529cf09 and 0a7aae9.

📒 Files selected for processing (16)
  • config/reliability-gates.jsonc
  • config/scripts/remote-agent-session-authority-repro.mjs
  • config/scripts/remote-agent-session-process-cleanup.mjs
  • config/scripts/remote-agent-session-repro-client.mjs
  • config/scripts/remote-agent-session-repro-fixture.mjs
  • config/scripts/remote-agent-session-repro-writable-shell.mjs
  • src/main/runtime/rpc/methods/agent-session.test.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-focus-intent.ts
  • src/renderer/src/runtime/web-session-intent-owner.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/renderer/src/store/index.ts
  • tests/e2e/remote-agent-session-focus-authority.spec.ts

@OrcaWin
OrcaWin merged commit fde0636 into stablyai:main Jul 24, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…i#10193)

* fix(remote): create paired agent sessions without host focus

* test(remote): assert structured resume request

* test(remote): preserve provider-separated resume coverage

* test(remote): assert paired agent focus authority

* fix(remote): separate agent host creation from viewer focus

* test(remote): harden agent-session authority validation

* test(remote): validate retired pane identity

---------

Co-authored-by: OrcaWin <[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.

Paired desktop UI cannot create agent session on headless host (No renderer window available)

2 participants