Skip to content

Keep idle Claude sessions selected during nested Codex work - #29386

Merged
nwparker merged 2 commits into
mainfrom
nwparker/foreground-agent-session-owner
Oct 16, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/foreground-agent-session-owner

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A finished Claude turn still belongs to the running Claude session. A background Codex worker must not take over its chat, mobile transcript, or resume command.

What Changed

Keep the identified Claude process as the session owner after a turn finishes or its status ages. Before accepting another provider, the execution host checks the existing process: confirmed exit or suspension permits replacement; an unavailable read preserves ownership. Local and relay ingestion use the same rule, including ordered, durable startup replay. Older hosts without this support retain their previous behavior.

Why

A timestamp or Stop hook describes a turn, not whether the foreground CLI exited. Reusing the existing process check avoids guessing from elapsed time or adding polling. Adversarial review also fixed pending requests publishing after stop or disable/re-enable, and a queued restart reviving a listener after a second stop. Regression tests cover these alongside suspension/resume and durable replay.

The incomplete done/stale replacement policy is present in merged PR #3990 (source-history attribution). #29264 fixed active-turn nested hooks but left this existing idle-session gap; it did not introduce it. The overlapping #10109 and #22866 are closed as superseded; #25687 is also superseded by the merged host ownership guard.

Linked Issue

Resolves the reproduced ownership paths in #10105 and #22767; both are closed with verification limits documented. Windows/unidentified processes and older hosts retain the previous fallback, and this verification used controlled hooks/transcripts rather than live model-backed nested turns.

Visual Proof

Before: the original #10105 report shows the incorrect Codex resume error:

Original reported error

After: controlled hooks/transcripts on the fixed macOS build, with an identified stand-in process running in the actual terminal. Claude's reply remains after six nested Codex hooks, the paired mobile client reads the same transcript, and Show terminal returns without an error. Three recorded runs passed; screenshots inspected. This uses a foreground process fixture, not a live Claude model turn.

02-claude-after-nested.png
03-return-to-terminal.png

page@355880a3f9e9162abd7d55cacde6a058.webm

Testing

  • Red/green: eight failing assertions across three new test files on the prior production code, then passing with the fix.

  • Final focused suite: 197 tests / 24 files passed (75.69s).

  • Hidden Electron UI + paired mobile transport: 3/3 recorded runs passed on macOS (52.2s), screenshots inspected.

  • pnpm tc, changed-code quality, reliability manifest validation, and Electron/CLI builds passed.

  • Reproduced the CI Linux failure in an isolated Linux container: the old test claimed the Playwright worker owned a terminal left at a shell prompt. The corrected test starts an identified foreground stand-in in the actual PTY and verifies it remains owned before nested hooks. Final Linux build: 3/3 hidden Electron runs passed (51.3s). Recording-enabled Linux attempts timed out during Electron startup, before the test ran; attached video is from macOS.

  • Reproduce UI proof: ORCA_BACKGROUND_LAUNCH=1 ORCA_E2E_RECORD_VIDEO=1 pnpm exec playwright test --config tests/playwright.config.ts tests/e2e/nested-agent-idle-session-owner.spec.ts --project=electron-headless --workers=1 --repeat-each=3.

  • I manually tested these changes locally

  • Automated tests added/updated

Tested on macOS with a real OS process identity and authenticated hook requests. Relay tests cover transport boundaries, legacy peers, cold replay, and genuine provider replacement. The Electron test uses the actual chat UI, paired mobile transport/resolver/transcript reader, and Show terminal action. Linux Electron is also exercised in an isolated container. No live SSH/WSL host, Windows Electron runtime, physical phone, or new live Claude/Codex model turn was tested.

Review

Adversarial sub-agent and parent reviews found and fixed stale HTTP/probe publications after stop or status disable/re-enable, a fixed-token relay restart race, and a second-stop queued-restart race. Regression tests pass; the sub-agent found no remaining blocking issue. The Linux E2E fixture now uses the actual foreground PTY process instead of the test runner.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Process checks execute on the owning host; remote PIDs are never probed locally. New presence fields are optional for wire compatibility. No polling/timers added; conflicting hooks reuse the existing bounded process probe and concurrent-check deduplication. Folder workspaces use the existing host/workspace ownership scope. Windows/no-identity fallback remains a known limitation.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • Local focused tests, typecheck, changed-code quality, and Electron build pass. CI static checks and all five unit shards passed; remaining CI waits were explicitly waived for merge and outstanding PR runs cancelled at the user's request.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5673d2fd-c6cd-4a41-8df1-22159ec37956
📥 Commits

Reviewing files that changed from the base of the PR and between 9b99928 and 6a3d3d3.

📒 Files selected for processing: 33
  • config/reliability-gates.jsonc
  • src/main/agent-hooks/server-http-owner-probe-lifecycle.test.ts
  • src/main/agent-hooks/server-idle-process-owner.test.ts
  • src/main/agent-hooks/server-start-failure-lifecycle.test.ts
  • src/main/agent-hooks/server-startup-lifecycle.test.ts
  • src/main/agent-hooks/server/server-agent-presence.ts
  • src/main/agent-hooks/server/server-ingest-normalization.ts
  • src/main/agent-hooks/server/server-lifecycle.ts
  • src/main/agent-hooks/server/server-state.ts
  • src/main/agent-hooks/server/server-status-hook-lifecycle.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-hook-owner-presence.ts
  • src/shared/agent-hook-presence-transition.ts
  • src/shared/agent-hook-spool-drain.test.ts
  • src/shared/agent-hook-spool.ts
  • src/shared/agent-hook-startup.ts
  • src/shared/agent-process-presence-probe.test.ts
  • src/shared/agent-process-presence-probe.ts
  • src/shared/agent-process-presence.ts
  • src/shared/agent-status-identity.ts
  • src/wsl-guest/agent-hook-event-admission.ts
  • src/wsl-guest/agent-hook-provider-normalization.ts
  • src/wsl-guest/agent-hook-request.ts
  • src/wsl-guest/agent-hook-server-bind.ts
  • src/wsl-guest/agent-hook-server.ts
  • src/wsl-guest/agent-hook-spool-ingest.ts
  • src/wsl-guest/relay-agent-presence.ts
  • src/wsl-guest/relay-http-owner-probe-lifecycle.test.ts
  • src/wsl-guest/relay-idle-process-owner.test.ts
  • tests/e2e/helpers/host-created-terminal-retention-oracle.ts
  • tests/e2e/nested-agent-idle-owner.unit.test.ts
  • tests/e2e/nested-agent-idle-session-owner.spec.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker

Copy link
Copy Markdown
Contributor Author

Adversarial review completed with a sub-agent and independent parent review. Findings addressed in 6a3d3d359065ea6569933ccdc8f6d97cfed0074b:

  • P2: obsolete requests could publish after stop or status disable/re-enable. Reproduced on the original head for local HTTP and relay requests. Listener-generation and status-generation checks now discard the request before normalization/cache changes; process-probe publication and deduplication use the same lifecycle boundary. Fixed-token relay restart and interrupted spool replay have permanent regressions.
  • P2: a second stop could be undone by a queued restart. Reproduced with start → stop → queued start → stop while replay was pending. The queued start now retains its original generation and cannot reopen either listener after the second stop.
  • Linux test failure: incorrect process fixture. Reproduced the CI failure in an isolated Linux container. The test previously reported the Playwright worker as Claude while the real terminal was idle at a shell prompt, allowing shell reconciliation to clear the synthetic owner. It now runs an identified foreground stand-in in that PTY and verifies ownership before posting nested hooks. Assertions were preserved.

Final local verification: 197 tests across 24 files passed, full pnpm tc, changed-code quality, and reliability-manifest validation passed. Hidden Electron UI: 3/3 recorded macOS runs and 3/3 Linux-container runs passed. Screenshots inspected; fresh macOS screenshots/video are in the PR body. Recording-enabled Linux attempts timed out during Electron fixture startup before the test ran; Linux passing runs used screenshots without recording.

Reviewed ownership authority, host/workspace boundaries, legacy peer behavior, genuine replacement after exit/suspension, unavailable reads, startup/stop concurrency, and durable replay. No remaining blocking review findings. Live model-backed nested turns, live SSH/WSL hosts, Windows Electron, and a physical phone remain unverified; #10105 and #22767 remain open.

Merge is pending the exact current commit's full .github/workflows/pr.yml run and its PR checks passed aggregate, plus required checks.

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