Skip to content

fix(serve): include the learning sidecar in the graph-context cache key - #14

Merged
Azeem1985 merged 1 commit into
v8from
fix/mcp-sidecar-cache-key
Aug 25, 2026
Merged

Azeem1985 merged 1 commit into
v8from
fix/mcp-sidecar-cache-key

Conversation

@Azeem1985

Copy link
Copy Markdown

Defect

_GraphContextCache.load keys each context on graph.json's (st_mtime_ns, st_size) only. But the .graphify_learning.json sidecar is baked into the cached graph object at load time — serve._load_graph attaches it as G.graph["_learning_overlay"], which becomes the learning= NODE annotations. graphify reflect rewrites only the sidecar, never graph.json. Verified in tonight's audit on the live deployment: a long-running MCP server kept serving the pre-reflect lesson annotations (or none at all) until graph.json itself happened to change.

Maker-docs check

The multi-project cache feature (upstream CHANGELOG 0.9.5, Graphify-Labs#1594) documents the invalidation contract as "its own mtime+size hot-reload" — written for graph.json before the two-file read surface existed. The overlay feature (CHANGELOG 0.9.3) deliberately keeps the sidecar out of graph.json ("structural truth stays separate ... no rebuild churn") — which is exactly why graph.json's stat can never witness a reflect run. No config or intended handling for sidecar-driven invalidation exists in docs, CHANGELOG, or code comments: zero hits.

Community check

gh search issues/prs on Graphify-Labs/graphify for "cache sidecar", "stale cache reflect", "server stale", "cache key sidecar": zero reports.

Fix

The cache key now appends the sidecar's (st_mtime_ns, st_size), with (0, 0) standing in when no sidecar exists:

  • sidecar appears → key changes ((0,0) → real stat) → reload, annotations appear
  • sidecar rewritten by a fresh reflect → key changes → reload, new verdicts
  • sidecar vanishes → key changes back to (0,0) → reload, annotations gone
  • nothing changed → same 4-tuple → cache hit, no reload cost

Applies to both the pinned default graph and project_path LRU contexts (they share load(); the docstring's "sole owner of file statting and cache-key construction" contract is preserved — the stat moved nowhere).

Tests

  • end-to-end on a running HTTP server with a counting _load_graph: no sidecar → un-annotated + 1 load; sidecar appears (graph.json untouched) → learning=preferred + reload; unchanged → cache hit (load count flat); rewritten → learning=contested + reload; deleted → un-annotated + reload
  • same contract exercised through a project_path context
  • serve/serve_http/query/reflect/hook_strict families: 271 passed; ruff + py_compile clean

🤖 Generated with Claude Code

The context cache keyed on graph.json's (mtime_ns, size) alone, but the
.graphify_learning.json sidecar is baked into the cached graph object at
load time (_load_graph attaches it as the learning= annotation overlay).
graphify reflect rewrites only the sidecar, never graph.json — so a
long-running MCP server kept serving stale lesson annotations (or none)
until the graph itself happened to change.

The key now appends the sidecar's (mtime_ns, size), with (0, 0) standing
in when no sidecar exists: appearing, changing, and vanishing each
invalidate exactly like a graph change, on both the pinned default graph
and project_path LRU contexts; an unchanged pair still hits the cache.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Azeem1985
Azeem1985 merged commit 8055b62 into v8 Aug 25, 2026
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.

1 participant