Skip to content

Injection-side use-ledger credit and the abstained counter survive mutation: both documented, neither pinned #177

Closed

Description

@abogartz

What this is

Two invariants in the injection accounting path are documented in comments and pinned by nothing. I found them while mutation-probing #172 (which relocates this code from src/index.ts into src/injection-epochs.ts), and I confirmed both are pre-existing on main — this is a coverage gap in the #68 epic, not a regression from that PR.

Method: apply the mutation, run the full unit suite (bun test ./test/).

mutation on main (20bb57e, inline code) on #172 head (80d7200, controller)
delete the injection-side use-ledger credit 644 pass / 0 fail 647 pass / 0 fail
count abstained unconditionally 644 pass / 0 fail 647 pass / 0 fail

For reference, seven neighbouring mutations in the same controller ARE caught (dropping latestPrompt.delete from invalidate, dropping measuredTurns.delete from eviction, no-op touch, dropping the storeVersion pre-check, emptying the epoch's prompt so the #165 counterfactual cannot re-score, and two in src/host.ts), so this is a targeted hole, not general weakness.

Gap 1 — nothing proves injection credits the rows that rode the block

src/injection-epochs.ts:218-222 (was src/index.ts, same code):

// Use ledger (#42): the rows that actually rode the block, credited with
// the terms the prompt and those rows shared (never the prompt itself).
// Only once the build is ADOPTED — a discarded rebuild must not credit
// rows that were already offered under the frozen epoch.
await noteHits(sid, built.rode, prompt);

Three claims in that comment, all unverified: (a) injection credits at all, (b) it credits only built.rode (the budget-surviving rows) rather than the wider candidate pool, and (c) it credits after adoption, so a discarded #165 riding-bytes rebuild cannot re-credit rows. Deleting the statement entirely changes no test result.

Why it matters: the hits.logfmt ledger is what neverRetrieved() reports and what useSignals() feeds back into ranking (#42, #40). If injection stopped crediting, the visible symptom is only that "never retrieved" grows and ranking slowly degrades — no test, no evidence line, no surfaced number complains. To be precise about what is covered: test/hits.test.ts pins recordHits() itself for the "inject" source (throttle, per-session/per-row keying, empty-terms behaviour), but it calls the function directly — nothing pins that the injection path calls it, which is exactly why removing the call site is invisible.

Suggested pin (hook level, reusing the test/epoch-lifecycle.test.ts harness): prompt a session with a term that selects a known row, run one session.context hook, then read the ledger and assert (i) an entry for that session/row exists with terms drawn from the row ∩ prompt, and (ii) after a store_changed refresh whose rebuild is discarded by the riding-bytes rule, the ledger gains no new credit for the discarded render.

Gap 2 — abstained counts what the comment says it must not

src/injection-epochs.ts:288-294:

// Abstained = the epoch exists but its block is empty.
if (knowledge) st.cumChars += knowledge.length;
else if (epoch.has(sid)) st.abstained++;

Changing the else to an unconditional st.abstained++ leaves the suite green, so nothing pins the epoch.has(sid) half of the definition — precisely the case that separates "we had candidates and the budget dropped them all" (a real abstention worth showing) from "this session has no epoch yet, e.g. the first session.context before any prompt" (nothing to abstain from).

Why it matters: abstained is a user-visible number — src/status.ts:369 prints it in the session line (N request(s) · … rode · abstained M), src/status.ts:487 tells the reader what it means ("your prompt shares no content vocabulary with any memory, so nothing was injected"), and src/status.ts:122's own field comment defines it as "requests where the epoch block was empty". Counting no-epoch requests as abstentions would make a fresh session look starved by the budget, and the bug class is exactly the one #162/#165 were about: a metric that silently stops meaning what its label says.

Suggested pin: for a session that has never had a prompt, one session.context call must leave abstained at 0; for a session with a frozen epoch whose block renders empty, one call must move it to 1. readStatus(sid).stats.abstained is already observable in-process, so both fit the existing lifecycle test file.

Scope note

Fixing either gap is a test:-only change (no version bump under semantic-release), and neither blocks #172 — moving code that was already untested cannot lower coverage. Filing it here because the extraction is the moment these lines get a new home and a new test file beside them.

Activity

  1. added
    test-integrity
    on Oct 29, 2026
  2. abogartz-opencode-self-improvement commented on Oct 29, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.19 🎉

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    releasedtest-integrity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions