orca icon indicating copy to clipboard operation
orca copied to clipboard

fix(terminal): make remote agent sessions host-authoritative

Open OrcaWin opened this issue 4 months ago • 1 comments

Summary

Make the remote Orca host authoritative for agent-session ownership and terminal membership.

  • prevent two clients from waking the same live remote agent into duplicate PTYs
  • retire exited terminal surfaces durably so stale client snapshots cannot resurrect ghost tabs
  • negotiate the structured authority path only when the client, runtime, daemon, and relay support it
  • preserve the exact legacy launch behavior at safe pre-side-effect mixed-version boundaries
  • add a deterministic real remote-server reproduction harness and document the compatibility contract

Fixes #8878. Related to #9352.

Screenshots

No visual change.

Testing

  • [ ] pnpm lint — repository-wide baseline failures remain in untouched skill-freshness and generated skill-manifest files; task-owned oxlint, reliability, and max-lines checks pass
  • [x] pnpm typecheck
  • [x] pnpm test — 3,039 files passed, 6 skipped; 32,218 tests passed, 52 skipped
  • [ ] pnpm build — not run as a standalone command; the deterministic harness successfully built the CLI and Electron bundles
  • [x] Added or updated high-quality regression tests

Additional validation:

  • pnpm test:repro:remote-agent-session passes against a real headless orca serve process over the encrypted WebSocket pairing path
  • the harness verifies one physical spawn across two racing clients, canonical retry adoption, exit retirement, stale-publication rejection, and no resurrection after server restart
  • focused changed-area matrix: 15 files and 1,752 tests passed
  • pnpm exec oxlint, reliability gates, max-lines ratchet, and git diff --check pass

AI Review Report

Three independent adversarial reviews covered topology/persistence, protocol compatibility, and process lifecycle. They checked multi-client races, mixed old/new client-runtime-daemon-relay combinations, SSH reconnect identity, daemon and relay exit-before-reply ordering, PTY ID reuse, stale renderer writes, deletion boundaries, and bounded persistence state.

Review iterations tightened explicit spawn-admission fencing, per-incarnation exit handling, adopted canonical daemon IDs, SSH buffered-exit handling, registration-fence cleanup, and per-surface snapshot publication. All three final reviews returned CLEAN.

Cross-platform review explicitly considered macOS, Linux, Windows, native, WSL, and SSH execution. This PR adds no keyboard shortcut or UI-label behavior, uses platform path APIs in the harness, and does not add production shell assumptions or Git-version-dependent commands.

Security Audit

  • structured requests accept only supported agents and normalized provider identities
  • host-only claim identities omit raw provider session IDs and bind execution/worktree scope
  • unknown, conflicting, disconnected, malformed, or unproven ownership fails closed after dispatch
  • legacy fallback is allowed only before authority side effects, or after method_not_found proves an old host did not recognize the request
  • successful spawns require exact PTY incarnation proof; late exits cannot retire a reused PTY
  • host-private topology revisions are omitted from renderer hydration and writes, preventing cross-host authority collisions
  • no dependency, authentication, secret-storage, or permission model changes

No follow-up security action is required for the v1 scope.

Notes

Mixed-version combinations preserve workflows that existed before upgrading. The full fix activates only where every authority layer for that route advertises support, so partially upgraded routes may retain the original legacy behavior but do not lose functionality.

Documented future extensions include a durable fresh-operation journal for exactly-once fresh launches across runtime restarts, verified direct/nested SSH execution namespaces, and multi-process profile coordination.

OrcaWin avatar Jul 21 '26 04:07 OrcaWin

Review Change Stack

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▶️ Resume reviews
  • [ ] 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change introduces remote agent-session host authority with explicit resume and fresh-create RPCs, signed claims, ownership reconciliation, operation replay fencing, and legacy compatibility paths. PTY incarnation identifiers now flow through local, daemon, relay, SSH, runtime, persistence, and renderer layers to reject stale exits and prevent resurrection. Terminal retirement and topology revision state is persisted and reconciled across workspace transfers, host partitions, and restarts. Renderer launch flows now support structured host creation, provisional handoffs, session options, localized outcomes, and legacy fallback. A deterministic Electron-based reproduction harness and extensive regression coverage are added.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.67% 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
Linked Issues check ✅ Passed The PR implements host-authoritative remote session ownership, duplicate-resume prevention, and durable exit retirement, matching #8878's core goals.
Out of Scope Changes check ✅ Passed The changes stay within the agent-session and terminal authority lifecycle scope; the added docs, tests, and launch updates support the same feature set.
Title check ✅ Passed The title clearly and accurately summarizes the main change: making remote agent sessions host-authoritative.
Description check ✅ Passed The description covers the required template sections and is mostly complete; only the Notes section is missing.

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[bot] avatar Jul 21 '26 04:07 coderabbitai[bot]

Rebased onto current main at 2a32c5c9a and resolved the new conflicts.

Upstream integration audit:

  • #9821 is a naming-only refactor with no overlap.
  • #9822 is browser-navigation-only with no overlap.
  • #9836 independently landed the same environment-scoped mirrored-editor close fix. The rebase keeps upstream's implementation and removes the duplicate from this PR, reducing the diff from 163 to 161 files.

Post-rebase validation:

  • remote host-authority gate: 10 files / 325 tests passed
  • reconnect plus mirrored-close gate: 10 files / 1,014 tests passed
  • all TypeScript typechecks passed
  • reliability manifest: 46 gates passed
  • build-backed two-client remote harness passed: one spawn, retry adoption, durable exit retirement, no restart resurrection
  • git diff --check passed

The branch remains one squashed commit authored and committed by OrcaWin.

OrcaWin avatar Jul 22 '26 03:07 OrcaWin

Related to #8871.

AmethystLiang avatar Jul 22 '26 17:07 AmethystLiang