Skip to content

Add per-file result cache for Codex provider#185

Merged
iamtoruk merged 1 commit intomainfrom
feat/codex-result-cache
Apr 30, 2026
Merged

Add per-file result cache for Codex provider#185
iamtoruk merged 1 commit intomainfrom
feat/codex-result-cache

Conversation

@iamtoruk
Copy link
Copy Markdown
Member

Summary

Cache safety (validated by 6 review agents across 2 rounds):

  • Fingerprint captured before read, not after (no TOCTOU race on active sessions)
  • Atomic write via temp+fsync+rename (crash-safe)
  • 0o600 permissions (no world-readable billing data)
  • Object.hasOwn for prototype pollution defense
  • Eviction of deleted files on flush (no unbounded growth)
  • try/finally ensures flush even on parse errors
  • Respects CODEBURN_CACHE_DIR env var

Test plan

  • All 414 existing tests pass
  • CLI codeburn report works correctly
  • Verify on a machine with large Codex session directory (10K+ files)
  • Verify cache file created at ~/.cache/codeburn/codex-results.json with 0o600 permissions
  • Verify second run is near-instant (cache hits)

Fixes #183. Users with large Codex session directories (45 GB, 10K+
files) experienced CPU pegging because every 30-second refresh re-parsed
all session files from scratch.

Three optimizations:

1. readFirstLine now reads 16 KB via fs.open() instead of loading the
   entire file through readSessionFile. Cuts discovery I/O from ~45 GB
   to ~160 MB for 10K files.

2. Per-file result cache (codex-results.json) with mtime+size
   fingerprinting. Parsed results are cached on first run; subsequent
   runs return cached data instantly for unchanged files.

3. Cache-accelerated discovery skips header validation for cached files,
   pulling the project name directly from the cache manifest.

Cache safety: fingerprint captured before read (no TOCTOU), atomic
write via temp+fsync+rename, 0o600 permissions, Object.hasOwn for
prototype pollution defense, eviction of deleted files on flush,
try/finally ensures flush even on parse errors.
@iamtoruk iamtoruk merged commit 7ceef6b into main Apr 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex is too heavy for it to process, ccsage-codex can do it though, even if it takes a bit of time.

1 participant