fix(agents): don't crash autoreview copilot engine on Windows temp-dir cleanup (#97901)

On Windows the spawned copilot process and its MCP subprocesses keep the
TemporaryDirectory as their cwd briefly after exit, holding a directory handle.
That makes TemporaryDirectory's rmtree raise PermissionError (WinError 32) on
__exit__, aborting the run with a traceback even though the review completed
successfully. Pass ignore_cleanup_errors=True so cleanup is best-effort and a
post-review cleanup race never fails the run.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Campbell
2026-07-01 03:08:29 -07:00
committed by GitHub
co-authored by Copilot
parent dff45cae4c
commit 99bce5fef4
+5 -1
View File
@@ -624,7 +624,11 @@ def run_copilot(args: argparse.Namespace, repo: Path, prompt: str) -> str:
raise SystemExit("--thinking is not supported by the copilot engine")
if not args.tools:
raise SystemExit("--no-tools is not supported by the copilot engine; copilot requires a read-only file view tool to load the review bundle without exposing it in argv")
with tempfile.TemporaryDirectory(prefix="autoreview-copilot.") as tempdir:
# ignore_cleanup_errors: on Windows the spawned copilot process (and its MCP
# subprocesses) keep `tempdir` as their cwd briefly after exit, holding a directory
# handle that makes rmtree fail with WinError 32. The review already completed, so a
# cleanup race must not abort the run; best-effort delete is correct here.
with tempfile.TemporaryDirectory(prefix="autoreview-copilot.", ignore_cleanup_errors=True) as tempdir:
prompt_path = Path(tempdir) / "prompt.txt"
prompt_path.write_text(prompt)
os.chmod(prompt_path, 0o600)