Skip to content

fix: preserve cached captures when snapshot names collide - #257

Merged
vincentkoc merged 1 commit into
mainfrom
fix/cache-snapshot-collisions
Nov 18, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/cache-snapshot-collisions

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Taking two file-cache snapshots with the same name within one second can silently replace the first capture. Concurrent callers can all report success even though only the last caller's bytes remain.

User Impact

An existing capture is preserved. A colliding capture returns an already-exists error instead of overwriting it. The cache filesystem must support hard links; unsupported filesystems return a publication error.

Why This Change Was Made

Publish the completed private copy with an atomic operation that cannot replace an existing name, then remove its temporary name. This follows the repository's existing publication pattern. Filenames and API signatures remain unchanged.

Evidence

  • Before the fix, a second capture replaces the first one's bytes and all four concurrent publishers report success. Afterward, the first capture remains unchanged and exactly one concurrent publisher succeeds.
  • Tests verify complete contents and no leftover temporary files. Cache tests and the collision regressions pass under the race detector.
  • Full tests, static checks, module checks, and independent review passed. Tests use temporary files only.
Validation and review pins

Passed cache tests, GOWORK=off go test -race -count=1 ./cache -run '^TestSnapshotFile(PreservesExistingCapture|ConcurrentCollision)$', module tidiness with unchanged module files, vet, full uncached Go tests, formatting and diff checks.

Independent native P0–P3 review: no findings. Base: 798b6806ab443ee4282c1739f65e17f46e6f0328. Complete candidate: d65f22b8863ecddda90431fb05c84fd37bc820c0. Scope: complete diff, file copying, naming tests, and the existing publication pattern; isolated read-only review.

@clawsweeper

clawsweeper Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@vincentkoc
vincentkoc marked this pull request as ready for review November 18, 2026 08:18
@vincentkoc
vincentkoc merged commit bf9bdd1 into main Nov 18, 2026
8 checks passed
@vincentkoc
vincentkoc deleted the fix/cache-snapshot-collisions branch November 18, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant