Repository navigation
Commit aefa482
fix(agent-cli): Windows temp-cwd cleanup must not fail a successful batch (NVIDIA#317)
On Windows, run_agent_cli's TemporaryDirectory raised WinError 32 at
__exit__ whenever any live process still held the per-invocation temp
cwd — and the agent CLI's process tree routinely does: the binary is a
.cmd shim whose node children can outlive the direct child, and a
killed-but-unreaped child on the timeout path holds its cwd too. A
directory that is any live process's working directory (or contains any
open handle) cannot be removed on Windows, so cleanup raised *after* the
model had already answered, and llm_analyzer_base recorded the batch as
llm_batch_failed. Under batch concurrency the teardown window widens,
which is why multi-file scans failed while single-file scans passed
(NVIDIA#315). Each invocation already has a unique mkdtemp directory, so this
was never a cross-worker path collision; it is delete-at-exit racing the
process tree's teardown.
Fix: mkdtemp + explicit best-effort cleanup. _cleanup_temp_dir retries
briefly (10 x 0.2s) to reclaim the directory once the holder exits, then
leaks it with a warning instead of raising. A cleanup failure never
outranks a successful response.
Verified on Windows 10 with a mechanism-faithful fake CLI (a .cmd shim
that detaches a grandchild holding the temp cwd): 8 concurrent batches
fail 8/8 with the exact WinError 32 signature from NVIDIA#315 on main, and
pass 8/8 with this change. Controlled experiments confirm both hold
modes (another process's cwd; an open file handle inside the dir) block
rmtree with WinError 32.
Tests: 5 new cases including a Windows-only real-handle hold and a
regression test asserting run_agent_cli returns the response when rmtree
keeps failing. tests/unit/test_agent_cli.py 87/87 on Windows.
Closes NVIDIA#315
Signed-off-by: ppcvote <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>1 parent bfdcd5e commit aefa482
2 files changed
Lines changed: 132 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
632 | 633 | | |
633 | 634 | | |
634 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
635 | 667 | | |
636 | 668 | | |
637 | 669 | | |
| |||
767 | 799 | | |
768 | 800 | | |
769 | 801 | | |
770 | | - | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
771 | 808 | | |
772 | 809 | | |
773 | 810 | | |
| |||
792 | 829 | | |
793 | 830 | | |
794 | 831 | | |
| 832 | + | |
| 833 | + | |
795 | 834 | | |
796 | 835 | | |
797 | 836 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
733 | 733 | | |
734 | 734 | | |
735 | 735 | | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
0 commit comments