Repository navigation
recipes: reuse stable source hashes during reach validation - #875
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: the change reuses the existing HashCache for source hashes, and I found no input where a stale hash can be served.
Non-blocking
⚠ A file that keeps changing now raises RecipeError, not "source changed": tools/bloomery/reach_cache.py:51. The old _bytes raised OSError when a file moved during the read, and current() turned that into False (the "request a fresh key" path). HashCache.sha goes through hash_stable, which raises RecipeError after 3 tries, and current() catches only OSError, ValueError. The error escapes from key_inputs and validate, and its text says "something writes $BLOOMERY_DATA", which is wrong for a source file. This needs a file rewritten three times in a row during one read, so it is rare. Direction: in _file, catch RecipeError and re-raise it as OSError, or accept the new error and say so in the PR body.
⚠ _corpus resets a field of another module's object: tools/bloomery/reach_cache.py:61. cache.t0_ns = time.time_ns() is correct (it keeps the 2 s racy window current in a long-lived process), but nothing says why. Add one line of why, for example "the racy window is measured from this walk, not from tree creation".
Checked
- Duplicates: 0 new functions;
_fileand_linkedtake the existingHashCache(recipes.py:9152). No dryer pairs (no Rust change; the tools did not run). - Staleness path: the cache key is (size, mtime, ctime, inode, device). A same-size, same-mtime rewrite changes ctime, so it is re-read. Files newer than
t0_ns - RACY_NSare never cached. The digest is the same sha256 over raw bytes as before, so the key value does not change. - Silent failure: 4 sites followed (
_file,_linked,_corpus,_holds). A missing or broken file still raisesOSErrorfromos.stat, as before. The one change is the ⚠ above. - Tests: the new test protects
HashCache.shabeing used in_file. Mutant "unconditional read in_file" turns theassert not readsred. Mutant "drop ctime fromident" turns theafter != beforeassert red, because theutimecall restores only mtime. Mutant "_holdsuncached" is covered only if the file is an observed read; the corpus walk covers it anyway. - Gates: no pin, band or check list moved.
- Performance: tool code, not a decode or prefill hot path. The 2-run A/B in the PR body is thin but matches the claim.
- Escape catalog: no pattern matched (no shell changes).
Notes
- No Rust or GPU code changed, so
gpu.jsonhas no card evidence. - The timing ran on the pre-rebase base; the PR body says the patch is unchanged (
range-diff=).
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
contrib-check --tier t0의 입력 검증이 같은 소스 파일을 반복해서 읽고 해시하던 비용을 줄입니다.What and why
Validating a recorded reach key walks the source corpus and hashes every
.rs,.toml,.pyandCargo.lockfile, and the same files were read and hashed again on every later validation in the same process. This reuses the existingHashCachefor those reads, so a file whose size and modification time are unchanged is hashed once per process. A rewrite with the same size and modification time still invalidates its consumers, and recently modified files are hashed again.Release notes: internal, the t0 check tier finishes sooner; no behavior change.
Code shape
_fileand_linkedintools/bloomery/reach_cache.pynow take the tree's existingHashCacheinstead of reading and hashing on their own. Every caller was updated._fileis replaced, not kept beside the cached one.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up. There is no Rust change in this PR.Duplication found or removed (
path:line): none.What I ran
New test:
test_repeated_key_validation_reuses_stable_source_hashesintools/recipes-key-test.py. It computes a key twice, checks that the second validation does not reopen an unchanged source file, then rewrites that file with the same size and modification time and checks that the key changes.Putting the old unconditional read back in
_filemakes the new test fail.I timed the full t0 tier,
bash tools/contrib-check.sh --tier t0, with the changed files taken from the base and from the head in turn, main then head then main then head, after one untimed warm-up run:The timing base is upstream
c21e3b81eb7f3ede965e5ac68f325b8a59cb2e05, with this patch on it as the head. The branch was later rebased onto11b3f4f3049e9a56b8ad61ea92caf9e0c6aed97e. The patch is unchanged by the rebase (git range-diffshows=), and I did not rerun the timing.I did not run the GPU gates, since this change touches no GPU or Rust code.
Hardware
The runs used one machine:
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.