Skip to content

docs(readme): state the injection contract the code ships (#344) - #379

Merged
abogartz merged 4 commits into
mainfrom
344-injection-contract-docs
Nov 12, 2026
Merged

abogartz merged 4 commits into
mainfrom
344-injection-contract-docs

Conversation

@abogartz

@abogartz abogartz commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

What

The injection contract changed under #334 / #339 / #340; the README still described the old one. This states what the code ships, and pins the claims that had no guard.

1. The injection section gains the two rules that changed.

  • User-stated guidance rides ahead of the lexical picks — newest-first, at most three, injectBudget still bounds the whole block — and why it exists: a prompt about "the injected bug" shares no vocabulary with "the correct sales tax rate is 8.25%", and the shipped matcher scored it zero. memory_recall and the contextual pull stay query-driven.
  • The block re-scores at every user turn (prompt_reveal), and the epoch MOVES only when the rendered bytes move — a prompt change that selects the same rows in the same order costs no cache bust. Order is part of those bytes on this build: src/recall/relevant.ts renders the lexical picks in score order, so a prompt that keeps the same rows and re-ranks them renders different bytes and pays the bust. Canonical render order, which removes that churn, is still open (#388, #396).

Each claim names the test that pins it: test/hint-channel.test.ts ("guidance rides without lexical overlap, capped newest-first and never duplicated"), test/epoch.test.ts — including the new "a prompt that re-selects the same rows in the same order costs ZERO cache busts", which seeds two rows so that a rank order exists at all — and test/guidance-provenance.test.ts for the provenance reservation (#342). No claim is left pointing at prose.

2. Status surfaces: prompt_reveal is display-only, now pinned per surface. /memory and the TUI panel both reach the epoch reason through the shared contextLines() and cacheLines() in src/status/report.ts; neither enumerates it, so a value a later build adds renders as-is instead of blanking. test("epoch reason is display-only: known and unknown values render verbatim") asserts the CONTEXT line and the CACHE line separately, each over first, store_changed, prompt_reveal and an unknown provider_restart. Asserting the two surfaces as one joined string was not enough: with that shape, replacing either interpolation with an enumeration left the test green.

The ticket lists the viewer as a third surface. It has no epoch surface at all — it is an admin view over rows, deletions and blocklist entries — so there was nothing to change there. Verified by reading src/viewer/page.html rather than assumed: the page carries no epoch rendering, and its reason fields are blocklist and undo reasons.

3. Invalidations wording. "The byte-change counter records epochs whose …" becomes "The invalidation counter counts byte-moving recomputes", matching what #353 put on the status surfaces. The sentence keeps the bound: it is not a provider cache-miss or re-prefill count. The note also states what the D column does not cover: the bench re-scores only when the store fingerprint moves, so its 20 prompts never re-rank one shared set, and D's 0 is not evidence about the same-set re-ranking above. No measured number changes — bun run bench on this head reproduces the published table exactly.

Measured

  • bun test test/status.test.ts — 43 pass / 0 fail, 140 expect() calls.
  • bun test test/epoch.test.ts — 24 pass / 0 fail.
  • bun run gate green on 991811d: typecheck exit 0; biome 542 warnings (the existing baseline) and 147 infos; unit 1192 pass / 19 skip / 0 fail; terminal smoke + BDD 30 pass / 0 fail.

Docs plus two tests: no src/ change, so no behavior changes and nothing new can break.

Closes #344

The injection contract changed under #334/#339/#340 and the README still
described the old one: nothing said that user-stated rows ride ahead of the
relevance picks, at what cap, or that the block now re-scores at every user
turn. Two bullets state it, each pointing at the test that pins it rather than
at prose.

Invalidations are now called byte-moving recomputes, matching what the counter
actually measures and the wording #353 put on the status surfaces.

The reason values (first / store_changed / prompt_reveal) are display-only on
/memory and memory_status: they are interpolated, not enumerated. A test pins
that an unknown value a later build adds still renders verbatim, so the
surfaces cannot silently swallow a new reason. The viewer has no epoch surface,
so it needed no change.
@abogartz

Copy link
Copy Markdown
Owner Author

Adversarial review — REQUEST_CHANGES

Reviewed head 24ac65a01797b2aae58d075c0d82ed16aa825985 against merge-base f8f42fd. Findings below come from running code, not from reading the diff.

Most of the PR is accurate and green. One P1: the new README states a cache invariant the shipped code violates. That invariant only becomes true with sibling PR #396, which is still open.


P1 — README.md:153 asserts "a prompt change that selects the same rows costs no cache bust". False on this tree.

The block renders in score order: src/recall/relevant.ts:142 builds merged = [...guided, ...top.filter(...)] where top is scoreMemories output, and top order is a function of the live prompt. Two prompts that select the same set in a different rank order produce different bytes, so the epoch prefix differs (src/inject/epochs.ts:219) and the epoch moves (src/inject/epochs.ts:266) → prompt_reveal.

Reproduced end-to-end through the real hooks with a seeded two-row store and a temporary store root:

same rows both turns: true
bytes identical across the two turns: false
epoch_recompute reasons: first,prompt_reveal

Direct render proof:

P1 selected order: s1 s2   P2 selected order: s2 s1
same SET: true   block bytes identical: false
ORDER CHURN (same set, different bytes): true

PR #396 ("Render the memory block in a canonical order so re-ranking stops busting the prompt cache (#388)") is open and fixes exactly this; its test/cache-stable-block.test.ts does not exist on this branch.

The cited issue #340 carries the same wrong premise ("bytes move only when the SELECTED rows change"), and the cited test test/epoch.test.ts case 1 uses a single row, so order churn cannot manifest there. The sentence is stronger than both the code and its own cited test.

Fix, pick one:

  1. Merge Render the memory block in a canonical order so re-ranking stops busting the prompt cache (#388) #396 first, then this prose reads true.
  2. Drop the em-dash clause and keep only "the epoch MOVES only when the rendered bytes move".
  3. Qualify it to "re-selects the same rows in the same order" and note that order-stable rendering lands in Stop the memory block busting the prompt cache: prompt_reveal invalidations to zero #388/Render the memory block in a canonical order so re-ranking stops busting the prompt cache (#388) #396.

P2 — The new test under-pins claim 3; a one-sided enumeration regression passes

test/status.test.ts:262. The helper shown() joins contextLines(...) and cacheLines(...), so the reason survives if either one interpolates.

  • Mutating only src/status/report.ts:42 to enumerate (... ? p.reason : "other") → test stays GREEN; cacheLines masks it.
  • Mutating both :42 and :57 → RED.

Fix: assert each surface independently, for example
expect(contextLines(payload({ reason })).join("\n")).toContain(reason) and a separate cacheLines(...) assertion.


NITs

  1. The body cites src/tui/panel.tsx:371 as the epoch-reason interpolation site. Wrong line. panel.tsx:371 renders the blocked-write reason (b.reason from BlockedRow). The panel interpolates the epoch reason at panel.tsx:298/312 through the shared contextLines/cacheLines. The substance (the panel interpolates) is true; the line reference is misattributed and rot-prone. It appears only in the body, not in the shipped README.
  2. The new test would pass on base f8f42fd. report.ts:42/57 interpolate on base, unchanged. The test pins no behaviour introduced by EPIC: Retrieval — user guidance survives re-entry (hint channel, prompt-reveal rescore, capture dedup) #334/Hint channel: user-stated facts ride injection regardless of vocabulary overlap #339/Epoch re-scores on new prompts (prompt_reveal); the freeze hid later-topic rows #340 — it is added regression cover. Legitimate, but it is not "the one claim that had no guard" created by this work.
  3. Bench column D hides the churn. README:166 shows D "Epochs whose bytes moved 0". The bench workload never re-orders a shared set, so D=0 neither contradicts nor exposes the order-churn class Render the memory block in a canonical order so re-ranking stops busting the prompt cache (#388) #396 measures at 2.1×.

Claim-by-claim

# Claim Result Evidence
1a Guidance rides ahead, newest-first, at most 3, injectBudget bounds the whole block verified by probe epochs.ts:205 guidedCap: 3; relevant.ts:119-124 sort(cmpTs desc).slice(0, 3); probe: 6 rows → selected [r6, r5, r4]; capToBudget applied to sel.block (guided included), rendered length ≤ budget at 300 and 1200
1b The shipped matcher scored the example pair zero verified by probe scoreMemories("the injected bug", [tax-rate row]) → length 0
1c The block re-scores at every user turn verified by reading events.ts:184-193 prompt hook → sessions.prompt → refreshEpoch; early return only when version and prompt are unchanged (epochs.ts:258)
1d The epoch moves only when the rendered bytes move verified by reading epochs.ts:266 adopts on cached.prefix === built.prefix
1e "a prompt change that selects the same rows costs no cache bust" FALSE P1 above, reproduced
2 Each claim names the pinning test; title verbatim verified by reading, with the P1 caveat test/hint-channel.test.ts:23 title verbatim; epoch.test.ts and guidance-provenance.test.ts exist and pass; epoch.test.ts case 1 is single-row and does not pin 1e
3 prompt_reveal is display-only and pinned; report.ts and panel.tsx interpolate verified by probe, partial report.ts:42/57 interpolate, no enumeration anywhere (grep clean); the new test kills full enumeration. Caveats: P2 and NIT 1
4 The viewer has no epoch surface verified by probe grep -rn "prompt_reveal|store_changed|invalidation|epoch" src/viewer/ → only server.ts:708, a <epoch-ms> snapshot-name comment; all reason hits are mutation reasons
5 Invalidations wording is "byte-moving recomputes" and keeps the not-a-cache-miss bound verified by reading README:168 matches report.ts:52/55/60 ("byte changes, not provider cache misses") and panel.tsx:303 ("byte-moving epochs")
6 status.test.ts 43/0; gate green; no src/ change verified by probe see measured numbers; the diff touches only README.md and test/status.test.ts
— Applies to ce36c65 (main +14) verified by probe git apply --check clean; on main+patch: status 43/0, hint-channel + guidance-provenance + epoch 31/0

Issue #344 acceptance

#344 lists three items and one AC: "README + docs diff reviewed against the merged code; no claim without a linked measurement or test."

  • Items 1 and 3 are addressed. Item 2 lists the viewer as a status surface; the PR declines it on verified grounds — the viewer exposes no epoch surface at all.
  • The AC is not met while the P1 stands: claim 1e carries a linked test (test/epoch.test.ts) that cannot pin it, because its first case uses a single row.

Measured numbers (head pr-379)

  • bun test test/status.test.ts: 43 pass / 0 fail (136 expect calls) — matches the body.
  • Unit bun run test: 1191 pass / 19 skip / 0 fail.
  • e2e: 30 pass / 0 fail.
  • Typecheck: exit 0. bun run gate: exit 0.
  • Lint warnings: head 542 / 147 infos; base f8f42fd 542 / 147 infos. Delta 0.

Efficacy proof

Mutation applied to src/status/report.ts, then reverted with git checkout:

  • :42 ${p.reason} → ${p.reason === "first" || p.reason === "store_changed" ? p.reason : "other"}
  • :57 (${p.reason}) → enumerated equivalent

Result: the new test goes RED with Expected to contain: "prompt_reveal", so it is not decoration. The :42-only mutation stayed GREEN, which is P2.

…344)

Case 1 seeds a single row, so it cannot show a rank order. Seed two rows both
prompts score identically and assert the second prompt adopts without moving the
bytes: one epoch_recompute, reason=first. This is the half that must survive
#388's canonical render order, so the current order-sensitivity is deliberately
not pinned.
…end on (#344)

"a prompt change that selects the same rows costs no cache bust" is false on
this tree: src/recall/relevant.ts renders the lexical picks in score order, so
a prompt that keeps the same rows and re-ranks them renders different bytes and
src/inject/epochs.ts moves the epoch with reason prompt_reveal. State the
qualified claim, name the order as part of the bytes, and point at #388/#396 for
canonical render order.

The bench note gains the matching bound: its policies re-score only when the
store fingerprint moves, so the 20 prompts never re-rank one shared set and D's
0 is not evidence about that churn. No measured number changes.
The display-only test joined contextLines() and cacheLines() into one string, so
a regression where only one of them learns an enumeration stayed green: mutating
either src/status/report.ts interpolation alone left it passing. Assert the
CONTEXT line and the CACHE line independently, each over the three known reasons
plus an unknown one.
@abogartz

Copy link
Copy Markdown
Owner Author

Review follow-ups applied at 991811d

Three commits, no src/ change. Gate green.

F1 (P1) — the README stated a cache invariant this tree violates

The sentence claimed "a prompt change that selects the same rows costs no cache bust". src/recall/relevant.ts:142 builds the block as [...guided, ...top], where top is scoreMemories output — score order, a function of the live prompt. Two prompts that select the same rows in a different rank order render different bytes, so src/inject/epochs.ts:266 sees a new prefix and :296+ moves the epoch with reason=prompt_reveal.

Probed end to end through the real prompt and context hooks against a seeded two-row store. src/ is untouched by this PR, so the before and after runs are the same measurement; both are reproduced here.

{
  "turn1 ranks A before B": true,
  "turn3 ranks A before B": false,
  "same rows both turns (turn2)": true,
  "turn3 selects the same set": true,
  "turn3 bytes identical to turn1": false,
  "epoch_recompute reasons": "first,prompt_reveal"
}

Turns 1 and 2 select the same two rows in the same order: bytes identical, one epoch (first). Turn 3 selects the same two rows inverted: bytes differ, prompt_reveal. So the sentence must not promise more than the same-order case, and it no longer does. It now reads "the same rows in the same order", names order as part of the rendered bytes on this build, and points at #388 / #396 for canonical render order.

The old citation could not show the claim either way: test/epoch.test.ts case 1 seeds a single row, so there is no order to preserve. Added test("a prompt that re-selects the same rows in the same order costs ZERO cache busts") — two rows, both prompts scoring them identically, asserts one epoch_recompute with reason=first. That is the half which survives #396's canonical order. The current order-sensitivity is deliberately not pinned, because #396 exists to remove it.

F2 (P2) — the display-only test now pins each surface

It joined contextLines(...) and cacheLines(...) into one string, so one interpolation could enumerate the reasons while the other carried the assertion. Mutation matrix; each mutation replaces one interpolation with ["first","store_changed","prompt_reveal"].includes(reason) ? reason : "other":

Mutation Old joined shape New per-surface shape
src/status/report.ts:42 (contextLines) only 1 pass / 0 fail 42 pass / 1 fail
src/status/report.ts:57 (cacheLines) only 1 pass / 0 fail 42 pass / 1 fail
both 0 pass / 1 fail 42 pass / 1 fail

The new failure is the surface that moved, e.g. Expected to contain: "provider_restart" / Received: " this epoch other epoch since …". Each assertion now takes the single line it is about ( this epoch …, epochs whose bytes moved …) and checks it contains the reason verbatim, for first, store_changed, prompt_reveal and the unknown provider_restart. report.ts is back at its original bytes — git diff over src/ is empty.

F3 (NIT) — the body's panel citation was wrong and is gone

The epoch reason is not interpolated at src/tui/panel.tsx:371; that line renders the blocked-write reason. The body now names the shared functions contextLines() and cacheLines() in src/status/report.ts rather than a line number, so it cannot rot.

F4 (NIT) — the bench note states what D's 0 does not cover

The bench re-scores only inside the store-fingerprint guard (if (!cEpoch || cEpoch.version !== version), and the same guard in D), so its 20 prompts never re-rank one shared set. The note now says D's 0 is not evidence about that churn. No measured number changed, and bun run bench on this head reproduces the published table (A 60996 / B 55478 / C 55258 / D 53500).

F5 — body accuracy

"No claim is left pointing at prose" still holds after the F1 rewrite: the qualified claim points at the new test/epoch.test.ts case, not at prose. The body's other statements were re-checked against the tree — the viewer claim included (src/viewer/page.html renders no epoch surface; its reason fields are blocklist and undo reasons). The body now reports the current counts and names two tests instead of one.

Gate at 991811d

bun run gate green: typecheck exit 0; biome 542 warnings (the baseline, unchanged) and 147 infos; unit 1192 pass / 19 skip / 0 fail (1211 run, 13185 expects); terminal smoke + BDD 30 pass / 0 fail. bun test test/status.test.ts 43 pass / 0 fail, 140 expects (was 136); bun test test/epoch.test.ts 24 pass / 0 fail (was 23). git status --porcelain empty.

Deliberately not fixed

The order churn itself stays: a same-set re-rank still moves bytes and still reports prompt_reveal. That is #388's fix in #396, not a docs change, and pinning today's behaviour would have blocked it. Two related items belong to #396 rather than here: it changes the rendering that makes the stronger claim true, and at its head bun run bench prints B=56109 / C=55889 against this table, which is bench-runner drift on that side. Merge order also matters — #398 edits the same README section and conflicts with this PR's note sentence.

@ocsi-reviewer ocsi-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving.

The blocking claim is corrected at 991811d: the README now says the epoch moves only when the rendered bytes move and qualifies the no-cost case to the same rows in the same order, with #388/#396 named as the work that makes order-stability true. The status-surface test now asserts each surface separately, so a one-sided enumeration regression fails.

Full gate green, CI green. Not merged — the merge is left to a human.

@abogartz
abogartz merged commit f84763b into main Nov 12, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.24.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz
abogartz deleted the 344-injection-contract-docs branch November 19, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: new injection contract for README and status surfaces

1 participant