Repository navigation
fix(subagent): make Windows temporary directory cleanup non-fatal - #358
Merged
Merged
Conversation
… host on failure On Windows the web host exited with an unhandled `EPERM: operation not permitted, rmdir ...\Temp\stepcode-subagent-*`. Exit handling runs from both `close` and `exitStatus`, so two unawaited `rm(tempDir)` calls raced on the same directory; on Windows the second rmdir fails with EPERM while the first deletion is pending, and the bare `void rm(...)` rejection terminated the process. - remove the temp dir at most once, with retries for transient locks - swallow removal failures (best effort under the OS temp root) - skip terminate's rmSync when an async removal is already in flight
…ults Guard duplicate exit notifications, retry worktree cleanup without masking task outcomes, and verify synchronous and asynchronous cleanup ownership. Make real-child test teardown wait for Windows cwd locks and document cleanup boundaries.
ZouR-Ma
requested review from
MelodyVAR,
Uking-xxx and
liuedcson
as code owners
November 14, 2026 08:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An RPC subagent creates a temporary prompt directory. Both the child's
closeevent and bounded exit drain finalized the same exit and started independent
unawaited removals. On Windows those removals can race and reject with
EPERM;the unhandled rejection terminates the embedding host.
Changes
and retry transient filesystem errors three times with 100 ms linear backoff.
terminate()cleanup fromracing asynchronous cleanup, and skip another removal after synchronous success.
preserve the original Git allocation error when its cleanup also fails.
tests allow Windows to release the child's working directory before teardown.
Behavior and compatibility
No CLI options, RPC frames, stored session formats, provider behavior or permissions
change. Cleanup is best effort under the OS temporary directory. A locked directory
may remain after bounded retries; it must not change an already-completed task's
outcome. Unknown exceptions retain the existing host policy: this PR adds no global
unhandled-rejection suppression. This main branch has no Web application.
Validation
Windows, Node v24.22.1:
packages/coding-agent:pnpm exec vitest run test/subagent test/step-capabilities-extension.test.ts— 13 files, 87 tests passed.
pnpm run check— exit 0. Biome reports one pre-existing informationaluseTemplatediagnostic intest/step-subagent-events.test.ts; no formatter changes.invokes removal twice. The original success-path worktree cleanup fails the
completed-result regression.
git diff --check— passed.bash ./test.sh— not completed: its offline prebuild stops atscripts/build-coding-agent-bundle.mjs:183withspawnSync npm ENOENTon Windows,before the full repository tests start. This is not a passing full-suite claim.
Limitations
CI results and maintainer approval are pending. The prebuild blocker above remains
outside this subagent cleanup repair. No merge or release has been performed.