Define cache schema 2.6, integrity verification, stale-entry pruning, and
fail-open behavior.
- Cache object lifecycle:
codeclone/cache/store.py:Cache - Cache statuses:
codeclone/cache/versioning.py:CacheStatus - Stat signature source:
codeclone/cache/store.py:file_stat_signature - Wire encode/decode:
codeclone/cache/_wire_encode.py,codeclone/cache/_wire_decode.py - CLI/runtime integration:
codeclone/surfaces/cli/runtime.py,codeclone/core/discovery.py
On-disk schema (v == "2.6"):
- top-level:
v,payload,sig payloadkeys:py,fp,ap,files, optionalsrap(analysis_profile) keys:min_loc,min_stmt,block_min_loc,block_min_stmt,segment_min_loc,segment_min_stmt,collect_api_surfacefilesstores compact per-file entries with stat signature, extracted units, optional metrics sections (including report-onlysecurity_surfaces), referenced names/qualnames, and cached source statssrstores optional segment-report projection payload
Refs:
codeclone/cache/store.py:Cache.loadcodeclone/cache/_wire_encode.py:_encode_wire_file_entrycodeclone/cache/_wire_decode.py:_decode_wire_file_entry
- Cache is optimization-only; invalid cache never blocks analysis.
- Any cache trust failure triggers warning + empty-cache fallback.
- Compatibility gates:
v == CACHE_VERSIONpayload.py == current_python_tag()payload.fp == BASELINE_FINGERPRINT_VERSIONpayload.apmatches the current analysis profilesigmatches deterministic hash of canonical payload
- Stale deleted-file entries are pruned on save/update; cache must reflect the current worktree, not historical deleted modules.
- Cached entries without valid source stats are treated as cache-miss for processing counters and reprocessed.
Refs:
codeclone/cache/store.py:Cache.loadcodeclone/cache/store.py:Cache._ignore_cachecodeclone/cache/integrity.py:sign_cache_payloadcodeclone/core/discovery.py:discover
- Cache save writes canonical JSON and atomically replaces the target file.
- Empty sections are omitted from wire entries.
- Referenced names/qualnames are serialized as sorted unique arrays and omitted when empty.
- Cached public-API symbol payloads preserve declared parameter order.
- Legacy
.cache_secretis warning-only and never used for trust.
Refs:
codeclone/cache/store.py:Cache.savecodeclone/cache/_wire_encode.py:_encode_wire_file_entrycodeclone/cache/versioning.py:LEGACY_CACHE_SECRET_FILENAME
| Condition | cache_status |
|---|---|
| File missing | missing |
| Too large | too_large |
| Stat/read OSError | unreadable |
| JSON decode failure | invalid_json |
| Type/schema failure | invalid_type |
| Version mismatch | version_mismatch |
| Python tag mismatch | python_tag_mismatch |
| Fingerprint mismatch | mismatch_fingerprint_version |
| Analysis profile mismatch | analysis_profile_mismatch |
| Signature mismatch | integrity_failed |
CLI behavior: cache failures do not change exit code; analysis continues without cache.
Refs:
codeclone/cache/versioning.py:CacheStatuscodeclone/surfaces/cli/runtime.py:resolve_cache_status
- Cache signatures are computed over canonical JSON payload.
- Wire file paths and compact row arrays are sorted before write.
- Optional segment-report projection is additive; invalid/missing projection falls back to runtime recomputation.
Refs:
codeclone/cache/integrity.py:canonical_jsoncodeclone/cache/projection.py:wire_filepath_from_runtimecodeclone/cache/_wire_encode.py:_encode_wire_file_entry
tests/test_cache.py::test_cache_v13_uses_relpaths_when_root_settests/test_cache.py::test_cache_load_analysis_profile_mismatchtests/test_cache.py::test_cache_signature_validation_ignores_json_whitespacetests/test_cache.py::test_cache_signature_mismatch_warnstests/test_cache.py::test_cache_too_large_warnstests/test_cli_inprocess.py::test_cli_reports_cache_too_large_respects_max_size_flagtests/test_cli_inprocess.py::test_cli_cache_analysis_profile_compatibilitytests/test_core_branch_coverage.py::test_discover_prunes_deleted_cache_entries
- Cache file content stability across schema bumps is not guaranteed.
- Cache is tamper-evident only; it is not an authenticated secret store.