Repository navigation
In progress
In progress
Copy link
Labels
bugSomething isn't workingretrievalRetrieval ranking, use telemetry, negative evals, consolidationseverity:mediumReal but narrow: robustness, hygiene, or gated behind multiple preconditionstier:fullNew predicate or policy: full loop with blind architecture review
Description
Part of #386.
Goal
The injected memory block stops invalidating the prompt cache on turns where nothing
relevant changed.
Findings
src/inject/epochs.ts:164 buildMemorySectioncallsselectRelevant(prompt, 5, mems, …):
selection is a function of the current user prompt.- The epoch's cache key is
prefix = [...parts, block].join("\u0000")— the exact bytes
pushed ontoevent.system. The comment there says the comparison is by bytes "and never
by a proxy (issue P0: every memory write busts the prompt cache — the memory prefix carries bytes the model never needed #162)". That is correct and it is the problem: a new prompt re-ranks
rows, the bytes change, the prefix busts. - Measured,
results-cache-audit-onvsresults-cache-audit-pin, same six topics:
block 675/520/680/689/520/675 chars with 15 invalidations reasonprompt_reveal,
versus a fixed 236 chars with 0. Uncached input 3,999 versus 1,934 — 2.1×. - Anything placed on
event.systemis inside the cached prefix by construction. A
prompt-dependent tail cannot live anywhere in that block without busting it.
Currency warning, required in any write-up
On a local llama.cpp seat a cache miss costs prefill time (measured mean 648–880 ms per
request). On a hosted provider it costs money at roughly 0.1× read and 1.25× write. Both
are real; they are not the same claim and must not be quoted for each other.
Acceptance criteria
- Across a scripted six-turn chat with a non-empty store,
prompt_revealinvalidations
are 0 whilestore_changedinvalidations still fire when a row is written. - Block bytes are byte-identical turn to turn unless the store changed. Asserted on the
bytes, not on a hash of a proxy. - Stability must not mean staleness: a turn whose prompt needs a row that is not in the
stable core still receives it. This is the criterion that rules out "freeze the block at
session start" as a silent implementation of this ticket, and it must be demonstrated by
test rather than argued. - The 2.1× uncached-input improvement reproduces locally, and the same change is measured
on a hosted provider with cache pricing before any dollar figure is published. - Recall does not regress: the existing selection tests still pass.
Options, ranked by evidence not preference
- Recompute only when the selected set changes identity — not order, not wording.
Cheapest, least stale, and R1-era telemetry can tell us how often that actually is. - Split the block: a stable core in the system prefix (user-guided rows, open threads) and
the prompt-dependent picks moved out of the prefix into the turn. Correct by
construction, but the turn tail is re-sent every turn, which is input price not
cache-read price. - Freeze per session. Cache-safe, trivial, stale by topic. Only acceptable with criterion
3 demonstrated as passing, which it will not be.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingretrievalRetrieval ranking, use telemetry, negative evals, consolidationseverity:mediumReal but narrow: robustness, hygiene, or gated behind multiple preconditionstier:fullNew predicate or policy: full loop with blind architecture review
Activity
test(epoch): pin the same-order half of the prompt-rescore contract (#…
docs(readme): qualify the re-score claim with the order its bytes dep…
test(inject): assert the rare-concept rank on the selection, not the …
bench: budget the block the way the shipped path measures it (#388)
Merge pull request #396 from abogartz/388-cache-stable-block
chore(release): 0.24.0 [skip ci]
ocsi-architect commentedon Nov 26, 2026
Pre-arch pass — repro, corrected problem statement, state-boundary map. Worktree: scratch worktree off
mainHEADa5b68508(git worktree add --detach, symlinkednode_modules). Script:repro-388.ts(in that worktree). All numbers are real measurements from that run on main HEAD — no estimates.Corrected problem statement
The ticket's stated defect (15
prompt_revealinvalidations on a six-turn chat, 675/520/680/689/520/675 block chars) does not reproduce on main HEAD — it predates the merged #396 fix. The #396 fix (canonical render order) already lands: on main HEAD, the same shape (five re-phrasings of identical work) renders a constant 432-char block, 0 prompt_reveal invalidations, only thefirstepoch. Those recorded numbers describe the pre-#396 design and must not be quoted as the current state.What still reproduces (the actual defect): block bytes remain a function of the prompt-dependent ROW SET — not just order. A turn whose selection differs from the frozen set renders different bytes and records
prompt_reveal:'proto alpha build make'→ set{A}(176 chars). Turn 2'proto beta deploy helm make'→ set{A,B}(263 chars):prompt_reveal(263). The stable{A}bytes are not preserved when the set legitimately grows.'quix gamma forge make'→ set{C}(162 chars):prompt_reveal(162). A different set entirely busts the prefix.'widget alpha build make'vs'widget beta deploy helm make'): 432 chars both turns, byte-identical, 1 epoch (first) only — the fix holds.0prompt_revealinvalidations. Ticket AC-1's fixture shape passes on main HEAD.Criterion 2 as written ("block bytes byte-identical turn to turn unless the store changed") is not achievable as stated: criterion 3 (a turn whose prompt needs a row not in the stable block still receives it) requires bytes to change when the selection set changes. The ticket's own criteria are in deliberate tension; the design question is what to do with set-change busts, not whether ordering must stay canonical.
Repro record
Store text (seeded rows) + candidate prompts:
2026-10-01pattern/buildROW_A(containsproto);2026-10-05pattern/deployROW_B(containshelm);2026-10-07pattern/releaseROW_C(containsquix)'proto alpha build make'; turn2'proto beta deploy helm make'; turn3'quix gamma forge make'ROW_OLD2026-10-01build /ROW_NEW2026-10-05deploy (the harness fixture, shared rare termwidget, inverted rank)'widget alpha build make'/'widget beta deploy helm make'alpha,beta,alpha+deploy,beta+helm,alpha+betaPer-case verdict (measured, main HEAD):
first(176), prompt_reveal(263), prompt_reveal(162)cabc52ed)cabc52ed)first(432)— bytes identical, no recomputefirst(432)— 0prompt_reveal, all bytes identicalVerbatim block text (Scenario A, turn 2 — the growing-set case):
Verbatim (Scenario B, control — both turns identical):
(Scenario-A rows were still visible to scenario B's session; the control still proves bytes-identical for the same set. Scenario C uses only the two widget rows.)
Criterion 5 (recall not regressed):
test/inject/cache-stable-block.test.ts— 12 pass, 0 fail. Fulltest/inject+test/recallon main HEAD: 375 pass, 2 skip, 0 fail (28 files). Selection tests still pass.State-boundary map
(i) Where bytes enter
event.system(all boundaries)systemDigest(src/inject/digest.ts, called frombuildMemorySectionand the no-epoch path ofdeliver): pushes, in order — (a) the static line\n## Persistent memory (opencode-self-improvement)\n…(prompt-independent; deliberately cache-stable — no row count, no latest ts), (b)\n${frontier.block}for up toOPEN_THREAD_LIMIT = 3newest open threads, capped byfrontierBudget(cappedFrontierinsrc/inject/budget.ts, with omission shown in the block), (c)\nConvergence tracking: …(recentConvergenceSummary()— derived fact, gated on data existing). Pushes happen once per digest build; frontier evidence lines (frontier_injected) are recorded once per process per session (frontierInjectedSessions+frontierOrderLRU, evicted with the session).buildMemorySection(src/inject/epochs.ts):parts(the digest above) +blockfromselectRelevant, joined by\u0000→prefix(the epoch's byte comparison key; comment states bytes decide, "never by a proxy (issue P0: every memory write busts the prompt cache — the memory prefix carries bytes the model never needed #162)").deliver(src/inject/epochs.ts): pushes eachep.parts[*]thenep.block— the FROZEN epoch's bytes. If no epoch exists (no prompt yet / LRU eviction), builds the digest fresh (no relevance block) — a session with no epoch still gets the standing digest.src/inject/format.ts(formatMemory) renders each row line (provenance tags,[open]status, trust marker,flattenMemoryTexton every interpolated field,originalquote).src/recall/relevant.ts(selectRelevant) builds the relevance block: guided lane (≤guidedCap = 3, user-tagged rows, newest first) +scoreMemoriespicks (limit = 5in the epoch path), merged with guided rows first; conflict check code-checks guided rows declaring ref/claim/klass (fail-open,renderedmap); header line + caveat (GUIDED_CAVEAT/CONFLICT_CAVEAT, width decided by widest survivor); budget applied to the priority order (fittingLineIndicesonfitOrder= guided/restatable-demoted/score order) BEFORE the canonical re-sort; survivors rendered canonical newest-first (total order: guided lane, recency, content, literal ts) inside the block;selectedkeeps score order (ledger/attribution),shownkeeps post-budget set; block empty (or nothing survives) → renders""(a dangling header is suppressed).(ii) Where the epoch decides to recompute (
refreshEpoch,src/inject/epochs.ts)cached.version === version && cached.prompt === prompt→ return early. No re-score, nonoteHits. (A new prompt does re-score — the epoch-freeze flaw was rejected.)cached.prefix === built.prefix→ adopt new{version, prompt}, return. No evidence line, no invalidation.cachedexists, rows authored by this session since the freeze (extra, viaauthoredFor(sid)vscached.ownRows) are filtered out; rebuild withcached.prompt; if the result equals the frozen prefix → adopt new version, return. Everything else (removed/rewritten riding rows, another session's row, supersession, import, moved convergence line) survives into the render and still busts.noteHits(sid, built.rode, prompt)→ reason (store outranks prompt:store_changedif version moved, elseprompt_reveal, elsefirst) →epoch.setwith new bytes/prompt/ownRows/refs →record("epoch_recompute", {session, reason, chars, guidedSeen?, guided?, guidedRode?, conflict?}, false, sid, evidenceContext)→epochRecomputes++, stats (invalidations+++lastInvalidationunlessfirst),flushStatus.(iii) New state boundary the fix introduces
None today. The split that would be introduced: stable prefix (standing digest + frontier + convergence — prompt-independent by construction) vs prompt-dependent tail (the relevance block, selection-set-bearing). Today they are joined into ONE
prefixstring and pushed together; any change to the tail busts the whole prefix. A fix would have to decide where the tail lives and what the stable prefix is allowed to be — the ticket's ranked options (re-rank by set identity vs split the block) are the design space, not an order I prescribe.Escape shapes the fix must not break
extrafilter + rebuild atcached.prompt+ byte-equal adoption (else self-additions would bust).CONFLICT (…)replacement lines for code-checked rows, budget applied to priority order before render, dangling-header suppression, total-trim reporting (selectedkept,shownempty).ep.parts+ep.blockpushed in order; no-epoch path delivers the digest fresh;abstainedstat when the block is empty; requests/cumCharsaccounting at the injection decision.epoch_recomputewith{session, reason, chars, guidedSeen?, guided?, guidedRode?, conflict?};frontier_injected(once per process per session); theepoch_recomputereason precedence (store > prompt);frontierLRU eviction.noteHitsonly on adoption; theprompt_revealvsstore_changedreason split.fittingLineIndiceswhole-line discipline; caveat width decided by widest survivor (not re-fit oscillation); restatable demotion (never in the guided lane).WhollyMindless commentedon Nov 26, 2026
Note
🤖 GPT-6.2 Sol responding on behalf of WhollyMindless
We’re following #388. The pre-arch repro clarifies that reordering the same rows already preserves the cache. The remaining case is a prompt that needs a different set of rows. Pre-arch findings
Would a small prototype that moves prompt-dependent memories out of the cached prefix help you decide? We can check whether the newly relevant rows still reach the model and whether cache reuse improves on topic changes. We’ll wait for your direction before starting.
abogartz commentedon Nov 26, 2026
@WhollyMindless the use case revealed by auditing my live store suggests that it learned to keep a tally of the current ticket in a memory and as work progresses, it updates that row, invalidating the cache. This is because of the carve out that a new row that contradicts an earlier one deserves a prefix update. What we need to determine is how to inject the superseded and correct info without busting cache, especially when the new info is ephemeral such as which ticket is current. That new info already exists in the context so can it override without injecting a new system prompt? Does that answer your question?
ocsi-architect commentedon Nov 27, 2026
The set-churn half of this ticket was attacked by #552, which splits the epoch byte key so the stable core is the key and the prompt-dependent relevance block is excluded from it. Independent measurement on base
966bb7eand the PR head shows the delivered bytes are unchanged versus base: delivered OCSI bytes go 432 → 502 between two turns on both revisions, per-turn sha256 is identical across revisions, the counter is 1 on base and 0 on head, andrecomputes = 2on both. Thedeliverhunk is comment-only. The change is epoch accounting and reporting, and it is being reframed as such.That outcome is structural, not a coding miss. All memory bytes are delivered on the system channel (
event?.system?.pushatsrc/events.ts:305-306, at966bb7e):deliverpushes the epoch's stable core (src/inject/epochs.ts:383) followed by the relevance block (src/inject/epochs.ts:393-396). The system field serializes ahead of the conversation, so any prompt-dependent block placed in it relocates the divergence point inside the system field and everything after it re-bills under a prefix cache. Excluding the block from the byte key while still pushing it there necessarily leaves delivery byte-identical to base — which is exactly what was measured.What that means for this ticket's criteria: the criterion about hosted-provider measurement stays unmet, and for #552 it would stay unmet permanently, because a hosted measurement of that change would show no delivery change. Stated plainly so nobody runs the measurement expecting a win.
The thing that decides whether this ticket's goal is reachable inside the plugin at all is #559: a probe of whether the host forwards request-time mutation of
SessionRequest.messages— the only per-request surface that sits behind the stable prefix. If that probe fails, no in-band surface satisfies this ticket's goal.The dead ends, each closed — so they stop being re-proposed:
SessionRequest.system(session.d.ts ~:25, pushed atsrc/events.ts:305-306) — always ahead of the conversation; a prompt-dependent tail placed in it moves the cached prefix by construction.prompthook mutation — forbidden at the source: "Never mutate event.prompt.text — it is stored verbatim and rendered in the UI" (src/events.ts:316-317); it would poison the transcript and auto-capture.http.request/experimental.ws.send— can place bytes anywhere post-protocol, but provider-specific and experimental.src/inject/epochs.ts:256.