fix(cache): invalidate cache written by a different binary version#51
Merged
Conversation
mtime freshness can't detect scanner-logic changes that ship without a CACHE_VERSION bump: the source data didn't change, but the binary's interpretation of it did (#37). Stamp CARGO_PKG_VERSION into the cache file and treat any mismatch as stale on load, at the cost of one full rescan per upgrade. The write-side carry-over path for in-flight agents is gated the same way so entries shaped by an older binary are dropped instead of being re-persisted with a fresh mtime. Validation now lives in a pure parse_cache helper; AGF_DEBUG=1 logs which binary wrote the rejected cache ("cache built by X, current Y"). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
load_cacheinvalidates only onCACHE_VERSIONmismatch or data-source mtime advance. When scanner SQL/parsing logic changes inside the sameCACHE_VERSION, an upgraded binary keeps serving per-session payloads written by the old binary until the data source's mtime happens to move — the "data didn't change but its interpretation did" failure mode described in #37 (option A there).Fix
CacheFilegainsagf_version: String(stamped withenv!("CARGO_PKG_VERSION")on write,#[serde(default)]on read so pre-field caches parse and then fail the match).parse_cache(content, binary_version) -> Result<CacheFile, String>checking parse → schema version → binary version, in that order.load_cacherescans on any rejection;AGF_DEBUG=1logs the reason, e.g.cache built by 0.11.4, current 0.12.0 → rescanning.write_cachecarry-over path for in-flight agents goes through the same gate, so entries shaped by an older binary are dropped rather than re-persisted with a fresh mtime.CACHE_VERSIONstays for schema changes within one package version (dev builds); the header comment documents the relaxed bump policy.Cost: one full rescan per upgrade (a few hundred ms) — the trade-off recommended in the issue.
Tests
parse_cacheunit tests: accept on full match; reject on schema mismatch, binary mismatch, missingagf_version(legacy cache), and unparseable content.cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test(58/58) all pass.Closes #37
🤖 Generated with Claude Code