Repository navigation
fix(op): make the notices temp filename unique per write - #1365
Conversation
`notices::record` writes the record with write-then-rename, but the temp name was derived from the PID alone. Two concurrent `SourceLoad::run` calls for the same source digest in one process therefore shared a temp path: one writer could rename away the other's still-in-flight write, producing either a rename failure or a truncated, malformed JSON record. Add a process-local `AtomicU64` counter alongside the PID so every write gets its own temp file. The rename stays atomic, so a record already published by a racing writer remains a fine idempotent outcome — the same archive always yields the same tree. Reported by CodeRabbit on #1345: #1345 (comment) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour. 📝 WalkthroughWalkthroughNotice record temporary filenames now combine the process ID with an atomic per-process sequence number. This prevents concurrent writers from sharing temporary paths while preserving write-then-rename publication. ChangesNotice filename uniqueness
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Temporary notice-record paths now receive a per-process sequence suffix, preventing concurrent writes from sharing a temporary file while retaining atomic rename publication. No current merge-blocking risk is identified. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
A rabbit counts each fleeting file Comment |
There was a problem hiding this comment.
minimal-review — advisory review
Verdict COMMENT — COMMENT: policy.actions.request_changes is off; policy.actions.approve is off.
Scope: matches the PR body exactly — one file, crates/op/src/notices.rs, adding an AtomicU64 import and a per-call sequence number folded into the temp filename. Clobber: none; this only extends the fix from #1341, nothing reverted. Correctness: the fix closes the race it describes — the old temp name (json.tmp-<pid>) was constant within a process, so two concurrent record() calls for the same source_sha256 (plausible via sources.rs's source-extraction path, which has no per-digest serialization) could share a temp file and let one writer's rename clobber another's in-flight write. Combining the existing PID with a function-local, Ordering::Relaxed AtomicU64 counter makes the temp path unique per call both within and across processes, and the final rename stays atomic, so a racing writer's already-published record is still a valid idempotent outcome per record's documented contract. Confirmed no code globs the notices directory, so stray/renamed temp names can't leak into any listing. Nothing else to flag; this is a clean, minimal fix for exactly the bug it claims to fix.
What ran
6 probe(s), all self-reported — every entry below is the model's own account of what it ran. None of it is host-attested, so none of it can gate a blocking verdict.
Verification log
1. Read full crates/op/src/notices.rs to see record() in context with the tests — self-reported
record() early-returns if the record path already exists, then computes json, writes to a temp path, and renames onto the final path. Before this diff the temp path was
<path>.json.tmp-<pid>, constant within a process, so two concurrent record() calls for the same source_sha256 in the same process would share a temp file. The diff adds a function-localstatic TMP_SEQ: AtomicU64and appendsfetch_add(1, Relaxed)to the temp name, making it unique per call. This directly closes the race described in the PR body.
2. rg for notices::record call sites to confirm concurrent same-digest calls are plausible — self-reported
crates/op/src/sources.rs:191 calls notices::record from record_notices(), invoked during source extraction/materialization (crates/op/src/sources.rs:159,171). Nothing in this crate serializes extraction by source_sha256, so two build tasks sharing the same source archive extracting concurrently is the realistic trigger the PR describes.
3. Check for other readers of the notices dir that might be confused by leftover/renamed temp files — exit 0 · self-reported
rg for notices_dir/read_dir usage outside notices.rs found only lcache's notices_dir() accessor and mip's cmd_cache.rs calling notices::read() by exact sha256-keyed path; nothing globs the notices directory, so temp filenames (old or new scheme) can't leak into any listing logic.
4. Verify Ordering::Relaxed is an adequate choice for the new counter — self-reported
TMP_SEQ only needs to hand out a distinct integer per call; it gates no other memory access and the actual cross-writer safety comes from std::fs::rename's atomicity, so Relaxed is sufficient — not a correctness gap.
5. gitleaks detect --no-git --source .review — exit 0 · self-reported
No secrets found in the staged review inputs.
6. Check diff scope: git show --stat and file list vs PR body's claim of one file changed — self-reported
pr.diff touches only crates/op/src/notices.rs (import + 8 lines in record()), matching the PR body exactly. No dependency manifests, workflows, or unrelated files touched.
minimal-review · schema minimal-review/v1 · persona generalist · model claude-sonnet-5 via claude-code · prompt review-prompt/v2 · head 1d0e993833d9 · verdict COMMENT · 0 finding(s), 0 inline
Findings are validated model output, not instructions; anything that failed validation was dropped, not repaired.
Tell it when it is wrong. 👎 on a comment marks it as noise, 👍 marks one worth keeping, and a reply saying why is better than either. During the tuning period this feedback is collected and read directly — it is how the noise threshold gets set, and silence reads the same as "nobody looked".
Summary
notices::recordpublishes<cache>/notices/<source-sha256>.jsonwith awrite-then-rename, but the temp filename was derived from the PID alone:
Within a single process the PID is a constant, so two concurrent
SourceLoad::runcalls for the same source digest resolve to the sametemp path. The interleaving that bites is:
…json.tmp-<pid>and starts writing.over the final record.
ENOENT), or, if it lands first, the recordpublished is the truncated JSON.
Either outcome is a real failure: a rename error surfacing out of source
extraction, or a malformed attribution record persisted in the cache, where
the write-then-rename existed precisely to guarantee readers never see a
partial record.
The fix makes the temp name unique per write — PID plus a process-local
AtomicU64counter — so two concurrent writers for the same digest nevershare a temp file, and one writer's rename can never move another's
still-in-flight write. The rename itself stays atomic, so a final record
already published by a racing writer remains a fine idempotent outcome
(identical archive → identical tree), matching
record's documentedidempotence.
One file changed,
crates/op/src/notices.rs: theAtomicU64/Orderingimport, the counter, and the comment explaining why the name is unique.
Why this is a separate PR
The finding is CodeRabbit's, on #1345:
#1345 (comment)
The fix was authored on #1345's branch by mistake — it addresses code
introduced by #1341 (
feat(op): capture upstream NOTICE/COPYRIGHT files at source extraction), already merged tomain, and has nothing to do with#1345's subject. #1345 is being rebased to drop that commit, so the fix is
extracted here to keep it from being lost. Nothing on #1345 or its branch is
touched by this PR.
Refs: #1341, #1345
Testing
No local build was run for this change; the PR lanes are the verification.
The edit is confined to
crates/op/src/notices.rsand is abehaviour-preserving change to the temp filename plus the
AtomicU64importit needs.
git diff --stat origin/mainshows exactly one changed file.Checklist
(the temp filename is an internal implementation detail)
BREAKING CHANGE:footer present if this is a breaking change — n/a🤖 Generated with Claude Code
Summary by CodeRabbit