Repository navigation
fix(inject): refresh the frozen memory block when its rows change - #65
Merged
Merged
Conversation
The frozen injection block was keyed on (active row count, newest ts). A hand redaction, a viewer edit or a blocklist entry changes neither, so the old text (a leaked secret or a blocked instruction) kept going out on every model request until the next prompt that also changed the count. - storeVersion hashes each visible row's ts and rendered form, so edits, redactions, block/unblock, forget and supersede all change it. - The epoch is re-checked in the request-time context hook, not only at prompt time, so a removal takes effect on the very next request. The latest prompt is kept per session for re-scoring. - If nothing visible changed, the block stays byte-identical. The digest already changes on every write, so this adds no extra cache misses. - One loaded row set per request is shared by the fingerprint, relevance scoring and the digest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
abogartz
approved these changes
Oct 24, 2026
abogartz
left a comment
Owner
There was a problem hiding this comment.
Approve — the staleness is real and reproduced; the restructure is safe against the one host-ordering assumption it depends on. Three wording/robustness items below; none block merge for me.
What I re-verified on 0.8.1 (main @ 4643ec4)
- Hand redaction: seeded a row containing a key, prompted, saw the key injected; rewrote the day file in place (same
ts, same row count) → the old key still rode the next request, and still rode it after a fresh prompt. Fixed on your branch. - Mid-loop block: row injected →
addBlock(ts)→ the poisoned row still rode the next request with no new prompt. Fixed on your branch. - The host-ordering assumption your restructure depends on (
session.promptmust run beforesession.context, otherwise a store change during a tool loop gets re-scored against the previous prompt): I probed a realopencode v2.0.26turn with a scripted tool loop. Observed order wassetup → session.prompt → session.context → tool.before → session.context, i.e. prompt-first and onecontextper model request.latestPrompt.set()thenrefreshEpoch()in the prompt hook is therefore correct, and the loop re-scores against the current prompt. - Cache stability: three consecutive requests with an unchanged store produced byte-identical injected parts (same sha256). Cost: 200
storeVersion()passes on a 60-row store = 26 ms on main vs 32 ms here, ~0.03 ms per request. Not a concern. - 290 pass / 4 skip / 0 fail at head; 3 of your tests fail against main's source;
tscclean; biome warnings identical to main.
Please fix (wording / bookkeeping)
- "The digest line … already changes on every write and sits before this block, so this adds no new cache misses" is not true for the case you are fixing. The digest's
latest:is the maxts, so a same-tshand-edit leaves the digest unchanged — which is exactly why the stale block survived. Your new fingerprint changes there, so this PR does add one cache bust per out-of-band edit. That is the correct trade (correctness over one bust), but please say it plainly instead of claiming zero cost. latestPromptandepochare unbounded per session.latestPromptholds the full prompt text of every session a long-lived server has ever seen, and nothing evicts on session end/archive (compaction only).src/repokey.tsalready hasSESSION_CAP = 64for exactly this shape of leak — cap these the same way or evict together.- Positional-parameter collision with #66. You add
systemDigest(input, output, rows?), #66 addssystemDigest(input, output, budget). A naive merge picks one side and #66's own test then failstscwithTS2345: Argument of type 'number' is not assignable to parameter of type 'Memory[]'(I merged all six PRs to check; a working resolution issystemDigest(input, output, rows?, budget?)+mems, budgetat the call site). Please convert both to one options object —systemDigest(input, output, { rows, budget })— so this class of merge error is impossible rather than merely caught by CI.
Note
refreshEpoch keeps the single-load-per-request property you claim (the same rows feed storeVersion, relevantKnowledge and systemDigest). flushStatus still does its own loadAll on a recompute, unchanged from main.
This was referenced Oct 24, 2026
|
🎉 This PR is included in version 0.8.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Contributor
Author
|
Thanks for merging. Your three points:
|
abogartz
pushed a commit
that referenced
this pull request
Oct 24, 2026
One 64-session LRU (same cap as repokey.ts) evicts epoch, latestPrompt, sessionStats and measuredTurns together. It is touched in the prompt and context hooks and in message.updated. An evicted session gets no relevance block until its next prompt, then a fresh "first" epoch, so it never sees stale state. Follow-up to #65, where latestPrompt made the leak worse. Closes #75. Co-Authored-By: Claude Opus 5.5 <[email protected]>
abogartz-opencode-self-improvement Bot
pushed a commit
that referenced
this pull request
Oct 24, 2026
## [0.8.6](v0.8.5...v0.8.6) (2026-10-24) ### Bug Fixes * **inject:** bound per-session state in a long-lived server ([ee67acd](ee67acd)), closes [#65](#65)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The frozen relevance block keeps sending a memory after it's been redacted or blocked. I found this while reviewing 0.8.0, and it's unchanged in 0.8.1.
The problem: the epoch fingerprint is
${activeCount}:${maxActiveTs}, and it's only re-checked in theprompthook. That causes two failures:On 0.8.0, with the repro:
With this PR, neither does.
Change:
storeVersionhashes each visible row'stsand its renderedformatMemoryline, so edits, redactions, block/unblock, forget and supersede all change it.contexthook re-checks it before every model request, re-scoring against that prompt. A removal therefore takes effect on the very next request. (Thanks for checking the prompt-before-context order against a real 2.0.26 turn.)ts, such as a hand redaction. The digest'slatest:is the maxts, so it doesn't change in that case, which is exactly why the stale block survived before. Blocks and mid-loop removals also now invalidate on the next request rather than the next prompt, so the invalidation counter ticks slightly more often. That's the intended trade, correctness over one cache miss, but it isn't free.Tests (
test/epoch.test.ts):storeVersionchanges on a same-ts content edit.With the source change reverted, the new tests fail.
Checks (Linux, Bun 1.4.4, on 0.8.1):
bun test ./test/286 pass, 4 skip, 0 fail.bun run test:e2eagainst opencode 2.0.26: 9 pass.tsc --noEmitis clean, andbiome lintexits 0 with warnings unchanged frommain. It usesnode:cryptoSHA-256 and nothing platform-specific.Follow-up: the options object for
systemDigestis in #66, and the bounded per-session maps (#75) are in #77.🤖 Generated with Claude Code