Skip to content

Windows terminals can Switch to Chat: the terminal owner ends its job and reports every process - #29367

Closed
brennanb2025 wants to merge 7 commits into
brennanb2025/flip-pr1-stop-before-adoptfrom
brennanb2025/flip-pr1b-windows-job
Closed

brennanb2025 wants to merge 7 commits into
brennanb2025/flip-pr1-stop-before-adoptfrom
brennanb2025/flip-pr1b-windows-job

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​125 $\color{#cf222e}{\Huge{\mathbf{−}}}$​11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​114
Prod 28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​345 $\color{#cf222e}{\Huge{\mathbf{−}}}$​66 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​279

Stacked on #29242 (merge that first). Part of STA-10705.

Problem

#29242 makes "Switch to Chat" stop the terminal's agent and prove every process under that terminal is gone before a chat takes over the same conversation. Without that proof, two programs end up writing one conversation (real-app runs showed Claude and OMP transcripts branching on macOS and Linux).

On Windows #29242 cannot give that proof yet, so it refuses the switch while the terminal's agent is running ("Exit Claude in the terminal first, then resume this conversation in chat."). Windows processes can leave their parent chain: a Windows QA run saw a Codex branch detached from the shell's ancestry and a child process that outlived its pane by 30 seconds. Only the terminal's Windows job object lists everything the terminal started, and only the process that holds the terminal (the terminal daemon, or Orca itself when the daemon is off) can read it.

What changes for users

On Windows, "Switch to Chat" / "Stop and Switch to Chat" now works for PowerShell, CMD and Git Bash terminals the same way it does on macOS and Linux: the terminal closes and the chat continues the same conversation with its full history.

It still refuses, with the same message as before, when Orca cannot prove everything stopped:

  • a WSL terminal, or a terminal where wsl is running (Windows cannot see the Linux agent inside it);
  • a terminal opened before this update that is still attached to the previous terminal daemon (it works again once that terminal is reopened);
  • a Windows build that cannot report process creation times.

Mechanism

  • New terminal-daemon request terminatePtyJobAndReport, answered by whoever holds the terminal (the daemon's subprocess handle, or the in-process terminal provider). It records every member of the terminal's job object with its creation time, then ends the job. It reports success only when ending the job itself succeeded; ending a job takes every process in it at once, including any started after the read.
  • Orca then confirms each recorded process is gone from a fresh process table (pid absent, or the pid now belongs to a newer process). Anything unreadable counts as not proven.
  • The daemon protocol version is bumped and the request is gated by the owning daemon's version, so terminals on an older daemon keep Refuse chat resume until terminal writers have exited #29242's refusal and never receive the request.
  • Refuse chat resume until terminal writers have exited #29242's Windows refusal before reservation is removed; a failed job read still refuses before anything is stopped.

Why this approach

Reading parent ids from Orca's own process table can't prove completeness on Windows (the detached branch above). The job object can, and the terminal's owner already ends jobs this way during forced teardown, so the proof and the stop are one operation instead of a stop followed by a hope. The common pattern for this kind of handoff is to wait for the exit of a process the app spawned itself; a terminal agent's parent is the user's shell, so here the terminal's owner reports what it contained instead (intended difference, same as #29242).

Limitations

  • Processes that deliberately broke away from the job (allowed for native shells) are not covered. Temporary: removed by the per-agent detectors planned as step 5 of this lane, the same limit Refuse chat resume until terminal writers have exited #29242 labels on macOS and Linux.
  • A Codex background daemon running inside the terminal's job is stopped with it, the same as force-closing that terminal. Intended: Orca's own Codex launcher runs Codex without a daemon.
  • Five files were at the 300-line limit, so a few existing functions moved without behavior changes (the session's job accessor, the snapshot request, two terminal-host methods).

Testing

Unit tests for the job report (complete read, WSL refusal, retry after a new member, failed job termination), the old-daemon gate, and the Windows survivor probe. Real Windows QA (PowerShell, CMD, Git Bash, WSL, and a terminal on the previous daemon) follows before this leaves draft.

…option

The terminal's owner (daemon or in-process provider) records every job member
with its creation time, then ends the job; only a successful job termination
counts as proof. WSL panes and panes with a wsl.exe member refuse. Older
daemons answer not-terminated through the protocol gate, keeping PR1's refusal.
…e-adopt' into brennanb2025/flip-pr1b-windows-job

# Conflicts:
#	src/main/runtime/structured-agent-cli-stop.ts
…e-adopt' into brennanb2025/flip-pr1b-windows-job

# Conflicts:
#	src/main/daemon/daemon-foreground-confirmation-protocol.test.ts
#	src/main/daemon/daemon-protocol-version.ts
#	src/main/daemon/macos-daemon-launchd.test.ts
#	src/shared/local-build-compatibility-contract.json
#	src/shared/local-build-compatibility-contract.ts
@brennanb2025
brennanb2025 marked this pull request as ready for review October 16, 2026 06:36
@brennanb2025
brennanb2025 marked this pull request as draft October 16, 2026 06:39
@brennanb2025
brennanb2025 marked this pull request as ready for review October 16, 2026 06:39
@brennanb2025
brennanb2025 marked this pull request as draft October 16, 2026 17:44
@brennanb2025
brennanb2025 deleted the branch brennanb2025/flip-pr1-stop-before-adopt October 19, 2026 08:08
@brennanb2025
brennanb2025 deleted the brennanb2025/flip-pr1b-windows-job branch October 19, 2026 18:17
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