Skip to content

fix(terminal): prevent reconnect from killing live daemon sessions - #9804

Merged
OrcaWin merged 7 commits into
mainfrom
OrcaWin/issue-9749-windows-daemon-generation-safety
Jul 22, 2026
Merged

OrcaWin merged 7 commits into
mainfrom
OrcaWin/issue-9749-windows-daemon-generation-safety

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Separate explicit user terminal closes from reconnect/lifecycle observations with the additive session.tabs.closeLifecycle RPC.
  • Require exact publication, terminal incarnation, runtime environment, ownership, liveness, and intent evidence before lifecycle retirement; missing or incompatible evidence keeps and audits instead of killing.
  • Preserve legacy daemon discovery and warm PTY reattachment while preventing stale mirrors from routing destructive kills across surviving daemon generations.
  • Add a deterministic native-Windows v21-v25 named-pipe harness covering production desktop discovery, repeated reconnects, client relaunch, simultaneous clients, remote-profile requests, exact root/descendant liveness, and bounded shutdown-dispose-failed fencing.

Addresses #9749. The complete issue/PR investigation and call-flow reconstruction are included in docs/reference/plans/2026-07-21-windows-daemon-generation-safety-investigation.md.

Screenshots

No visual change.

Testing

  • pnpm lint — changed-file oxlint and code formatting pass; the repository-wide switch-exhaustiveness lane has pre-existing unmatched cases in skill-freshness-group.tsx outside this diff.
  • pnpm typecheck
  • pnpm test — focused production/RPC/renderer coverage passes 948/949; the sole failure is the existing Windows /tmp versus \tmp badgeColor dedupe expectation in untouched code.
  • pnpm build — fresh Electron Vite and paired web-client builds pass; the full native/package build was not run.
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused evidence:

  • Native Windows five-generation reconnect oracle: 2/2 passed in 99.1s; v21-v25 each accepted 16 reconnect hellos, all ten PTY roots and ten descendants survived six lifecycle attempts per stale mirror, and zero session-killed events occurred.
  • The same oracle passed with a fresh Electron E2E build in 137.1s; a separate 25-burst stress run passed.
  • Practical Electron clean quit/relaunch with a live daemon-backed terminal: 1/1 passed in 24.0s with restored output and working keyboard/direct PTY input.
  • Mixed-version preservation/retirement: 2/2 passed; non-empty v22 remained reattachable while empty v24 retired.
  • Daemon discovery/adoption/retirement suites: 224 passed, 3 skipped in the final broad lane; the focused changed scanner lane passed 133/133.
  • Remote-runtime, real E2EE WebSocket, shared-control, SSH-provider, WSL-context, and PTY transport suites passed.
  • Reliability-gate validator, max-lines ratchet, changed-code oxfmt --check, changed-code oxlint, and git diff --check passed.

AI Review Report

Three full-diff review rounds ran against merge base 937a2015e.

Round 1 found and fixed four destructive-action safety issues: lifecycle retirement could still reach renderer/process teardown, unavailable PTY inventory was treated as death, close intent could cross runtime profiles, and the Windows harness allowed an unsafe PID-start tolerance. An elegance pass also removed a cached capability result that could outlive server replacement. Round 2 was clean. After strengthening the harness to call production desktop discovery, round 3 found and fixed a Windows socket-mock defect in scanner tests; the subsequent full-diff review was clean.

The review explicitly checked macOS, Linux, and Windows compatibility; legacy protocol behavior; Windows named pipes and process identity; SSH, WSL, remote-runtime, sleeping/reattachable sessions, and multi-client behavior; path handling; Electron lifecycle behavior; cleanup ownership; polling/listener/handle risks; and reconnect-storm performance. Platform-specific fixture behavior is runtime-gated, and production adds no PowerShell/CIM hot path, polling loop, listener, subprocess, or Job Object implementation.

Security Audit

The changed RPC is a destructive-action boundary. Lifecycle requests require typed provenance plus exact host publication and terminal-incarnation evidence, fail closed on missing/access-denied liveness, and never fall back to the legacy destructive method on an old server. Explicit user closes retain the existing destructive path.

Logging records client kind, connection/request identity, reason, publication, and allow/refusal decision without terminal contents, authentication tokens, pairing secrets, or environment data. No dependency, authentication primitive, shell-command, Git command, or production process-enumeration change was added. The Windows harness uses guarded temporary roots and exact PID/start identities, refuses cleanup outside its fixture namespace, and left no process, pipe, handle, or temp-directory residue.

Notes

@coderabbitai

coderabbitai Bot commented Jul 22, 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

Run ID: 27d735d3-4ba5-48f1-a8b9-5c56febc1cf6

📥 Commits

Reviewing files that changed from the base of the PR and between 7770f07 and 20e6a5a.

📒 Files selected for processing (13)
  • config/reliability-gates.jsonc
  • docs/reference/plans/2026-07-21-windows-daemon-generation-safety-investigation.md
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/session-tabs-schemas.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • tests/e2e/fixtures/daemon-generation-fixture-contract.ts
  • tests/e2e/fixtures/daemon-generation-reconnect-client.ts
  • tests/e2e/fixtures/daemon-generation-runtime-close.ts
  • tests/e2e/helpers/daemon-generation-safety-fixtures.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • src/main/runtime/runtime-rpc.ts
  • tests/e2e/fixtures/daemon-generation-runtime-close.ts
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • src/main/runtime/rpc/methods/session-tabs-schemas.test.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • tests/e2e/fixtures/daemon-generation-reconnect-client.ts
  • src/main/runtime/orca-runtime.ts
  • config/reliability-gates.jsonc

📝 Walkthrough

Walkthrough

Adds lifecycle-aware session-tab close RPCs with explicit reasons, publication epochs, terminal incarnation handles, and host-side liveness adjudication. Renderer close-intent tracking is scoped by environment and worktree, with replay and snapshot freshness handling. Daemon initialization supports isolated legacy history paths. New Windows-focused Playwright fixtures exercise multi-generation reconnect survival, bounded disposal failure, process liveness, and cleanup behavior. Reliability-gate documentation records the investigation, evidence, criteria, and validation gaps.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.19% 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 matches the main change: preventing reconnect/lifecycle flows from killing live daemon sessions.
Description check ✅ Passed The description covers all required template sections and includes testing, review, security, screenshots, and platform notes.
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.

@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

🧹 Nitpick comments (1)
tests/e2e/daemon-generation-reconnect-safety.spec.ts (1)

25-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: guard against protocol-version overlap in the fixed generation list.

ALL_GENERATION_PROTOCOLS hardcodes [21, 22, 23] and appends PROTOCOL_VERSION - 1 / PROTOCOL_VERSION. This is correct while PROTOCOL_VERSION stays at 25, but if it ever lands on 22–24 the list gains a duplicate protocol (and thus a colliding named-pipe socket path), surfacing only as a cryptic L290 set-size failure. Deduping the list would make the intent version-agnostic.

♻️ Suggested dedupe
-const ALL_GENERATION_PROTOCOLS = [...GENERATION_PROTOCOLS, PROTOCOL_VERSION - 1, PROTOCOL_VERSION]
+const ALL_GENERATION_PROTOCOLS = [
+  ...new Set([...GENERATION_PROTOCOLS, PROTOCOL_VERSION - 1, PROTOCOL_VERSION])
+]

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6890fdf2-892c-4471-8152-545618cacfc8

📥 Commits

Reviewing files that changed from the base of the PR and between b25c298 and e1e2190.

📒 Files selected for processing (40)
  • config/reliability-gates.jsonc
  • docs/reference/plans/2026-07-21-windows-daemon-generation-safety-investigation.md
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • src/main/daemon/daemon-init.test.ts
  • src/main/daemon/daemon-init.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/session-tab-close-methods.ts
  • src/main/runtime/rpc/methods/session-tabs-schemas.test.ts
  • src/main/runtime/rpc/methods/session-tabs-schemas.ts
  • src/main/runtime/rpc/methods/session-tabs.test.ts
  • src/main/runtime/rpc/methods/session-tabs.ts
  • src/main/runtime/runtime-rpc.ts
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts
  • src/renderer/src/components/terminal-pane/terminal-parked-tab-watchers.test.ts
  • src/renderer/src/components/terminal-pane/terminal-parked-tab-watchers.ts
  • src/renderer/src/components/terminal/terminal-close-incarnation.test.ts
  • src/renderer/src/components/terminal/terminal-close-incarnation.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.test.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
  • src/renderer/src/runtime/web-runtime-session.test.ts
  • src/renderer/src/runtime/web-runtime-session.ts
  • src/renderer/src/runtime/web-session-close-intent.test.ts
  • src/renderer/src/runtime/web-session-close-intent.ts
  • src/renderer/src/runtime/web-session-tabs-sync.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync.ts
  • src/shared/runtime-types.ts
  • tests/e2e/daemon-generation-reconnect-safety.spec.ts
  • tests/e2e/fixtures/daemon-generation-canary.cjs
  • tests/e2e/fixtures/daemon-generation-desktop-discovery.ts
  • tests/e2e/fixtures/daemon-generation-entry.ts
  • tests/e2e/fixtures/daemon-generation-reconnect-client.ts
  • tests/e2e/fixtures/daemon-generation-runtime-close.ts
  • tests/e2e/helpers/daemon-generation-processes.ts
  • tests/e2e/helpers/daemon-generation-runtime-fixture.ts
  • tests/e2e/helpers/daemon-generation-safety-fixtures.ts

@OrcaWin
OrcaWin merged commit f9f3cd2 into main Jul 22, 2026
11 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/issue-9749-windows-daemon-generation-safety branch July 22, 2026 02:20
brennanb2025 pushed a commit that referenced this pull request Jul 22, 2026
…onment (#9836)

#9804 added a leading `environmentId` parameter to recordWebSessionCloseIntent
(and isWebSessionCloseIntentPending) and updated the web-runtime-session.ts
callers, but missed the second caller in close-mirrored-editor-tab.ts, which
still passed 3 args. This broke the web typecheck on main and, had it compiled,
would have recorded the close intent under the wrong scope key
(closeIntentScopeKey(environmentId, worktreeId)) — so the host snapshot could
flash the just-closed mirrored tab back.

Pass the already-validated runtimeEnvironmentId (the same value handed to
closeWebRuntimeSessionTab immediately below) so the intent is scoped correctly.
Update the test's isWebSessionCloseIntentPending assertion to the 4-arg form.

Co-authored-by: Orca <help@stably.ai>
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
@AmethystLiang

Copy link
Copy Markdown
Contributor

Related to #9952.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…onment (stablyai#9836)

stablyai#9804 added a leading `environmentId` parameter to recordWebSessionCloseIntent
(and isWebSessionCloseIntentPending) and updated the web-runtime-session.ts
callers, but missed the second caller in close-mirrored-editor-tab.ts, which
still passed 3 args. This broke the web typecheck on main and, had it compiled,
would have recorded the close intent under the wrong scope key
(closeIntentScopeKey(environmentId, worktreeId)) — so the host snapshot could
flash the just-closed mirrored tab back.

Pass the already-validated runtimeEnvironmentId (the same value handed to
closeWebRuntimeSessionTab immediately below) so the intent is scoped correctly.
Update the test's isWebSessionCloseIntentPending assertion to the 4-arg form.

Co-authored-by: Orca <help@stably.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants