Repository navigation
fix(process-host): let a slow Windows taskkill finish instead of orphaning the grandchild - #29501
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
…aning the grandchild Co-Authored-By: Claude <[email protected]>
…t cannot walk a reissued pid Co-Authored-By: Claude <[email protected]>
72901ef to
ff799ba
Compare
…nder load Co-Authored-By: Claude <[email protected]>
…th list Co-Authored-By: Claude <[email protected]>
…; cap the background taskkill at 30 s Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Do not abandon an active tree kill when the root exits. · windows-tree-kill.ts:90-113
src/packages/process-host/src/windows-tree-kill.ts:90-113
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftDo not abandon an active tree kill when the root exits.
When the root emits
exit, the 2-second timer callskiller.kill()andfinish('unverifiable').finishthen callskillRoot(), which can only target the already-exited root. Iftaskkill /t /fis still terminating descendants, this can leave the grandchild alive. The PID-reuse guard does not prove that an active tree walk has finished.Track whether
taskkillhas reached the tree, and keep an active tree walk alive until it completes. Apply the PID-reuse abandonment only to a taskkill that has not started traversal.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4090098d-aaac-4d4d-8865-8e75bbef5d7b
📒 Files selected for processing: 5
src/packages/process-host/src/process-tree-termination.test.tssrc/packages/process-host/src/run-process-windows-tree-kill.test.tssrc/packages/process-host/src/run-process.tssrc/packages/process-host/src/windows-tree-kill.tssrc/shared/__tests__/process-host/windows-tree-kill-late-taskkill.win32.test.ts
🚧 Files skipped from review as they are similar to previous changes: 1
- src/shared/tests/process-host/windows-tree-kill-late-taskkill.win32.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
ELI5
When Orca stops a command on Windows, it asks Windows'
taskkilltool to end the command and everything the command started. On a busy machinetaskkillcan take many seconds. Orca used to give up after 5 seconds, kill only the top process, and leave the command's children running. Now Orca stops waiting after 5 seconds but letstaskkillkeep going in the background until it finishes. Nothing new waits on that background cleanup: the next git command is not held for it.What Changed
Before (Windows, loaded machine): a git command (or any other "termination barrier" command) times out or is cancelled.
taskkill /t /fis still walking the process tree when its 5 s cap hits. Orca kills thattaskkill, then kills the top process directly. With the top process gone,taskkillcan no longer find its children, so they (for example anodestarted by a.cmd) keep running.After:
taskkillper process tree (newsrc/packages/process-host/src/windows-tree-kill.ts). It is keyed by the child-process handle, not the pid, so a reused pid can never join another tree's kill. A second stop or force request for the same child joins the runningtaskkillinstead of starting another one.taskkillis not done. Thetaskkillitself keeps running for up to 30 s.taskkillis still running. Killing it early is exactly what orphaned the children. The tracked kill does the root-by-handle fallback itself, only oncetaskkillhas failed or been abandoned.taskkillis abandoned 2 s after the top process exits. Once the top process is gone, Windows may hand its pid to another process (possibly one of Orca's own, Windows PTY teardown: ancestryownis not true root identity (PID recycle into Orca tree) #10680), and a late-startingtaskkill /pidwould walk that tree instead. Within those 2 s ataskkillthat itself killed the top process can still report success. The old code's exposure window was 5 s, so this is no wider than before.live(taskkill still working),exited(taskkill reported success, the only proof),unverifiable(taskkill failed or ran out of time). Nothing else is reported as dead.runProcessbarrier (run-process.ts):taskkillsuccess still verifies the barrier and settles the caller right away.taskkillproves the tree dead. This signal is what returns the git admission slot.win32branch, and the new lookups return nothing on other platforms.Git commands after a stopped git command (before / after)
The git "admission" slot is one of Orca's 2–4 shared git concurrency slots. It is not a lock on the repository. The per-repo operation lock is held only by the caller's own wait, which is unchanged.
taskkillfast (idle machine)taskkillslow, grandchild holds the pipes (the measured case)taskkillfinishes (7.7–9.0 s measured)taskkillslow, nothing holds the pipestaskkillfinishes, at most 30 sWhat a longer hold would protect, and why there isn't one. A git process killed with
taskkill /fcannot clean up after itself. Anyindex.lockit held stays behind whether or not Orca waits for it to die. Refs are written by lock-and-rename, so a killed git leaves a stale.lock, never a half-written ref. Holding later git commands until the tree is confirmed dead would therefore prevent no failure. An earlier revision of this PR kept the slot past the top process's exit (at most 2 s); that is removed.A narrower "retry when the next git hits
index.lockwhile a kill is in flight" was considered and not added. The lock a force-killed git leaves is stale, so a brief wait or retry would not clear it. Only one git path uses this barrier today: pull-with-rebase from the base branch, on its timeout or cancel.Why
Measured on GitHub windows-2022 runners loaded with 2× CPU burners (see closed draft #28573): bare
taskkill /t /ftook 4.6–18 s (about 50 ms idle). With a 2 s cap the grandchild survived 8/8 runs; with a 15 s cap it was killed 8/8. #28577 raised the cap to 5 s, which is still inside the measured range, so a loaded machine still leaks children. Any fixed cap is a guess at the tail.Alternatives considered:
Linked Issue
N/A (maintainer PR). Follows the design suggested in the review of closed draft #28573; replaces the cap-only mitigation from #28577.
Visual Proof
N/A: process termination behavior, no UI.
Testing
windows-tree-kill.test.ts): success; late success after the caller's wait; joining an in-flight kill; no respawn after a proven kill; failure, spawn error, and launch throw becomeunverifiablewith a root kill and an allowed retry; the 30 s deadline; reused-pid isolation.runProcessbarrier tests on a simulated Windows host (run-process-windows-tree-kill.test.ts): the root is not killed whiletaskkillis in flight; a late success settles the caller; "child terminated" is reported on root close as before, while a latetaskkillsuccess still settles the caller; after the 30 s abandon the root is killed.process-tree-termination.test.tsupdated for the wait-versus-deadline split.windows-tree-kill-late-taskkill.win32.test.ts, added topackage (windows)): a.cmdstarts a hangingnodegrandchild;taskkillis started 8 s late (longer than the caller's 5 s wait); the test proves the grandchild is dead. A second CI step runs the same file with CPU burners (2× cores) and also runs the unmodifiedtaskkillunder that load.package (windows)job was blocked by unrelated failures onmainat the time). 6 job runs, all green; each runs the delayed test once idle and three times under 2× CPU burners, plus the realtaskkillunder burners three times. 42 out of 42 runs killed the grandchild.taskkillunder load took 7.7–9.0 s in all 18 loaded runs, which is past the old 5 s cap. Before this change, the cap would have cut each of those walks short.taskkillexited with code 255, not 0, in all 3 loaded runs (a process in the tree exited on its own mid-walk). The tree is reportedunverifiable, notexited. The grandchild is still dead, and the caller settles at the existing timeout + 15 s bound.package (windows)job: 1 run plus 3 reruns, all green. The realtaskkillunder load took 7.8–8.9 s, with exit code 255 each time; the grandchild was killed every time.vitest(macOS) on process-host, git command-runner, OpenCode, ripgrep, and preflight suites passes.AI Disclosure
Review
Agent skill upstream boundary
Notes
taskkill; unchanged.signalProcessTree(hooks, notebook kernel, WSL ripgrep stop, OpenCode preflight): they now share onetaskkillper child instead of starting a second one on force, and the top process is killed only aftertaskkillgives up instead of at 5 s.taskkillthat is still running, with the top process still alive, keeps that process's shared git slot until it finishes (at most 30 s). That is the same rule as before: the slot is returned when the top process's pipes close.taskkillexit code other than 0 (including 255 from a benign race) is never treated as proof. On a loaded machine, those callers wait the existing 10 s unverified grace.taskkill, so they don't get the late-success hook.killSpawnedCommandTree) termination paths have their owntaskkillcode.taskkill.exeper tree, now at most one at a time.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)