Repository navigation
Description
Follow-up on #162 (shipped in 0.14.16). #162 made the epoch freeze the whole memory section and version it on rendered bytes, so a write the session is never shown now costs nothing. This closes the remaining half: a session still pays a full re-prefill for memories it wrote itself.
The rule
A session never pays for bytes it is not currently riding.
A pure addition this session authored costs zero busts. Anything that removes or rewrites a row that is riding busts. Anything this session did not author busts.
Why: the cost is almost entirely self-inflicted
Lifetime dogfood evidence (memory/evidence/*.logfmt, 35 sessions with busts):
| Measurement | Value |
|---|---|
epoch_recompute reason=store_changed (lifetime) |
145 |
write_promoted (lifetime) |
245 |
| Busts attributable to the session's own writes | 134 = 92% |
The last row is a min-bound (a session cannot bust more often than it wrote, and its own writes are the only store changes it provably made), but per-session it tracks 1:1 — busts=11/own=15, 10/11, 10/10, 9/9. So the dominant cache cost of this plugin is a session being billed to re-read facts it just produced.
Why "already in the conversation" is mostly right — and where it isn't
A row this session promoted is in its own transcript. Re-showing it is a cost with no information gain. That argument is strong, and it is the whole rule above.
It does not extend to three cases, which is why the rule is split by what happened to a riding row rather than by "was it me":
- A correction is not "already known." If a riding row is superseded (
memory_update,memory_forget, consolidation, decay), the model knows the old fact. Freezing makes the store silently vouch for something it has already retired. - Not everything in the section is yours. The frontier is mostly other sessions' open threads — that is the feature. Plus concurrent sessions/worktrees, viewer edits,
memory_import,memory_undo,memory_merge_review. None of it is in this context, and a residentopencode servelives for days. - Additions are not always additive. A new open thread can push an older one out of the budget-capped frontier, and any new row shifts document frequencies, which can reorder or evict a riding row in the relevance block. Losing information the session was riding is a change, not an addition.
On the blocklist carve-out — the objection I raised, and why it costs nothing
I initially argued that freezing must exempt removals so a human can pull a poisoned memory mid-session. Two findings retire that as a tradeoff:
- It never happens. On the dogfood host
blocklist.logfmtdoes not exist — zero entries, lifetime.deletions.logfmthas 4. The only way to block a memory isPOST /blockin the viewer (src/viewer/server.ts:261); there is no plugin tool for it, so it requires deliberately opening the viewer and clicking. - And the rule does not ask us to choose. Blocking, redacting, forgetting or superseding a row removes it from what is rendering. Removals bust unconditionally under the rule above, authorship included. So the security path stays exactly as responsive as it is today while the 92% case goes free. There is no user-experience-versus-safety decision to make here.
(Worth recording honestly: even today's immediate removal is weaker protection than the framing implies. If a poisoned row rode the section, the model already read it and its output is already in the transcript — dropping it from the prefix stops the re-assertion of the instruction on every subsequent request, it does not un-ring the bell. The next session starts a fresh epoch and is protected regardless.)
Design
Authorship predicate. Rows persist ts,type,scope,content,issue,tags,kw,status,repo,repoPath — no author. Two options:
- (chosen) An in-process
sid → Set<rowTs>, filled where a write is promoted, living insrc/state.tsunder the sameSessionLruso it is bounded and evicted with the rest of the session state. The window that matters is exactly the window this map is alive. A server restart forgets authorship, which degrades to today's behavior (one bust), never to a wrong freeze. - (rejected) A persisted
by=field: it would need a store-schema change, migration, and privacy review (it records which session wrote what) to fix only the restart edge case.
Freeze test. At adoption, store with the epoch the set of row ids that actually rendered (sources) — frontier rows plus budget-surviving relevance rows; the digest and the convergence line are row-independent. On a store change, render the candidate section and freeze (adopt the new fingerprint, ride the old bytes, emit nothing) iff both:
cached.sources − built.sourcesis empty — nothing that was riding stopped riding (this is what makes removals always bust), and- the section re-rendered excluding rows this session authored is byte-identical to the same key stored with the frozen epoch — i.e. every byte that moved is attributable to this session's own additions.
(2) is checked by rendering twice on the store-changed path only; there is no model call in it, so the extra render is microseconds against a multi-second re-prefill.
Acceptance criteria
-
memory_rememberof a row that IS selected for injection → next request rides the OLD bytes, noepoch_recompute,invalidationsunchanged. (Today: busts.) -
memory_rememberof an open thread that evicts a riding frontier row → busts (loss of riding information). -
memory_update/memory_forget/ blocklist / hand-redaction of a riding row → busts on the next request, same as today. Existing tests intest/epoch.test.tsstay green. - A row promoted by a different session (and a viewer edit,
memory_import,memory_undo) → busts. - After a compaction the epoch is dropped, so the session sees everything it missed; a new session always renders fresh. Pinned by existing tests.
-
/memoryCONTEXT andmemory_statusstate the guarantee accurately: additions by this session are free; corrections and other writers land on the next request. - Bench gains an arm showing the self-authored-addition case at 0 busts, measured on the full section.
- Gate green:
bun run gate(tsc, biome, unit, e2e).
Out of scope
Persisting authorship. Tail-adjacent injection (injecting relevance after the latest turn instead of in the system prefix) — that is the only way to get per-turn relevance freshness and zero busts, and it trades away the invisibility the current design chose deliberately, so it is a separate product decision.
Activity
abogartz commentedon Oct 28, 2026
Implemented on
fix/riding-bytes. Three things changed between the pre-registered design and the code, recorded here rather than silently.1. The freeze test is simpler than the design's two conditions
The design said: check
cached.sources − built.sourcesis empty (nothing riding disappeared) and re-render excluding self-authored rows. The second check subsumes the first, so only it is implemented:A removal of a riding row cannot be reproduced by that render (the row is gone from the store, so subtracting my additions does not bring it back), so removals, redactions, blocklist, forget, supersession and decay all still bust without needing a separate
sourcesset. That also removed the need to plumb a row-id out-param throughsystemDigest.2. Self-authored eviction does NOT bust — and that is better than the design said
The design listed "a new open thread pushes an older riding row out of the capped frontier" as a change that must bust. It does not, under this test — and on reflection it should not: freezing never removes anything from what the session is riding. The session keeps riding the older row; the eviction only materialises at the next real adoption. Freezing cannot lose information for the current session, it can only be stale, so the eviction case costs a bust for no benefit.
3. A hole the design did not have: a topic change between the freeze and the write
Found while making the bench show the win. The epoch deliberately does not re-score when only the prompt changes (
test/epoch.test.tspins that as intended). So if the session pivots to a new subject and then writes a memory, the counterfactual rendered against the current prompt produced a different block than the frozen bytes — and the session paid a bust for a refresh the plugin refuses to perform on a prompt alone. That is the cost/benefit inversion from the issue text, reappearing through the back door.Fix: the epoch stores the prompt its bytes were scored against, and the counterfactual re-scores with that prompt. Pinned by
a topic change plus a self-authored write still costs nothing, which is red without the prompt pinning.Authorship: in-process, as chosen
noteAuthored(sid, ts)fires at the single place a row is created on behalf of a named session (runWriteGate, afterappendMemoryresolves the ts). The viewer's own writes are deliberately not attributed, so a human edit always looks foreign and always lands. Registry lives insrc/state.tsunder the sameSESSION_CAPLRU as the other session ledgers;resetState()clears it.Measured
One contract this changed outside the plugin: the use ledger
e2e/ledger.test.tsasserted that a session writing two facts earnedsrc=injectcredit for the block that then carried them. It no longer does — because it is no longer shown them. The test now asserts that explicitly (injected.length === 1: the next session is the first to be shown them), and the store report consequently shows honest dead weight: 1 retrieved, 1 never retrieved (50%), where before both rows looked used. That is the correct reading — a row nobody ever retrieved is dead weight — but it meansneverRetrievedcounts will rise after this ships. Anyone reading that number as a quality signal should know why.Boundary to keep in view
A very long-lived session that writes constantly will not see its own rows injected until a foreign change or a compaction drops the epoch. That is the requested trade, and compaction is the existing reset, but it is a real staleness window rather than a theoretical one.
Gate: 620 unit pass / 12 skip / 0 fail, 11 e2e pass / 0 fail,
tscclean, biome exit 0, bench byte-identical across runs.Merge pull request #166 from abogartz/fix/riding-bytes
chore(release): 0.14.17 [skip ci]
abogartz-opencode-self-improvement commentedon Oct 28, 2026
🎉 This issue has been resolved in version 0.14.17 🎉
The release is available on:
Your semantic-release bot 📦🚀
perf: a session never pays a cache bust for bytes it is not riding (a…
Merge origin/main (v0.14.17, abogartz#165) into fix/security-154-155
abogartz commentedon Oct 28, 2026
Live measurement: a memory write, before and after
Ran the experiment on the dogfood host while the versions happened to change underneath it, which produced a clean A/B for free.
The write that busted — 0.14.16 (#162 shipped, #165 not yet)
Same shape as the three earlier writes in that session (
21:59:20.177 → .273,22:22:54.399 → .495,23:08:01.505 → .576): the promoted write is followed within ~70–155 ms by a bust, and every bust costs the next request a full re-prefill of the conversation.The write that did not — 0.14.17 (#165)
Session counters across that write:
invalidations 0,sectionCharsheld at 3108, cache-served share unchanged at 95.7%.Ruling out the boring explanation
A write that renders nothing already cost nothing under #162, so a non-event proves nothing unless the row would have moved bytes. Checked by rendering this session's memory section from a copy of the live store, with and without the probe rows, using the plugin's own
systemDigest:It was written as an open thread deliberately, so it enters the frontier block regardless of prompt wording — 285 chars of genuinely new prefix. Under 0.14.16 that is a bust. Under 0.14.17 the session kept riding its old 3108 chars.
Cleanup: both probe rows removed; audited in
deletions.logfmt, snapshots retained formemory_undo. Removing them caused no bust either — they had never ridden the prefix, so the subtraction still reproduced the frozen bytes exactly. The "removals always bust" guardrail applies to rows that are riding and is covered bytest/epoch.test.ts, not by this live run.What happened, in order
Bench, full memory section, deterministic: naive 19 busts → pre-#162 3 → pre-#165 3 → shipped 0, with 12.3% fewer injected characters than naive.
Two things worth keeping in sight
Merged is not live. 0.14.17 hit npm at 23:13:53Z. The host restarted at 23:15 and still ran 0.14.16 — the
@latestplugin cache resolved to the install directory from 16:14, and nothing re-fetched. It only picked 0.14.17 up at a second restart at ~23:20. So "we shipped it" and "your sessions feel it" are separated by a restart, and sometimes two. Anyone validating a plugin fix against their own host should confirm the resolved version rather than assume it.The metric that moved on purpose. A writing session no longer earns
src=injectuse-ledger credit for rows it is never shown, soneverRetrievedin/memoryandmemory_statusrises after 0.14.17. That is the ledger telling the truth — those rows genuinely were not retrieved — but it will look like a quality regression to anyone who doesn't know the date.