Skip to content

fix(inject): preserve the prefix for same-session memory corrections - #553

Merged
abogartz merged 5 commits into
abogartz:mainfrom
WhollyMindless:fix/550-cache-correction
Nov 27, 2026
Merged

abogartz merged 5 commits into
abogartz:mainfrom
WhollyMindless:fix/550-cache-correction

Conversation

@WhollyMindless

@WhollyMindless WhollyMindless commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #550.

A successful memory_update can preserve the exact memory bytes a session already received when it corrects a row in its relevance block. The new value is already in that session's tool call. The durable store supersedes the old row, and a fresh session sees the current value. The no-cache-freeze tag opts out.

The branch includes the merged accounting changes from #552. The correction path compares the full delivered memory section, including the core and relevance block. A revocation can change delivered bytes while leaving the active-row fingerprint unchanged. Status reports those two measurements separately.

Review points

  • A hold starts on a store change. On later prompts, the existing hold can continue when the same rows would ride. A prompt that selects an additional row ends the hold and records prompt_reveal. This is the prompt-path decision to review against acceptance item 4 in A self-authored correction to a riding row still busts the cache though both versions are in the transcript #550.
  • The correction path keeps imported rows in its comparison so a relevant import can end the hold. The existing pure-addition path is unchanged.
  • The tests verify delivered bytes and store visibility. Model behavior when the transcript contains both values remains an open question. Maintainer clarification

Verification on 6f8e8c0f

  • Windows unit suite: 1,871 passed, 34 platform skips, zero failures. The exact-delivery tests cover chained corrections, prompt rephrasing and selection growth, fresh-session recall, blocking the successor, editing or blocking the predecessor, and convergence changes.
  • Linux smoke: 57/57 on OpenCode 2.0.26 and 57/57 on 2.4.1. Typecheck, lint, format, and comment policy passed.

GPT-6.2 Sol · T3 Code

@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.

FULL REVIEW — PR #553 (fix/550-cache-correction, 42219c0) — adversarial, read-only

Verdict: APPROVE, with named residuals below

The delivered bytes really hold — measured, not asserted — and every explicit constraint in #550 that this seat could re-measure holds on the delivered bytes, not on the epoch key or the ledger. This is not "reliable now": the provider-side win is unmeasured (as the #552 line-drawing already states), and two properties below ship with zero direct tests. Read the survivors before merging.

Topology first: what MERGEABLE does and does not hide here

git merge-base origin/main 42219c0 = 2c4d6b3 = current origin/main — the branch has fully merged main, so #552's core/tail split and #562 are ancestors of head. The head tree is main plus the correction path, which means GitHub's MERGEABLE verdict here does not hide a semantic conflict in src/inject/epochs.ts, and running the branch's suite at head is the rebase-onto-main test. It passes: full suite 1889 pass / 2 skip / 0 fail (1911 tests, 155 files, bun run test); bun test test/inject/ alone 207 pass / 2 skip / 0 fail; bun run gate → "merge gate: all green" (includes the 57/57 smoke). The fail-before also holds the honest way: the head epoch.test.ts run against the base worktree fails exactly the 8 hold-behavior tests for the right reason (no hold mechanism exists on base) while all 30 pre-existing pins pass identically on both.

The #552 interaction, resolved from code

The hold cannot mask a real byte move and the core-only key is never a sole pass condition on this path. The correction counterfactual compares both delivery targets — back.prefix === cached.prefix && back.block === cached.block (epochs.ts head:436) — on top of a parts-equality precondition (:415–419) and a riding-set containment check (:418). Delivery pushes ep.parts then ep.block (:544–557) and the hold branch keeps ...cached, so the held turn's bytes are literally the previous turn's bytes. The ledger fusion is consistent with #552 rather than collided: head moved storeMoves++ from reason === "store_changed" to the fingerprint-driven storeMoved (:466, :526), which is what preserves #552's storeMoves definition once a revocation can be store_changed without a fingerprint move — and that exact revocation case is pinned at epoch.test.ts:779-784 (invalidations 1, storeMoves 0).

The delivered-bytes measurement (the one #552 was reversed over)

Identical driver script, both revisions; sha256(12) of the full OCSI system section per turn; inv/moves = status invalidations/storeMoves.

turn base sha head sha bytes base reasons head reasons base inv/moves head inv/moves
1 first 1a7dcca3c790 1a7dcca3c790 442 first first 0/0 0/0
2 repeat 1a7dcca3c790 1a7dcca3c790 442 first first 0/0 0/0
3 after own correction c1 0c71b3c308b5 1a7dcca3c790 443→442 +store_changed — 1/1 0/0
4 tool-loop repeat 0c71b3c308b5 1a7dcca3c790 443 — — 1/1 0/0
5 rephrase (same rows) 0c71b3c308b5 1a7dcca3c790 443 — — 1/1 0/0
6 after own correction c2 d41bc2e613ef 1a7dcca3c790 444 +store_changed — 2/2 0/0
7 set growth (+helm) dee8e850e421 dee8e850e421 541 +store_changed +store_changed 3/3 1/1
fresh session d41bc2e613ef d41bc2e613ef 444 first first 0/0 0/0
post-compaction d41bc2e613ef d41bc2e613ef 444 +first +first 3/3 1/1

Readings. Turn 1 is identical on both revisions — the comparison starts from the same bytes. On head, turns 3–6 are byte-identical to turn 1 across two chained self-corrections: zero epoch_recompute, invalidations unmoved. Base busts once per correction. Head turn 7 and post-compaction land on the same shas as base, so the hold ends exactly where base behavior takes over — no fork in end-states. Post-compaction delivery equals fresh-session delivery on head: the session is shown the final corrected row and nothing frozen.

What is the model shown while holding? The delivered block carries the superseded text; the corrected text exists in the session's own memory_update call arguments — the exact trade #550 proposes, and it is named plainly here as deliberate staleness. Its bounds, all measured: per-request revalidation (restoreCorrections runs before the cheap pre-check at :359–364, so a blocked/edited predecessor or successor revokes on the very next request, delivered bytes show the withdrawal, reason store_changed); any prompt shift that changes the selected set; a foreign update to the chain; LRU eviction; compaction (events.ts:351 sessions.invalidate drops the epoch, and therefore the corrections map, with it).

Constraint-by-constraint against #550 (verbatim)

  1. "This is a narrow reversal of one #165 acceptance criterion, not a removal of the riding-bytes rule." — Holds. The pure-addition branch is unchanged logic (head :446–456 vs base :319–335) and every pre-existing riding-bytes test passes; base and head produce identical bytes at every non-correction step above.
  2. "Foreign writes, viewer edits, hand-redaction, blocklist, memory_import, memory_undo, and another session's consolidation or decay must still bust." — Holds, with one untested sub-case. Another session's memory_update busts and delivers that row (measured: A-after-B-c2 → d41bc2e613ef, store_changed, identical to base); test.each "…can replace a held correction" pins viewer edit, import, undo, hand-redacted predecessor and blocked successor, each one store_changed; hand-redaction of an authored row is pinned at epoch.test.ts:1013. Decay superseding a held tip has no test — my probe showed it busts fail-closed (DECAY|old=false|c1=false, store_changed, inv=1) — residual 2 below. A foreign write that renders nothing silent-adopts on both revisions (measured A-after-foreign-row, identical frozen sha base/head): the constraint cannot mean "bust a byte move that did not happen", and base behaves the same.
  3. "Frontier displacement, budget eviction, and moved convergence lines must still bust." — Holds. Pinned by test.each modes frontier and budget (bust controls) and convergence (mid-hold evidence event → prompt_reveal with the tracking line re-appearing in delivered bytes).
  4. "A row that was not riding when frozen does not qualify." — Holds. Write-side gate: noteCorrection records only when previous.ts is in cached.ridingRows or is a recorded edge tip (:599–604); test.each "non-riding predecessor" passes; measured: updating a non-riding row produces no recompute on either revision (nothing rendered moved — silent adoption, same sha on base and head).
  5. "A new session must see only the corrected row; the frozen old bytes are session-local overlay, not durable stale state." — Holds. Fresh-session bytes contain only the final row on both revisions (table); durable supersession (target.superseded_by === successor.ts) is asserted on every update in the driver; a fresh session that inherits the author's hold is not constructible without a mutation, and the M4 mutant is killed by the right assertion.
  6. "#390 stays intact: corrections must supersede in the data, not only in the wording." — Holds. The hold touches no store bytes; restoreCorrections re-reads the live store and requires reason === "update" plus the exact superseded_by pointer, so the overlay dies the moment the durable evidence is stale.
  7. "#388 remains the ticket for prompt_reveal row-set changes. This ticket is for store_changed from self-authored supersession." — Holds. Held rephrase turns record no recompute at all; a set-growth turn records prompt_reveal with storeMoves 0 (epoch.test.ts:731-735).
  8. "Add an explicit no-cache-freeze tag as an opt-out … Do not infer this from prose." — Holds. Implemented as a tag check in stillUsable on both live predecessor and successor; test.each "opt-out" busts; measured: opt-out row delivers the correction (0c71b3c308b5, store_changed, inv=1) while the untagged control holds.

Acceptance 1–5: scripted zero-recompute byte-identity (pinned + measured), fresh session (pinned + measured), all nine negative controls present as named tests and green, prompt_reveal unchanged, bun run gate green (local run: "merge gate: all green"; CI green).

Class-first, then instances

  • Scoping. Author-only by construction: the edge is recorded into the writer's own epoch at the tool call site. Constructed cross-session cases all bust; a correction cannot freeze another session's prefix and cannot extend past ridingRows/edge tips.
  • Ordering. The edge is noted only after markSuperseded returned true and the audit line recorded (update.ts:268-273); every PARTIAL outcome notes nothing, so a half-written correction busts rather than holds. Adoption (silent or full) clears corrections, so a moved epoch never carries stale edges back. The correction counterfactual still subtracts the session's same-turn pure additions, and deliberately keeps import-tagged additions in the comparison so a relevant import ends the hold instead of being absorbed.
  • Polarity. Inverted case checked: the non-authoring session does not get the benefit ("foreign" control, measured, and M1 below kills any broadcast).
  • Visibility. The model is shown the superseded text until the first revocation / set change / eviction / compaction; status reports the two counts separately and revocation counts honestly (invalidation yes, store fingerprint no).

Mutation checks (all applied in scratch, reverted after)

  1. Broadcast the hold to every session (noteCorrection records into all live epochs): killed by exactly one test — "foreign correction still refreshes the next request" (epoch.test.ts:830). Right pin, no redundancy.
  2. Hold never re-validates (if (cached?.holdsCorrection) return; before the pre-check): 8 tests fail — "a held correction survives a rephrasing…", "a same-session update preserves…", and six of the held-correction controls. The store-movement lifetime is heavily pinned.
  3. invalidate() keeps the epoch (the sharper lifetime mutant — hold outlives compaction): caught, but only by two accounting tests in test/inject/injection-accounting.test.ts ("context without an epoch does not count as abstention, before a prompt or after compaction"; "context before a prompt and after compaction stays uncached; compaction keeps lifetime counters"). They trip on counters, not on delivered bytes still showing the retired text. No test pairs compaction with a live hold — residual 1.
  4. Drop the updateLine receipt from the gate: 8 failures, all at the hold-behavior assertions themselves (toBe(frozen) / toBe(before)) — the failure names the real dependency, not an unrelated assertion.
  5. Fresh session inherits the author's correction (module-global edge map consulted at first epoch): killed by "a same-session update preserves the riding bytes and fresh sessions see the correction" — the fresh).toContain(latest) assertion. Right test.

Beyond the author's range (delivered bytes, head)

  • Two sessions correcting the same row: rider busts on the foreign successor and receives it — no cross-session freeze, and the foreign row is not papered over by the rider's own held chain.
  • Correction, then a second correction: hold survives the chain (turn 6 above); the delivered block keeps the original text while both corrections ride only the session's tool calls; a fresh session sees only the newest.
  • Correction of a non-riding row: no recompute on either revision — silent adoption, nothing rendered moved.
  • no-cache-freeze row: busts, correction delivered (measured above).
  • Correction followed by a store write to another row: foreign non-rendering write → hold continues, matching base silent adoption; own irrelevant write → hold continues (subtracted as an extra, same as the pure-addition rule).
  • Correction immediately before a set-growth turn: hold ends, delivered bytes match base exactly (dee8e850e421); the test-pinned variant records prompt_reveal with storeMoves 0. My variant also seeded a new row before the turn, so it recorded store_changed — correct precedence, the store did move.
  • Decay of a held tip: revokes and both versions disappear from delivery (store_changed, inv=1) — fail-closed, untested (residual 2).

Prose audit (mechanical)

Added lines grepped for issue refs, dates, narration: hits only on fixed fixture timestamps (2026-10-0x seed data). comment-lint clean (22 added comment lines vs merge-base). README diff: 0 lines. No claim in the added comments overstates the measurement — the docs bullet and the two ledger comments match what was measured here.

CI (all registered, none pending, head 42219c0)

check status duration
lint pass 13s
smoke pass 48s
smoke-stable pass 1m21s
test pass 1m2s
test-windows pass 2m53s

PR-body Windows totals (1,871 pass / 34 skips) come from the green Windows job and were not re-derived here; local macOS totals are 1889 pass / 22 skip.

What remains unverified (approval is not "reliable now")

  1. No direct test that compaction ends a hold. Measured correct (post-compaction ≡ fresh-session bytes), currently guarded only indirectly by the two abstention/lifetime-counter tests. A one-case addition (hold active → compaction → delivered contains the successor text) would close it.
  2. No test for decay/consolidation superseding a held tip. Measured fail-closed; add it to the controls bank next to the blocklist control.
  3. Provider-side cache billing is not measured by this PR or this seat — same honest ceiling #552 drew. The claim here is bounded to delivered bytes and byte-identical holds, which is what was proven.
  4. The real-store validator backstop (fingerprint replay over the live store) did not run in this seat; per contract it belongs before merge for src/inject changes.
  5. Delivered staleness during a hold is a product decision inherited from #550: the session is shown the superseded block text until the first revocation/set-change/compaction. Bounded as listed; the open question the PR body names (model behavior when the transcript holds both values) stays open.

Nothing merged, nothing pushed to the branch, live seat untouched on main.

@abogartz
abogartz merged commit a7d0c8a into abogartz:main Nov 27, 2026
5 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.37.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

A self-authored correction to a riding row still busts the cache though both versions are in the transcript

2 participants