Repository navigation
feat(#42): use ledger — what retrieval actually surfaced, and what it never does - #98
Merged
Merged
Conversation
abogartz
force-pushed
the
feat/hits-log
branch
from
October 25, 2026 18:18
d64c56c to
54e7718
Compare
added 2 commits
October 25, 2026 12:34
…idation The retrieval-quality epic needed ground truth for "did injection work": whether a memory was actually surfaced, how often, and how recently — and the honest view of how much of the store never is. - src/hits.ts: an append-only ledger (<memory-root>/hits.logfmt) with (ts, session, source, term, ts+scope of the memory, kw). Sources: `inject` (rode the epoch block), `pull` (returned by memory_recall), `recall` (rendered by contextualPull). One row per memory per session per source per hour; the term is a scan-truncated string from the MEMORY SIDE (the triggering message is never stored), and a hit is recorded only for rows sharing >=2 terms with the trigger — the same bar as scoring, never an assistant-selection signal. - Ledger rotation at 512 KB keeps the newest rows; the file is excluded from ingestion (RESERVED) and cleanup; ts+scope is verified against the store on read so a re-ingested or moved row cannot inherit reinforcement (unmatchable rows are counted, never credited). - scoreMemories use-aware tie-break: score first, open threads, then last-use recency (recent first), then row recency. Reinforcement never outranks a real score gap: useBoost <= 1.0 keeps every ordering #40's tests pinned. - Consolidation now respects use recency: a never-used settled row can be absorbed by the newest row (the #40 behaviour), but the most-recently- used row in a cluster is never the merge loser — recency in the boost is not recency in the ledger. - memory_status reports retrieved-in-30d, never-retrieved count and share, the oldest never-retrieved row, and unmatchable ledger rows. The numbers are reported, not acted on — retirement stays a decision. Test: test/hits.test.ts (ledger write/shape per source, injection records only block rows, throttle, term privacy, rotation keeps newest, re-ingestion cannot inherit reinforcement, use-boost ordering, merge consolidation by use recency, status lines) ticket: #42
The ledger shipped with no call sites, so nothing recorded and nothing consumed it. The e2e scenario (e2e/ledger.test.ts) is what caught it: a real opencode turn against the real plugin now asserts that a matching message credits exactly the rows that rode the block. - src/index.ts: `noteHits()` records (source, session, rows, shared terms) at the three surfaces — `inject` after an epoch block is built (only the rows that survived the budget), `pull` at the contextual-pool call site (only the rows that actually appended), `recall` inside memory_recall (only what the tool returned). Terms come from sharedTerms(): memory-side vocabulary, never the prompt. The scoring path reads the ledger through useSignals(), so the use tie-break is live instead of theoretical. - src/status.ts + src/tui.tsx: store counts carry `neverRetrieved`, rendered as "retrieved N rows in the last 30d; never retrieved M (P%) — reported, not acted on", in memory_status and in the TUI STORE panel. - e2e/ledger.test.ts: capture two facts, match one with a later message, recall it explicitly, then read the report. Asserts the ledger's row shape, that terms are memory-side only (the prompt never appears), that a block credits only its own rows, and that used + never-retrieved = active. ticket: #42
abogartz
force-pushed
the
feat/ranking-recency-kw
branch
from
October 25, 2026 19:44
5a525b9 to
3a91bfd
Compare
abogartz
force-pushed
the
feat/hits-log
branch
from
October 25, 2026 19:45
54e7718 to
e8dc708
Compare
added 2 commits
October 25, 2026 12:54
Adversarial review findings on #98, all four in the same direction — the surfaces claimed more than the ledger can know: - THROTTLE_MS was 60s while the PR body argues for an hour throttle; the hour is the design (retry storms vs. distinct sessions), so the code now matches it, and MAX_HITS_BYTES moves 512 KB -> 2 MB so the ring's retention is closer to the 30-day window it feeds. - a freshly installed ledger sees every row used zero times, and day one would have read "never retrieved 100%". StoreCounts carries ledgerSince; report and TUI qualify the number ("ledger only covers since ...") whenever it cannot honestly span 30 days (ledgerIsYoung). - resetLedgerCache's comment claimed writes invalidate the cache; nothing calls it on writes. The comment now describes the real TTL behaviour the tie-break depends on.
The PR body described test/hits.test.ts; it had never existed — e2e/ ledger.test.ts covered the wiring, but the module promises went unpinned. Twelve tests now pin them: line shape per source, the empty row-set and the 8-term cap, term privacy against the row's own vocabulary, the throttle and each axis of its key, the ring dropping the older half whole-line, a re-ingested row denied the old identity's credit, neverRetrieved/usedRecently over the 30-day window, use recency breaking ties but never crossing score gaps, and the young-ledger qualifier on both report paths.
abogartz-opencode-self-improvement Bot
pushed a commit
that referenced
this pull request
Oct 25, 2026
# [0.11.0](v0.10.0...v0.11.0) (2026-10-25) ### Bug Fixes * **#42:** the ledger keeps the promises its surfaces make ([25e38f9](25e38f9)), closes [#42](#42) [#98](#98) ### Features * **#42:** use ledger, injected-terms source, recency-in-boost consolidation ([68c89f7](68c89f7)), closes [#42](#42) [#40](#40) [#42](#42) * **#42:** wire the use ledger into every read path ([e8dc708](e8dc708)), closes [#42](#42) [#42](#42)
|
🎉 This PR is included in version 0.11.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Contributor
|
Two cases where the use ledger and the tool result disagree. We reproduced both on the PR head (
A matching-prompt control delivered the row in the system section and recorded one injection credit. For a regression test, comparing the provider’s actual tool message with the ledger catches the grep mismatch even when both the grep and ledger write succeed. |
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.
Closes #42
Part of #84. Depends on: this stack is sequential — merge order #96 → #97 → this PR → #44 → #45. Base is
feat/ranking-recency-kw; rebase-free because each branch stacks on the previous.What this does
Gives the store ground truth about its own retrieval: which memories were actually surfaced, how often, how recently — and the honest number of how many never are.
The ledger —
src/hits.tswrites an append-onlyhits.logfmtunder<memory-root>/:inject— rows that actually rode the epoch block (not everything that scored).pull— rows returned bymemory_recall, including the keyword-bridge arm.recall— rows rendered bycontextualPull(the tool path).RESERVED) and from cleanup; rotation at 512 KB keeps the newest rows.ts+scopeare verified against the store on read. A hit whose memory no longer matches is counted as unmatchable and earns no credit — this is the P0: Value-keyed rejection tombstone — rejected content must stay rejected across re-ingestion #35 re-ingestion scenario: a retired-and-resurrected row must not inherit reinforcement from its previous life.Use-aware ranking (the consolidation #40 asked for, done carefully).
scoreMemories's tie-break is now: score → open threads → last use (recent first) → row recency.useBoost ≤ 1.0, so reinforcement never outranks a real score gap — #97's pinned orderings still hold. The consolidation rule follows use recency: a never-used settled row can be absorbed by the newest row (the #40 behaviour), but the most-recently-used row in a cluster is never the merge loser — recency in the boost is not recency in the ledger.Reporting —
memory_statusnow carries retrieved-in-30d, the never-retrieved count and share, the oldest never-retrieved row, and unmatchable ledger rows. The numbers are reported, not acted on; retirement stays a decision you make.Why this shape
(ts, scope)pair, so the moment the store stops agreeing, the credit stops.Tests
test/hits.test.ts(12 tests) — added during the adversarial review: this file did not exist when the PR was opened, though this body described it. It now pins, at unit altitude: the exact line shape per source; the empty row-set no-op and the 8-term cap; term privacy against the row's own vocabulary (every stored term is a word the row already contains; prompt-only words never appear); the throttle window and each axis of its(source, session, row-set)key; the ring dropping the older half whole-line while the newest survives; a re-ingested row denied the retired identity's credit;neverRetrieved/usedRecentlyacross the 30-day window; use recency breaking a score tie but never crossing a real score gap; and the young-ledger qualifier on the report. "Only the rows that rode the injected block" is a plugin-wiring property and is pinned end-to-end ine2e/ledger.test.ts, not here.tscclean; Biome clean.Review focus
recordHitsreceives the raw prompt.useBoostas shipped is a pure tie-break — present in the ledger (1) vs absent (0); it is never multiplied into the score, so reinforcement can never cross a real IDF gap. (An earlier draft of this body described a frequency multiplier capped at ≤1.08; the shipped rule is stricter.) Open question unchanged: should use ever beat a score gap? (Today: no.)Review addendum (post-open fixes, pushed as
25e38f9+e678e17)Own adversarial pass after opening found three places where the surfaces
promised more than the ledger can know, all fixed on this branch:
the design;
THROTTLE_MSnow matches it, andMAX_HITS_BYTESmoved to2 MB so rotation retention is closer to the 30-day window.
zero times, so day one read "never retrieved 100%".
StoreCountsnowcarries
ledgerSince, and both report paths (and the TUI) qualify thenumber — "ledger only covers since …" — whenever it cannot honestly
span 30 days.
resetLedgerCache's comment claimed writes invalidate the cache;nothing calls it on writes. The comment now describes the real TTL
behaviour the tie-break depends on.
test/hits.test.ts(above) came out of the same pass.