Repository navigation
Conversation
📝 WalkthroughWalkthroughAdds a Windows process-tree termination helper using 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9855eab8-811b-4ea7-a6ef-75ded1886c6e
📥 Commits
Reviewing files that changed from the base of the PR and between 8685cdb and 60ca616ac60ef3e97d1097a9c7650088c43abbcc.
📒 Files selected for processing (6)
src/main/providers/local-pty-provider.test.tssrc/main/providers/local-pty-provider.tssrc/main/pty-descendant-termination.test.tssrc/main/pty-descendant-termination.tssrc/main/windows-process-tree-kill.test.tssrc/main/windows-process-tree-kill.ts
Sync update (
|
Windows agent teardown previously degraded to shell-only kill because descendant snapshot is POSIX-only. Orphaned claude/codex/MCP children kept worktree cwd handles open and blocked worktree remove. Use taskkill /T /F on the PTY root in killWithDescendantSweep (daemon + local agent shutdown) so the ConPTY tree is cleared before teardown. Fixes stablyai#10004
Prevent a wedged taskkill from delaying killRoot, and hide the console flash during agent PTY tree teardown (CodeRabbit on stablyai#10100).
84dbdab to
7373001
Compare
|
Thanks so much for this, @innocarpe — taskkill agent PTY descendant trees on stop. Verified (fail-on-main/pass-on-branch), reviewed, and merged. Really appreciate it! 🙏 |
* fix(win): taskkill plain-shell PTY trees on immediate teardown Deleting a Windows worktree that still has a live process in a terminal tab (a `pnpm i`, or any command that spawns a child tree) failed with "Failed to physically stop every PTY for worktree" after the full 10s teardown deadline. Root cause: on Windows, closing a plain shell's ConPTY does not reap its orphaned children — node-pty's `useConptyDll` skips the console-process reap. A live `pnpm i`/`node` child survives the shell's exit, keeps the ConPTY console non-empty (so the daemon still reports the session alive), and holds the worktree cwd handle. The destructive-removal physical-stop check then fails closed. #10100 fixed this for agent sessions (killWithDescendantSweep -> taskkill /T /F) but plain shells were never swept. Fix: extend the Windows taskkill /T /F descendant tree-kill to non-agent shells on the immediate/destructive teardown path, in both the daemon (TerminalSessionTeardown) and local provider. Gated to win32 + immediate with the same ownsRoot guard so a naturally-exited/recycled PID is never signalled; POSIX shells keep reaching their child pgroup via forceKill and are unchanged. Reproduced and verified end to end via the Electron dev build: a worktree with a live node child previously failed to delete after 10s; with the fix the child tree is taskkilled, the directory is removed, and the delete succeeds in ~1.8s. * fix(win): claim plain-shell termination before the taskkill sweep forceKillAndWaitForExit sets _isTerminating in its synchronous prologue. Awaiting the Windows descendant sweep ahead of it left createOrAttach's doomed-session guard open for the taskkill's duration, so a concurrent attach could bind a pane to a session about to be tree-killed.
On Windows, ConPTY shell-only kill left npm/dev-server children listening, so switching projects could still serve the previous app on the same port. - taskkill /T /F via killWithDescendantSweep for every local PTY stop on Windows - Ports UI kill path also tree-kills on Windows - Keep POSIX agent-only descendant sweep; plain POSIX terminals unchanged Closes stablyai#10150 Related: overlaps Windows agent path of stablyai#10004 / stablyai#10100
On Windows, ConPTY shell-only kill left npm/dev-server children listening, so switching projects could still serve the previous app on the same port. - taskkill /T /F via killWithDescendantSweep for every local PTY stop on Windows - Ports UI kill path also tree-kills on Windows - Keep POSIX agent-only descendant sweep; plain POSIX terminals unchanged Closes stablyai#10150 Related: overlaps Windows agent path of stablyai#10004 / stablyai#10100
* fix(win): taskkill agent PTY descendant trees on stop Windows agent teardown previously degraded to shell-only kill because descendant snapshot is POSIX-only. Orphaned claude/codex/MCP children kept worktree cwd handles open and blocked worktree remove. Use taskkill /T /F on the PTY root in killWithDescendantSweep (daemon + local agent shutdown) so the ConPTY tree is cleared before teardown. Fixes stablyai#10004 * fix(win): bound taskkill with timeout and windowsHide Prevent a wedged taskkill from delaying killRoot, and hide the console flash during agent PTY tree teardown (CodeRabbit on stablyai#10100).
…yai#10339) * fix(win): taskkill plain-shell PTY trees on immediate teardown Deleting a Windows worktree that still has a live process in a terminal tab (a `pnpm i`, or any command that spawns a child tree) failed with "Failed to physically stop every PTY for worktree" after the full 10s teardown deadline. Root cause: on Windows, closing a plain shell's ConPTY does not reap its orphaned children — node-pty's `useConptyDll` skips the console-process reap. A live `pnpm i`/`node` child survives the shell's exit, keeps the ConPTY console non-empty (so the daemon still reports the session alive), and holds the worktree cwd handle. The destructive-removal physical-stop check then fails closed. stablyai#10100 fixed this for agent sessions (killWithDescendantSweep -> taskkill /T /F) but plain shells were never swept. Fix: extend the Windows taskkill /T /F descendant tree-kill to non-agent shells on the immediate/destructive teardown path, in both the daemon (TerminalSessionTeardown) and local provider. Gated to win32 + immediate with the same ownsRoot guard so a naturally-exited/recycled PID is never signalled; POSIX shells keep reaching their child pgroup via forceKill and are unchanged. Reproduced and verified end to end via the Electron dev build: a worktree with a live node child previously failed to delete after 10s; with the fix the child tree is taskkilled, the directory is removed, and the delete succeeds in ~1.8s. * fix(win): claim plain-shell termination before the taskkill sweep forceKillAndWaitForExit sets _isTerminating in its synchronous prologue. Awaiting the Windows descendant sweep ahead of it left createOrAttach's doomed-session guard open for the taskkill's duration, so a concurrent attach could bind a pane to a session about to be tree-killed.
fix(win): taskkill agent PTY descendant trees on stop
Summary
On Windows, stopping an agent terminal now kills the whole ConPTY process tree, so orphaned agent/MCP children no longer hold the worktree open and block removal.
ELI5
When you closed an agent terminal on Windows, Orca only stopped the shell — the agent and its helper processes kept running and locked the folder, so deleting the worktree failed. Now Orca tells Windows to kill that entire process family.
Root cause & fix
Agent teardown used a POSIX
psdescendant snapshot that is a no-op on Windows, so only the shell root was killed while Claude/Codex and their MCP children reparented, kept the worktree cwd handle, and madeworktrees:removefail with "Failed to physically stop every PTY" (#10004).killWithDescendantSweep()now branches on platform: Windows runstaskkill /pid <root> /T /F(5s timeout,windowsHide) to walk the ConPTY tree beforekillRoot, while POSIX keeps the existing snapshot + signal path. Anytaskkillfailure or timeout is swallowed sokillRootalways runs.Evidence
Validated & rebased onto latest main during a bug-bash triage on 2026-07-23.
origin/main(base8a23618310, head84dbdab7ad).pty-descendant-termination.test.ts,windows-process-tree-kill.test.ts,local-pty-provider.test.ts.windows-process-tree-killimport is absent on main, and the providervi.mockerrors because the wiring moved tokillWithDescendantSweep. Restored fix → 119 passed again.oxlinton all three source files reports no warnings/errors.Trade-offs
None — pure fix.
taskkill /T /Fis force-kill, but matches the pattern already used for git/codex/relay cancellation on Windows and ConPTY stop was already force-oriented.Regression risk
Zero on macOS/Linux: the POSIX branch keeps the identical snapshot + signal +
killRootsequence. The new behavior is Windows-only, gated on agent-session membership,ownsRoot, and valid-pid checks, andtaskkillis invoked only onwin32. Everytaskkillerror is caught so root kill always proceeds. Proven by the passing branch tests that fail when the fix is reverted.Original fix by @innocarpe. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.