Repository navigation
Description
Symptom
A session goes quiet for several seconds immediately after any memory write, then recovers. It looks like the whole conversation is being re-sent to the model. It is: the write busts the provider prompt cache, so the next request re-prefills the entire history uncached.
This directly contradicts the headline promise. README.md:102 ("the provider's prompt cache survives ordinary turns"), README.md:115 ("byte-identical between store changes so the prompt cache stays warm"), and the badge/panel copy memory never invalidated your cache prefix are all false for the turn after a write.
Receipts (dogfood host, 2026-10-28, 20 promoted writes)
The write itself is not the problem:
| Measurement | Value |
|---|---|
gate_start → write_promoted latency |
4 / 15 / 27 / 44 ms (min / median / p90 / max) |
epoch_recompute events |
34 |
… with reason=store_changed (= cache busts) |
21 |
Gap between write_promoted and its epoch_recompute |
0.1 – 1.5 s |
The write gate is zero-model, so no hidden LLM call is involved. The stall is entirely provider-side re-prefill of a changed prefix.
Root cause — three independent volatile bytes in the cache-critical prefix
-
The epoch versions on the store fingerprint, not on rendered output.
refreshEpoch(src/index.ts:1156-1158) comparesstoreVersion(mems)(src/inject.ts:377-389, a sha256 over every active row) and rebuilds on any difference. A promoted row that renders nothing at all still forces a new epoch, still emitsepoch_recompute reason=store_changed, and still incrementsstats.invalidations. Three of today'sstore_changedrecomputes produced a block of identical length (849c) — the current version key cannot even tell us whether the bytes moved. -
The standing digest is volatile and is rebuilt on every request.
systemDigest(src/inject.ts:295-299) pushes"{mems.length} durable memories; latest: {latest ts}", called with freshly loaded rows in everysession.context(src/index.ts:1263-1267). So any promoted row changes the system prefix even when the relevance block is untouched. This is the bust that survives fixing (1). -
The frontier block shifts with every open row.
cappedFrontier(src/inject.ts:237-270) is newest-first and budget-capped, so a new open thread reorders/re-trims it. Here the injected content genuinely changed — one bust is correct and intended.
Why it matters
Injection rides the front of the system prompt, so a single changed byte invalidates everything after it, including the whole conversation history. On a long session that is the most expensive thing the plugin can do to a turn, and it is paid once per write. The plugin already measures this honestly (stats.invalidations, the yellow badge dot) — the numbers are simply worse than the product claims.
Proposed fix
Make the memory prefix cache-stable by construction, and make the invalidation counter mean exactly what it says.
- Version the epoch on rendered bytes. Build the full memory prefix (digest + relevance block + frontier), then compare that string. Unchanged → keep the epoch, emit no
epoch_recompute, do not incrementinvalidations. The store fingerprint stays useful as a cheap pre-check, but it must stop being the authority. - Remove volatile facts from the prefix. Drop
latest: <ts>and the row count from the digest line, or freeze them with the epoch so they are stable until the injected content actually changes. Both facts already live on surfaces where exactness is free and cache-neutral: the footer badge,/memory,memory_status, and the viewer. - Keep the honest bust. A write that changes injected content must still produce exactly one invalidation on the next request. Freshness beats cache warmth; the goal is no gratuitous busts, not no busts.
Acceptance criteria
- Unit test: write a row that is not selected for injection → next
session.contextproduces byte-identical prefix,epoch_recomputenot emitted,invalidationsunchanged. - Unit test: write a row that IS injected → exactly one
epoch_recompute reason=store_changedandinvalidations + 1. - Unit test: two writes in the same turn → at most one bust on the following request (the prefix is compared once per request, not once per write).
-
bun run benchextended to report busts per policy, not just injected chars; the shipped policy must show 0 busts for store changes that do not alter the block. - README cost model + badge/panel copy updated to the real guarantee ("writes that change what you see cost one re-prefill; the rest cost nothing") — and the claim must be reproducible by the bench.
- Existing gate green:
bun test,bun run lint,bunx tsc --noEmit.
Out of scope
Batching/deferring writes, lowering store-read cost, and the separate evidence-line bloat issue (unbounded evidence_refs).
Activity
Merge pull request #164 from abogartz/fix/162-cache-stable-prefix
chore(release): 0.14.16 [skip ci]
abogartz-opencode-self-improvement commentedon Oct 28, 2026
🎉 This issue has been resolved in version 0.14.16 🎉
The release is available on:
Your semantic-release bot 📦🚀
fix: a memory write must not bust the prompt cache unless bytes move (a…
chore(release): 0.14.17 [skip ci]
perf: a session never pays a cache bust for bytes it is not riding (a…
chore(release): 0.24.0 [skip ci]