Repository navigation
Fix stale cache reads on equal-size, same-mtime transcript rewrites - #572
Conversation
|
| Filename | Overview |
|---|---|
| tokenjam/core/transcript_cache.py | Adds complete-content hashing and post-parse cache validation, but the previously reported cold/metadata-mismatch version-pairing race remains outstanding. |
| tests/unit/test_transcript_cache.py | Adds broad regression coverage for fingerprint invalidation and warm-cache races, without covering the outstanding cold or metadata-mismatched race. |
Sequence Diagram
sequenceDiagram
participant Caller
participant Cache as cached_read_records
participant Source as Transcript
participant Store as Cache file
Caller->>Cache: read(path)
Cache->>Source: stat
Cache->>Store: load entry
alt metadata-matching entry
Cache->>Source: fingerprint before parse
alt fingerprint matches
Cache-->>Caller: cached records
else fingerprint differs
Cache->>Source: parse records
Cache->>Source: stat and fingerprint after parse
Cache->>Store: store only if revalidation succeeds
end
else cold or metadata-mismatched entry
Cache->>Source: parse records
Cache->>Source: stat and fingerprint after parse
Cache->>Store: store when metadata remains equal
end
Reviews (5): Last reviewed commit: "Merge branch 'main' into fix/issue-560-c..." | Re-trigger Greptile
|
@Vam-si-krish Thanks for this pr bro! A few things before merge:
|
Agentic contribution tools (Cursor background agents and similar) poll GitHub's search API on `is:open no:assignee label:"good first issue"` — they don't read claim comments. When 15 issues got both labels in one burst, two different tools opened PRs for the same issue within 50 minutes of each other because neither tool's feed reflected the other's claim (public PRs Metabuilder-Labs#572, Metabuilder-Labs#573 against the same issue Metabuilder-Labs#560). Removing the labels the instant a closing PR opens is the lever that actually keeps an issue off those feeds; a comment changes nothing they read. Labels are restored, and only the exact ones this workflow itself removed, if that PR is later closed without merging. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
welcome and thanks for the contribution @Vam-si-krish ! |
|
Adding to @anshss's review (his 5 points are the right gate — lazy fingerprint, the store-time divergence gap, the unreadable-file test, the PR body, and the docstring tradeoff all stand). Two things his list doesn't cover:
Not merging yet — for the maintainers once CI is green and the above + Ansh's points are addressed. |
Delay hashing until metadata suggests a cache hit, then revalidate the source after parsing before persisting records. This prevents a digest from being paired with records parsed from different content while preserving readable and unreadable cache transitions. ContribPilot: CP-0023 Issue: Metabuilder-Labs#560 Co-Authored-By: anshss <[email protected]> Co-Authored-By: OpenAI GPT-5 <[email protected]>
|
Thanks @Vam-si-krish. The whole-file SHA-256 fingerprint is the right direction and it does fix the middle-rewrite case. But the last round of feedback isn't addressed yet — the last code commit (
Also the branch is behind |
|
@Vam-si-krish - are you planning to work on this? |
Bring the review fixes onto the latest upstream base before rerunning the full validation suite. Co-Authored-By: OpenAI Codex (GPT-5) <[email protected]>
|
@anilmurty @anshss — yes, I’ve addressed the review gate and pushed the update.
Local verification:
The refreshed CI run is waiting for maintainer approval: https://github.com/Metabuilder-Labs/tokenjam/actions/runs/30514071537 Once that workflow is approved, this is ready for another review. |
anilmurty
left a comment
There was a problem hiding this comment.
Thanks @Vam-si-krish — this is a clean, well-reasoned fix. Going full-file SHA-256 instead of the edge-sampling I'd suggested in the issue was the right call: edge-sampling would've missed a middle-only rewrite, and your tests cover exactly that alongside the equal-size/same-mtime case, unreadable files, and legacy cache entries without a fingerprint. The deferred-fingerprint-on-cold-miss tradeoff is sensible and documented, and re-fingerprinting after the parse to refuse a divergent entry is a nice touch.
Addresses my earlier review. Merging. Thanks to @anshss for the co-author work too.
The transcript cache previously trusted
(size, mtime), which can miss equal-size in-place rewrites. This adds a full-content fingerprint while keeping cache misses and concurrent rewrites safe.Summary
sizeandmtime.Nonefingerprints for unreadable-but-stattable files while invalidating both readable-to-unreadable and unreadable-to-readable transitions.Issue #560: equal-size transcript rewrites
The original metadata-only validity check could return stale parsed records when content changed without changing file size or modification time. A streaming whole-file digest closes that gap, including changes located away from the head and tail of large transcripts.
The revalidation step also prevents a digest observed before parsing from being stored beside records produced from different content. If the source moves while parsing, the fresh records are returned to the caller but no internally inconsistent cache entry is persisted.
Tests / Verification
.venv/bin/python -m pytest tests/unit/test_transcript_cache.py -q— 18 passed.venv/bin/ruff check tokenjam/— passed.venv/bin/mypy tokenjam/— 268 source files checked, no issuesorigin/mainworktree; none touch the transcript cache.What's NOT in this PR
main.Closes #560
🤖 Generated with OpenAI Codex
Co-Authored-By: anshss [email protected]