Repository navigation
fix(core): retry snapshot capture when concurrent Git writes collide on Windows - #56190
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
The change looks sound. I couldn't verify it here because the race only happens on Windows and this environment is Linux, so Windows CI remains the real signal. Only a non-zero Git exit is retried; the cause === undefined check correctly skips failures to start Git. Both commands are safe to rerun: objects are named by their content, and update-index writes the index through a lock file, so a failed attempt leaves it unchanged. On the PR head, bun test test/snapshot.test.ts test/git.test.ts passes (27/27) and packages/core typechecks.
Public API is unchanged (internal change to packages/core/src/git.ts only).
No blocking concerns.
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.
Summary
Snapshot > captures concurrently from independent processesflakes on Windows CI (3 of the last 15 failedtest.ymlruns ondev, e.g. 38931653291). The diagnostics added in #56181 surfaced the cause:Independent processes capturing into the same snapshot store often write identical loose objects. On Windows, when two Git processes finalize the same object at the same moment, the loser gets a sharing violation instead of "already exists" and exits non-zero.
capture()is best-effort, so the snapshot is silently lost.Change
Only on Windows, the two commands that write objects,
update-index --add(blobs) andwrite-tree(trees), are retried up to 2 times (3 attempts total, 50 ms apart) when Git exits non-zero. Objects are content-addressed, so a retry finds the other process's copy in place. Only the failing command reruns; there is no new worktree scan.Unchanged behavior:
captureTreeis untouched.Trade-off: on Windows, a persistent failure in one of these two commands, such as an unreadable worktree file during
update-index, costs two extra runs of that command (~100 ms) before surfacing. Telling it apart from the race would mean matching Git's possibly localized stderr, which this code avoids elsewhere.Testing
bun typecheckinpackages/corebun test test/snapshot.test.ts test/git.test.ts --rerun-each 3The race did not reproduce locally (30/30 passes without the fix), so Windows CI is the real signal.