Add cache invalidation based on file mtime #38

Open
opened 2026-04-07 02:51:05 +00:00 by mcp-service · 0 comments

The cache is keyed purely on path (SHA-256 of the path string). On a re-run, any path with an existing cache entry is skipped — even if the file has changed, been deleted, or new files have appeared in the directory.

The only current escape hatch is --fresh, which wipes the entire cache and starts over.

What should happen

When an investigation re-uses an existing cache, each entry should be validated before being trusted:

  • File entries: compare the cached cached_at timestamp against the file's mtime. If the file is newer, invalidate the entry and re-investigate.
  • Dir entries: if any file in the directory has changed (new, deleted, or modified since cached_at), invalidate the dir entry too.
  • Missing files: if a cached path no longer exists, remove the entry.

Implementation notes

  • Store mtime (from os.stat) in file cache entries at write time
  • On re-run, has_entry (or a new is_valid_entry) checks mtime before returning True
  • Dir entry invalidation can be triggered by checking if any child file entry was invalidated
  • --fresh remains the nuclear option for full cache reset
  • Noted as a Known Unknown in PLAN.md under "Cache invalidation on strategy changes"
  • #35 (watch mode incremental re-investigation) will need this same mechanism
The cache is keyed purely on path (SHA-256 of the path string). On a re-run, any path with an existing cache entry is skipped — even if the file has changed, been deleted, or new files have appeared in the directory. The only current escape hatch is `--fresh`, which wipes the entire cache and starts over. ## What should happen When an investigation re-uses an existing cache, each entry should be validated before being trusted: - **File entries**: compare the cached `cached_at` timestamp against the file's mtime. If the file is newer, invalidate the entry and re-investigate. - **Dir entries**: if any file in the directory has changed (new, deleted, or modified since `cached_at`), invalidate the dir entry too. - **Missing files**: if a cached path no longer exists, remove the entry. ## Implementation notes - Store `mtime` (from `os.stat`) in file cache entries at write time - On re-run, `has_entry` (or a new `is_valid_entry`) checks mtime before returning True - Dir entry invalidation can be triggered by checking if any child file entry was invalidated - `--fresh` remains the nuclear option for full cache reset ## Related - Noted as a Known Unknown in PLAN.md under "Cache invalidation on strategy changes" - #35 (watch mode incremental re-investigation) will need this same mechanism
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: archeious/luminos#38
No description provided.