Skip to content

Name the reason when the mod says the cache broke - #16

Merged
maxsoldev merged 1 commit into
mainfrom
fix-cache-break-nudge
Nov 21, 2026
Merged

maxsoldev merged 1 commit into
mainfrom
fix-cache-break-nudge

Conversation

@maxsoldev

Copy link
Copy Markdown
Owner

Summary

The mod's cache toast now names why a Call lost the cache, in the same order as the engine's cache breaks.

 on(turn.step, main loop)
   if cache held or re-write ≤ 20k: no toast
-  if idle > 5 min: "cache expired after N min idle"
+  if compacted since last Call:    "re-written after a compaction, as expected"
+  if model changed:                "re-written after a switch from A to B"
+  if idle > 1 h:                   "cache expired after N min idle"
+  if idle ≤ 5 min:                 "the start of the request changed (tools, MCP, CLAUDE.md?)"
+  if idle 5–60 min, 1 h cache:     same, "within its 1-hour lifetime"
+  if idle 5–60 min, lifetime unknown: "expired if it lives 5 min, else the start changed"
  • The mod cannot ask the engine: the engine runs only while the viewer is open.
  • TurnUsage has no 5 min / 1 h split. The mod learns the 1-hour lifetime when the cache holds over a pause longer than 5 min. After that, the cost uses the 1 h write price (2×).
  • New Live fields: compacted (set by session.compact, but not for precompute; cleared by the next Call) and hourCache.

Evidence

  • Before: in a real session, /clear-tools came after a 41 min pause. The toast said "cache expired after 41 min idle". The engine's v_cache_breaks gives reason = compaction for that Call, and the Calls before it wrote 1 h cache entries.
    After: packages/mod/test/nudges.test.ts, one test per reason (red before the change, 57/57 green after):
    step(read 300k) · 40 min · compact · step(read 0, write 100k)
      → "cache re-written after a compaction, as expected; this call wrote 100k tokens (~$0.50)."
    step(read 300k) · 20 min · step(read 301k) · 40 min · step(read 0, write 302k)
      → "...within its 1-hour lifetime: the start of the request changed ... (~$2.42)."
    
    pnpm check passes.

Merge Danger

Door: two-way

Only the toast text and when it shows change. No stored data changes.

Blast Radius: toasts

A cache loss with no pause now gives a toast, where before it gave none. If the 50 % read share gives a false positive (for example, a Call right after a large re-measure), the person sees a toast that is not needed.

The toast said "cache expired after N min idle" for every cache loss
after a 5 min gap. After a /clear-tools or /compact it blamed the
clock, and in sessions with a 1-hour cache it said "expired" for gaps
the cache outlives. A loss with no pause gave no toast at all, though
a change at the start of the request is the case worth a look.

The mod now checks the reasons in the engine's order: compaction,
model switch, idle past the lifetime, else a prefix change. It cannot
ask the engine: the engine runs only while the viewer is open. Claude
Code's TurnUsage has no 5 min / 1 h split, so the mod learns the 1-hour
lifetime when the cache holds over a pause longer than 5 min; until
then a 5-60 min gap names both causes.
@maxsoldev
maxsoldev merged commit 25579c5 into main Nov 21, 2026
5 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.

1 participant