Skip to content

load_cached() silently swallows corrupt cache entries (55% of a real-world cache was dead, no diagnostics) #2405

Open

Description

@jorgefusterr

While auditing a knowledge graph built from a personal Markdown vault (~230 files, Windows 11), I found that 138 of 249 entries in graphify-out/cache/ were invalid JSON. Every incremental run had been re-extracting more than half the corpus, paying that LLM work again each time, and nothing in the output suggested it.

The cause is in graphify/cache.py:

try:
    result = json.loads(entry.read_text(encoding="utf-8"))
except (json.JSONDecodeError, OSError):
    return None

load_cached() treats a corrupt entry exactly like a missing one, so the corruption never surfaces and the file stays in place, failing again on every future run. I checked the current v8 HEAD and the behavior is still there.

How my entries got corrupted is a separate story: they came from an old install (graphifyy 0.3.4) that wrote Windows paths with unescaped backslashes into source_file ("C:\Users\..."). That producer side looks covered by #2380 and #2197. This issue is only about the consumer side: whatever the origin, corrupt entries deserve a signal.

Repro on HEAD: drop any invalid-JSON file into graphify-out/cache/ and run an incremental update. The entry is re-extracted, nothing is logged, and the file remains for the next run.

Two small changes would cover it:

  1. Count decode failures in load_cached() / check_semantic_cache() and print one warning per run, e.g. warning: 138 corrupt cache entries ignored (will re-extract).
  2. Optionally rename bad entries to .corrupt so they stop being re-parsed every run.

Happy to send a PR for either if that helps.

Environment: Windows 11, Python 3.14; corruption produced under graphifyy 0.3.4; silent behavior verified in v8 HEAD graphify/cache.py.

Activity

  1. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    This looks fixed on the v8 branch by 5d8d6113 (fix(cache): surface corrupt semantic cache entries instead of silently missing (#2683)). Could a maintainer confirm and close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions