Skip to main content

is_cache_entry_stale_verified

Function is_cache_entry_stale_verified 

Source
pub fn is_cache_entry_stale_verified(
    path: &str,
    cached_mtime: Option<SystemTime>,
    cached_hash: &str,
) -> bool
Expand description

Staleness with content verification: like is_cache_entry_stale, but when the mtime claims “unchanged”, additionally compares the md5 of the on-disk content against the cached hash.

mtime alone cannot be trusted for correctness: same-second writes are invisible on coarse-granularity filesystems (HFS+ 1s, FAT 2s) and mtimes can be restored by tools. Serving an [unchanged] stub for changed content would silently mislead the agent — the worst failure mode a context layer can have. The extra disk read costs microseconds for typical source files; the stub’s token savings are unaffected. Opt out: LEAN_CTX_CACHE_VERIFY=0.

Note: entries whose stored content differs from disk by design (e.g. secret redaction) hash differently and therefore never serve stubs — conservative and correct.