fix(kit): retry promote() retire-rename on Windows ACCESS_DENIED - #3917
Merged
Conversation
On Windows, os.Rename fails with ERROR_ACCESS_DENIED when another goroutine holds an open handle to the directory being renamed aside. Concurrent Build() calls for the same agent hit this in the retire step of promote(): one goroutine holds finalDir open while another tries to move it to a .old-... sibling. Add a build-tagged helper isRetryableRenameErr() — Windows checks errors.Is(err, syscall.ERROR_ACCESS_DENIED); all other platforms return false unconditionally so POSIX EACCES is still a hard error. In the retire-rename error path, treat a retryable error as a loop continuation rather than a hard failure: increment attempt, yield (runtime.Gosched) so the competing goroutine can release its handle, then retry with a fresh unique sibling name. Fixes TestBuild_ConcurrentRunsForSameAgentAreSafe on Windows (CI run 31013010316, job 92330933439).
aheritier
marked this pull request as ready for review
August 5, 2026 20:29
trungutt
approved these changes
Aug 6, 2026
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.
Fixes
TestBuild_ConcurrentRunsForSameAgentAreSafefailing on Windows in CI run 31013010316.Root cause:
promote()inpkg/sandbox/kit/kit.gorenamesfinalDiraside (to a.old-…sibling) before atomically installing the new kit. On Windows,os.Renamefails withERROR_ACCESS_DENIEDwhen another goroutine holds an open handle to that directory. ConcurrentBuild()calls for the same agent hit this exactly.Fix: Add a build-tagged helper
isRetryableRenameErr():rename_windows.go(//go:build windows): returnserrors.Is(err, syscall.ERROR_ACCESS_DENIED)rename_other.go(//go:build !windows): always returnsfalseIn the retire-rename error path, treat a retryable error as a loop continuation (set
lastErr, callruntime.Gosched()to yield to the competing goroutine, thencontinue) instead of returning hard. On POSIX,EACCESon a rename is a genuine hard error and the path is unchanged.Testing:
TestBuild_ConcurrentRunsForSameAgentAreSafepasses on POSIX; the Windows path compiles cleanly (GOOS=windows go build/vet).Reviewer note: The reviewer noted that
isRetryableRenameErrhas no Windows unit test (since CI doesn't run Windows-tagged tests on Linux). The function is a singleerrors.Iscall with no branch; correctness is covered by the concurrent integration test in Windows CI.