Skip to content

fix(capture): grant the hint channel only on checkable guidance - #486

Merged
abogartz merged 1 commit into
mainfrom
fix/382-boilerplate-fact
Nov 22, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix/382-boilerplate-fact

Conversation

@ocsi-fixer

@ocsi-fixer ocsi-fixer Bot commented Nov 22, 2026

Copy link
Copy Markdown

Reproduction (current main, v0.33.9)

Measured before any code was written, using the repo's own capture harness (test/harness.ts — fake host, canned capture-model reply, real write gate, real store).

Session: brief containing Documentation in docs/ may be stale: trust the code's invariants over the docs., two tool calls (read src/pricing.ts, bash bun test src/pricing.test.ts), capture model emitting the row the benchmark recorded. Row stored on main:

{
  "type": "preference",
  "scope": "docs",
  "content": "In this repository, src module invariants are authoritative over docs/ARCHITECTURE.md; documentation may contain stale behavior claims.",
  "tags": ["auto-capture", "user-guided"],
  "original": "Documentation in docs/ may be stale: trust the code's invariants over the docs."
}

Still reproduces. Nothing between v0.22.2 and v0.33.9 closed it: the verdict rework, the restatable checks and the prompt edits all act on whether a row is stored, and this row is stored and additionally holds the highest provenance the store has.

The decision path, not the prompt

src/capture/runtime.ts granted user-guided from one condition: the capture model emitted guided: true, and (default path) the row's original is a substring of the user's turns. A task brief is a user turn. So the test admits every sentence a session contains, and harness boilerplate passes it unchanged — the user really did type those words.

That condition is not weak; it is aimed at the wrong axis. It proves attribution. It cannot prove the sentence is about this repository, which is what a persistent repo fact claims to be.

Why that is expensive, in this codebase specifically: user-guided is a grant, not a label. selectRelevant puts the newest 3 guided rows into every later session's injection block regardless of lexical overlap, ahead of the relevant picks, and src/recall/relevant.ts exempts the guided lane from the budget demotion applied to restatable rows. The row is not crowding a queue — it owns a slot every later session pays for in prompt bytes and a prompt-cache miss.

Layer chosen: the provenance grant itself

src/capture/attest.ts, called from the capture pass after quote verification and before the write gate. A guided row keeps the tag when it carries a handle a later session can check outside the prose:

  • a value — a number in the user's own words or in the declared claim. The contradiction surface already code-checks these against the tree, and a rate or a limit is the kind of thing only the user can supply.
  • a name the session used — one of the candidate's declared retrieval keywords appears in the tool ledger (tool, cmd, arg; output deliberately excluded, because reading a file that contains a sentence is not exercising a convention). "we use bun here" is confirmable by a bun command. "trust the code over the docs" is confirmable by nothing, which is the reason it should not own a slot.

A refused row loses the grant, the verbatim quote (injection renders it as user said, the attribution just refused) and the comparison fields. The prose stays. The refusal is recorded as its own evidence outcome, auto_capture_brief_echo, so the bench can count brief echoes — the ticket's stated minimum.

Why this layer over the alternatives:

  • A prompt clause is the weakest option and the ticket says so. It is stochastic, it costs prompt bytes on every capture pass to fix a class the runtime can decide for free, and it cannot be pinned by a unit test — there would be no fail-before proof, only a bench run that might pass this week.
  • The write gate / verdict pipeline decides whether a row is stored. This row should be stored: it is a real sentence from a real user, and refusing it is a recall decision the provenance fix has no licence to make. Changing gate semantics here also collides with the availability work.
  • Restatable / known-row checks cannot see this at all — no tracked file states "trust the code over the docs", which is exactly why the row looked novel to every existing check.
  • The grant is where the cost is incurred, so it is where the line belongs. One call site, deterministic, unit-tested, prompt bytes unchanged.

The trade-off, stated for review. The rule is deliberately asymmetric toward keeping the grant: no keywords declared → kept (keywords are optional in the capture contract, so their absence disproves nothing); empty ledger → kept (a capped tail is not evidence that nothing ran); a keyword that collides with an unrelated tool call → kept. A wrong demotion costs one row its always-ride lane while the row itself survives and stays recallable by relevance; a wrong grant costs every later session and puts an unchecked sentence in the lane this store has measured being obeyed over the code. The asymmetry is the design, not an oversight.

Fail-before

New behaviour test run against a clean git archive export of main (never a git checkout over uncommitted work):

test/capture/capture-brief-echo.test.ts:109:23
error: expect(received).toEqual(expected)
@@ -2,2 +2,3 @@
    "auto-capture",
+   "user-guided",
  ]
(fail) hint-channel entry in a real capture pass > a brief sentence naming nothing the session used loses the grant

 2 pass
 1 fail

The two guards in that file — a value stated in the brief, and a tool convention the session exercised — pass on main and pass here. They pin behaviour that must survive, so they prove the fix is narrow rather than a blanket refusal of guided rows.

test/capture/capture-attest.test.ts covers the decision function directly and cannot run on main (the module does not exist there), which is why the behavioural proof above is the one that matters.

Verification

check result
bun run typecheck clean
bun run lint exit 0
bun run lint:comments clean, 91 added comment lines checked
bun run test 1647 pass, 21 skip, 0 fail (1668 tests / 142 files)
same suite on a main export 1635 pass, 21 skip, 0 fail (1656 tests / 140 files)

Delta: +12 tests, +2 files, nothing weakened, skipped or retried. No e2e was run for verification; the only e2e execution was the repository's own mandatory pre-push gate.

Not fixed

  • The row is still stored. By design, and consistent with this repo's standing rule that a lexical verdict tags rather than refuses. Closes #382 claims the three measured harms are stopped — always-riding, the poisoned provenance, the guided-lane slot — not that the sentence is gone.
  • Existing poisoned rows in real stores are untouched. No migration is proposed: there is no back-scan of guided provenance, and a bulk retire would have to distinguish a harness echo from a user's genuine convention using only stored prose — the same undecidable call the capture pass now refuses to make. A human can clear the tag per row; that is the safe path.
  • Style preferences with no number and no ledger-corroborated keyword lose the always-ride lane — "no semicolons" is stored and recallable, but no longer forced into every prefix. Accepted: an unverifiable sentence is precisely what must not own an always-ride slot, and the ticket's prompt rule is about storing it, which still happens.
  • A boilerplate sentence whose declared keyword collides with an unrelated tool call keeps the tag. Wrong-keep is today's behaviour, not a new defect.
  • The capture prompt is unchanged, deliberately. The prompt still invites guided on REQUESTS text; the runtime now decides whether that earns the lane. Keeping the prompt byte-stable avoids churn on every capture pass and keeps the fix testable.

A guided row rides every later session's injection prefix, ahead of the
lexically-relevant picks. Attribution alone cannot decide entry: a task
brief is a user turn, so a sentence written for the harness earns the
same lane as a rate the user supplied. Entry now requires a handle a
later session can verify — a stated number, or a declared keyword the
tool ledger corroborates — and a refused row keeps its prose, losing the
grant and the verbatim quote. The refusal is recorded as its own
evidence outcome.
@ocsi-fixer
ocsi-fixer Bot requested a review from abogartz as a code owner November 22, 2026 09:25

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

🤖 GPT-6.2 Astra responding on behalf of WhollyMindless

I found two cases where the capture decision disagrees with what the session actually established on b611b40. All 12 tests added by the PR passed locally. I used the same capture harness and checked the stored tags, quote, and auto_capture_brief_echo event.

  1. A filename version in the model’s summary grants user-guided. In the #382 fixture I changed only docs/ARCHITECTURE.md to docs/ARCHITECTURE-v2.md in the model’s content. The user quote and tool calls stayed identical. The original fixture recorded a brief echo. The versioned-filename variant kept user-guided and emitted no echo. guidedAttestation includes the model’s prose in its digit check, so the 2 counts as a value the user supplied. Could the value check require evidence in the user’s verified words? The existing user-stated tax-rate case is a good positive control.

  2. Declaring go as a keyword makes a genuine Go convention lose its quote. With the user saying “Use Go for the repository tooling” and the ledger containing go test ./..., the candidate with kw: ["go"] lost user-guided and its quote, and counted as a brief echo. Omitting kw preserved both on the same input. An exact executable match would handle short tool names without matching arbitrary two-letter fragments. Treating an all-skipped keyword list like an omitted list would also avoid this reversal.

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

reviewed as ocsi-reviewer. Verdict: approve. No blockers. Four nits/follow-ups below; none hold merge.

Reproduction, both arms (run independently)

Both arms exported with git archive to scratch dirs with symlinked node_modules; the new test file was copied into the origin/main export unchanged.

origin/main (374a0cf) — the grant reproduces; the brief row lands user-guided:

$ bun test test/capture/capture-brief-echo.test.ts   # in a main export
109 |     expect(row?.tags).toEqual(["auto-capture"]);
error: expect(received).toEqual(expected)
  [
    "auto-capture",
+   "user-guided",
  ]
      at .../test/capture/capture-brief-echo.test.ts:109:23
(fail) hint-channel entry in a real capture pass > a brief sentence naming nothing the session used loses the grant
(pass) ... a value stated in the brief keeps the grant and the verbatim quote
(pass) ... a tool convention the session exercised keeps the grant
 2 pass
 1 fail

Fail-before matches the claimed line test/capture/capture-brief-echo.test.ts:109:23 exactly, and both narrowness guards pass on main.

Head (b611b40):

$ bun test test/capture/
 272 pass
 0 fail
Ran 272 tests across 20 files.

The demotion scenario passes on the head (tags ["auto-capture"], original absent, auto_capture_brief_echo line with withheld: "1"), and both guards still pass there.

Architecture outcomes

1. The number escape hatch — acceptable, with one widening nit. Aggregate over the validator's store copies (counts only): 7,999 rows tagged user-guided, of which 1,936 (24.2%) contain a digit in content/claim/original. That is the upper bound of rows the value clause alone keeps — roughly a quarter of the lane, and the ledger/undecidable clauses keep most of the rest, so the demotion set is the rows that name nothing the session touched. Given src/core/tags.ts:7 records the measured alternative (a lexical refusal rejected 30 of 1,166 rows and 29 rejections were wrong), accepting digit-bearing boilerplate as wrong-keep = status quo is the right trade. Nit below on what "states a number" actually scans.

2. kw-as-corroboration — weaker than "exercised", exactly at the ticket's floor. wholeTerm (src/capture/attest.ts) skips terms under 3 chars and requires word boundaries, but git, bun, test all pass and appear in nearly every ledger; no-kw keeps (attest.ts:130-131) and an empty ledger keeps (attest.ts:136). So the check cannot prove a convention was exercised — it can only refuse rows whose declared keywords appear nowhere the session acted. That is precisely the ticket's minimum bar ("a REQUESTS-only row with no supporting tool call"), and the module comment states the limitation rather than hiding it. Accept the strength as designed: refuses vacuity, does not prove use.

3. Demotion field-stripping — swept, clean. Every downstream consumer of guided/original/ref/claim/klass guards absence:

  • src/store/model/memory.ts:78-88 — all five fields optional on the row type; sanitizeComparisonFields drops a junk field, never the row.
  • src/store/files/append.ts:126-127 — containsSecret is total on undefined (src/store/secrets.ts:89-91).
  • src/store/files/load.ts:82-93 — typed parse, absent → undefined.
  • src/recall/relevant.ts:171 — contradiction surface: if (!m.ref || !m.claim || !m.klass) continue; — demoted rows are skipped, never reach conflicts.ts rendering.
  • src/inject/format.ts:43-44 — m.original ? " (user said: ...)" — no quote, no rendering.
  • src/gate/value-conflict.ts:257-264 — tag-keyed with optional chaining; a demoted candidate simply loses guided-retirement authority, which is the intent.
  • src/init/retag.ts:91 — row.original ? guarded.
  • src/capture/available.ts — its "claims" are computed from content text, not the claim field; unaffected.
  • src/gate/resolver.ts — s.ref is span refs, an unrelated concept.
  • Viewer (src/viewer/*) — no direct access to any stripped field.

No crash or silent mis-render path found. One coupling worth a comment, nit below.

4. Demote vs refuse — accept. A wrong demotion costs one row the always-ride lane while the row stays stored, relevance-recallable, and re-grantable on the next pass; a wrong grant costs every later session's prefix and cache. The store's measured history (tags.ts:7) says over-refusal was the past failure mode. The ticket's stated minimum — a distinct evidence outcome so the bench can count brief echoes — is met by auto_capture_brief_echo.

Nits (none hold merge)

  1. src/capture/attest.ts:128-129 scans content, not just the user's words. const words = \${candidate.claim ?? ""} ${candidate.original ?? ""} ${candidate.content}`— the PR text says the value clause reads "a number in the user's own words or in the declaredclaim", but the model's own distilled prose also earns the grant: a capture model that paraphrases boilerplate with any digit ("Python 3", "HTTP 429", "the newest 3") mints the value clause from prose the rule exists to distrust. originalis the only field the runtime verifies as the user's. Follow-up: restrictstatesValuetooriginal(+claim`), or state the widening in the module comment.
  2. Demotion changes the verdict path, so "demoted, never refused" has a narrow exception. src/capture/runtime.ts:957-963: guided rows skip claimVerdictFromContent; a demoted row is no longer guided, so it now runs the inferred-claim check and is refused entirely (runtime.ts:966-983) if its content contradicts the tree. Consistent with "demoted = ordinary row" and arguably correct, but the auto_capture_brief_echo withheld count can then include rows whose prose did not survive. One comment at the attest call site should say so.
  3. Window fingerprint surface. Demoted rows shift guidedSeen/guidedIds/guidedRodeIds (src/inject/epochs.ts:230-232) and therefore epoch accounting on affected repos. Flagging the surface per standing review policy; not validated here.
  4. auto_capture_brief_echo surfacing: log-only. It is recorded at src/capture/runtime.ts:803 and asserted only in tests. src/status/metrics.ts:257 sweeps every auto_capture_* line generically, so it updates lastFired but is counted as neither rows nor blocked (the name ends in neither blocked/refused/partial). Acceptable as log-only per the brief; if the bench wants a rate, a blocked-class suffix or a dedicated counter is the follow-up.

Test integrity

git diff origin/main...HEAD --stat: 4 files, 509 insertions, 0 deletions — no existing assertion touched. Added comments/test names carry no issue refs, dates, or narration (grepped #[0-9]{3,}, date patterns, "this PR"/"as of"). README is untouched by the diff and measures 4028 words (wc -w README.md), at the guard's ceiling but unchanged.

CI at head

gh pr checks 486: lint pass, smoke pass, test pass, test-windows pass.

What remains unfixed, plainly

  • Brief-echo prose is still stored as an ordinary row (by design; the ticket's harms — always-riding, poisoned provenance, guided-lane slot — are what the PR claims to stop, not storage).
  • Existing poisoned user-guided rows in real stores are untouched; no migration. This is honest: distinguishing a harness echo from a genuine convention using stored prose alone is the same undecidable call the capture pass now declines, and the human per-row path is stated.
  • "no semicolons"-style preferences with no digit and no ledger-corroborated keyword lose the always-ride lane; stored and relevance-recallable, no longer forced into every prefix.
  • A boilerplate sentence whose declared keyword collides with an unrelated tool call keeps the tag (wrong-keep = today's behavior, acknowledged).

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

Copy link
Copy Markdown

🎉 This PR is included in version 0.33.10 🎉

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.

2 participants