Repository navigation
fix(storage): a throttle stamp must write a non-empty payload so its mtime advances - #2213
gdamprint-cmyk wants to merge 4 commits into
Conversation
…mtime advances std::fs::write(path, b"") truncates but issues no WriteFile call for the empty buffer, so on Windows the mtime does not advance. claim_update_fetch_slot in src/cli/hot_exec.rs therefore never consumed its interval: every spawn ran git fetch again. touch_stamp writes b"1"; the content is never read back.
[Medium impact] The change reaches daemon cleanup and CLI update-check throttles. The PR should not merge until the Unix cleanup test can open its directory successfully. FindingsFix with agent prompt### Issue 1
crates/jcode-build-support/src/version_gc.rs:undefined-293
`make_version` passes a directory to this helper, but the non-Windows branch now opens it with `.write(true)`. Unix rejects write-only directory opens, so after fixing the missing import, `keeps_protected_recent_and_fresh_versions` still fails at the `.unwrap()`. Open the directory read-only, as the old `File::open` call did.
```suggestion
let file = std::fs::OpenOptions::new().read(true).open(path)?;
```
### Issue 2
crates/jcode-storage/src/lib.rs:undefined-874
If the temporary directory uses a filesystem with two-second timestamp steps, such as FAT, the two writes can get the same timestamp despite the 1.1-second sleep. The strict comparison then fails even though the helper works. The new test in `version_gc.rs` has the same issue.
Set the marker's mtime well into the past with `File::set_modified`, then call the helper and compare against the saved timestamp. This also removes the waits.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR adds
Reviews (4) · Last reviewed commit: "fix(build-support): keep the mtime helpe..." · Reviewed by Greptile |
| .and_then(|meta| meta.modified()) | ||
| .expect("mtime after empty write"); | ||
|
|
||
| std::thread::sleep(std::time::Duration::from_millis(1100)); |
There was a problem hiding this comment.
Timestamp tests can fail intermittently
If the temporary directory uses a filesystem with two-second timestamp steps, such as FAT, the two writes can get the same timestamp despite the 1.1-second sleep. The strict comparison then fails even though the helper works. The new test in version_gc.rs has the same issue.
Set the marker's mtime well into the past with File::set_modified, then call the helper and compare against the saved timestamp. This also removes the waits.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-storage/src/lib.rs
Line: 874
Comment:
**Timestamp tests can fail intermittently**
If the temporary directory uses a filesystem with two-second timestamp steps, such as FAT, the two writes can get the same timestamp despite the 1.1-second sleep. The strict comparison then fails even though the helper works. The new test in `version_gc.rs` has the same issue.
Set the marker's mtime well into the past with `File::set_modified`, then call the helper and compare against the saved timestamp. This also removes the waits.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Use one stamp writer for session and scratch pruning, build cleanup, and update-fetch throttling. Reopening an empty stamp does not reliably advance its mtime. Upstream: 1jehuang#2213 Co-authored-by: Guntrip <[email protected]>
Upstream-PR: 1jehuang#1357 Upstream-PR-Commit: 1jehuang#1357 0da5e81 Upstream-PR: 1jehuang#1362 Upstream-PR-Commit: 1jehuang#1362 5962058 Upstream-PR: 1jehuang#1486 Upstream-PR-Commit: 1jehuang#1486 fadc624 Upstream-PR: 1jehuang#1733 Upstream-PR-Commit: 1jehuang#1733 01f3415 Upstream-PR: 1jehuang#1750 Upstream-PR-Commit: 1jehuang#1750 1ac0c82 Upstream-PR: 1jehuang#1822 Upstream-PR-Commit: 1jehuang#1822 73f85fc Upstream-PR: 1jehuang#1912 Upstream-PR-Commit: 1jehuang#1912 36d7682 Upstream-PR: 1jehuang#1978 Upstream-PR-Commit: 1jehuang#1978 0f55643 Upstream-PR: 1jehuang#2007 Upstream-PR-Commit: 1jehuang#2007 638f87c Upstream-PR: 1jehuang#2213 Upstream-PR-Commit: 1jehuang#2213 c5e1487 Upstream-PR: 1jehuang#2234 Upstream-PR-Commit: 1jehuang#2234 0d4d5d4 Upstream-PR: 1jehuang#2266 Upstream-PR-Commit: 1jehuang#2266 217ddc2 Upstream-PR: 1jehuang#2267 Upstream-PR-Commit: 1jehuang#2267 e98c40b
…imestamp resolution
|
|
||
| #[cfg(not(windows))] | ||
| fn set_mtime_on_handle(path: &Path, when: std::time::SystemTime) -> std::io::Result<()> { | ||
| let file = fs::OpenOptions::new().write(true).open(path)?; |
There was a problem hiding this comment.
make_version passes a directory to this helper, but the non-Windows branch now opens it with .write(true). Unix rejects write-only directory opens, so after fixing the missing import, keeps_protected_recent_and_fresh_versions still fails at the .unwrap(). Open the directory read-only, as the old File::open call did.
| let file = fs::OpenOptions::new().write(true).open(path)?; | |
| let file = std::fs::OpenOptions::new().read(true).open(path)?; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-build-support/src/version_gc.rs
Line: 293
Comment:
**Unix cleanup test fails**
`make_version` passes a directory to this helper, but the non-Windows branch now opens it with `.write(true)`. Unix rejects write-only directory opens, so after fixing the missing import, `keeps_protected_recent_and_fresh_versions` still fails at the `.unwrap()`. Open the directory read-only, as the old `File::open` call did.
```suggestion
let file = std::fs::OpenOptions::new().read(true).open(path)?;
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
Want your agent to iterate on Greptile's feedback? Try greploops. |
Problem
A "touch this marker to start the throttle window" helper wrote an empty payload. Upstream
master, measured:std::fs::write(path, b"")truncates the file but issues noWriteFilecall for an empty buffer, so onWindows the mtime does not advance. Every later pass then reads the same old mtime,
age < INTERVALstaysfalse, and the guarded work runs again on every spawn instead of once per interval.
Fix
Add one helper in
crates/jcode-storage/src/lib.rs:The marker's content is never read back, so the payload is only a carrier that forces the write to reach the
filesystem.
Call sites converted (all were writing
b""):src/cli/hot_exec.rsclaim_update_fetch_slotcrates/jcode-base/src/scratch_maintenance.rsmark_prunedcrates/jcode-base/src/session/maintenance.rsclaim_prune_slotcrates/jcode-build-support/src/version_gc.rsmark_prunedTests
jcode-storage,mod stamp_tests:touch_stamp_writes_a_non_empty_payload- the file must be non-empty, which is the property an empty writeviolates.
touch_stamp_advances_the_marker_mtime- captures the mtime after an empty write, sleeps 1.1 s, then assertstouch_stampmoves it forward. This is the negative control: it proves the test exercises the differencerather than passing on a filesystem with coarse timestamps.
jcode-build-support,mod stamp_marker_tests:mark_pruned_advances_the_marker_mtimeprune_due_is_false_right_after_a_passVerification (real runs, Windows, dedicated
CARGO_TARGET_DIR)Branch is based on
upstream/master(9de9fdcc2).Why this is the general form
Upstream's own
2f8957ca6("cut idle battery drain: stamp-gated git polling") introduced a stamp in the sameshape, so a non-empty payload is the correct contract for any stamp that is supposed to move an mtime. This PR
does not change
2f8957ca6; it repairs the calls that still wroteb"".Linked issue
Closes #2286
Reviewer notes (updated after push)
Greptile's P2 was correct about the shape and was fixed in
e8f9d08ac, together with a second instance of the same defect that it did not see:mark_pruned_advances_the_marker_mtimeno longer sleeps 1.1 s. It rewinds the marker by a minute first and asserts thatmark_prunedmoves it forward, so the test cannot pass merely because a sleep crossed a timestamp tick and cannot fail on a filesystem whose granularity is coarser than the sleep.make_versionopened its directory read-only and then calledset_modified, which isPermissionDenied(os error 5) on Windows before the test reaches any assertion. Opening a directory there needsFILE_FLAG_BACKUP_SEMANTICSplusFILE_WRITE_ATTRIBUTES; the combination is documented by std's ownremove_dir_all.Verification after the change, Windows:
The remaining failures in
cargo test -p jcode-build-support --lib(paths.rs,tests.rs) and the twoneedless_returnclippy errors injcode-storageare pre-existing on this branch's base commitcc85b4c02: re-running the same commands with this PR's diff stashed reproduces them. They are outside this PR's scope.