Skip to content

fix(recall): name the origin of keyword-only tokens in the ambiguous clause - #562

Merged
abogartz merged 1 commit into
mainfrom
fix/469-ambiguous-keyword-clause
Nov 27, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix/469-ambiguous-keyword-clause

Conversation

@ocsi-fixer

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

Copy link
Copy Markdown

Closes #469.

Defect

The AMBIGUOUS evidence clause prints a row's keywords as bare tokens even though the recall renderer never prints keywords, so the reader is told a row "only in" carries text that appears nowhere on screen.

Reproduction (measured at the base)

Calling the real ambiguousLine with row 1 the cache is invalidated on write + kw: ["python"] and row 2 the same content with no keywords produced, byte for byte:

AMBIGUOUS (release): rows 1 and 2 share shape but neither restates the other — only in 1: python. Action: neither supersedes the other. Pick by what you are actually doing; if both apply, use both.

python exists only in row 1's keyword field. Nothing rendered contains it.

Scope

The marker reaches exactly one surface: src/tools/recall.ts is the only call site of ambiguousLine, so the clause appears in memory_recall output and nowhere else. Injected blocks, memory_status, the viewer payload, and memory_list never render it.

Decision: option 3, label the origin

only in 1: python (keyword). Rejected, with the measured reasons from the architecture record:

  • Option 1 (render kw in the row): formatMemory output is pinned across every inject surface and is hashed into src/inject/version.ts. That is a delivery change, escalating a low-severity recall-tool wording fix into a different tier to fix a line the reader sees in one tool.
  • Option 2 (compute the clause from content-only sets): verified broken, not merely ugly — the clause list is gated by sides.length, so a pair whose only difference is a keyword renders the marker with no evidence clause at all, less informative than the current line.

Labeling rule

A token is labeled (keyword) only when it is not present in that row's rendered content. Because folded uniqueness (which is unchanged) already excludes any token another row carries — as content or as a keyword — the label can never claim a shared token is unique, and never claims a token is visible when it is only a keyword on the side being described. The mixed case follows the same rule in both directions: a token in row 1's content and row 2's keywords appears in no clause and carries no label, and so does its mirror; the visible content tokens still carry the clause unlabeled.

Untouched, deliberately

contentTokens is unchanged: it is pinned by test/recall/dedupe-scope-leak.test.ts (it must fold keywords into the vocabulary) and the clash grouping in src/recall/dedupe.ts depends on that folding — the fix is clause-level, exactly as the architecture record requires. formatMemory is unchanged: those bytes are hashed into the inject version and are out of scope for a recall-tool wording fix. Content-derived clauses are byte-stable — the existing pins in test/recall/ambiguous.test.ts (only in 2: example-images, example, images, only in 1: python) and test/recall/dedupe-tool.test.ts:215 pass unmodified, and a new full-clause byte pin covers the content-only fixture.

Tests

Six new tests in test/recall/ambiguous.test.ts: keyword-only on one side, content-only byte identity, the mixed case in both directions, keyword-only on both sides, and the token cap (the cap counts tokens, labels are decoration, every shown token keeps its label, withheld tokens stay absent).

Fail-before on the pre-fix base 48bdf6f (scratch worktree, this test file, no source change) — 15 pass / 3 fail, each failing on the unlabeled clause, not on imports or setup:

(fail) ambiguousLine > a keyword-only difference names its origin
  Expected: " — only in 1: python (keyword)"
  Received: " — only in 1: python"

The content-only and mixed-case identity pins pass on the base by design: they pin bytes that must not change, before and after.

Totals (fresh baseline at this base, not remembered numbers)

pass skip fail
base 48bdf6f 1869 22 0
this branch 1875 22 0

Drift is exactly the six added tests. typecheck, lint (biome lint + format), and lint:comments all pass.

Left open

Nothing in scope for this fix. If keywords should ever be visible in delivered rows, that is the option-1 delivery change the record places in a different tier — a separate decision, not a follow-up here.

Base

Branch fix/469-ambiguous-keyword-clause from origin/main at 48bdf6f72d783cee8a1a15f4c93d515a3b703cd4.

…clause

The AMBIGUOUS evidence clause is built from contentTokens, which folds a
row's keywords into its vocabulary, while the recall renderer prints only
content. A difference carried solely by keywords therefore printed as a
bare token, pointing the reader at text neither rendered row contains.

Label such a token with its origin ("python (keyword)"). The label
decision is per token against the row's own content set: a token the row
renders stays byte-identical, and one carried only by its keywords names
where it lives. Tokens shared with another row by any route were already
excluded by folded uniqueness, so no label can claim a shared token
unique or invisible. contentTokens and formatMemory are untouched: the
first is pinned by the scope-leak vocabulary test and depended on by the
clash grouping, the second feeds bytes hashed into the inject version.
@ocsi-fixer
ocsi-fixer Bot requested a review from abogartz as a code owner November 27, 2026 20:00

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

Review: full (constraints-first), adversarial. Verdict: APPROVE.

Reviewed 48bdf6f..3798af4 in scratch worktrees only. Shape confirmed first: one commit, direct child of base, exactly two files touched (src/recall/ambiguous.ts +14/−1, test/recall/ambiguous.test.ts +111/−0). Nothing else moved.

Constraint-by-constraint, against the issue body and the architect record

Constraints numbered as extracted verbatim; each proven on the surface it lives on.

C1 (record §1) "No bare token in the only in N: clause may be invisible on the surface where the marker appears. A keyword-only token is labeled with its origin; a content token is unchanged." — PROVEN. Recorded repro replayed against real modules: base 48bdf6f renders — only in 1: python. byte-identical to the record; head renders — only in 1: python (keyword). Defect present at base, gone at head. Keyword-only and content-unchanged each pinned; beyond-range constructions A–D (below) extend both directions past the author's fixture.

C2 (record §2) "The label must never lie… Pin that mixed case." — PROVEN. Both mixed directions are pinned (a token visible as content is not labeled… and its mirror): a token that is content on one row and keyword on the other is excluded from every clause by folded-uniqueness, and no (keyword) appears anywhere on those lines. My 3-member construction repeats this across a family: weekly (row 1 content, row 2 keyword) appears nowhere, while nightly stays bare and golang gains its label in the same clause — the per-token decision, not a per-row one.

C3 (record §3) "Both sides and the token cap keep working" (base :101-106, :130-168). — PROVEN. The cited capped-content, two-sided, three-member-family and per-source-drop tests pass unmodified at head. Cap boundary tested in both directions past the author's single case (F1–F4 below): at 5 and exactly 6 unique keyword tokens every token shows labeled with no overflow note; at 7 the cap holds at 6 elements, (+1 more), and the withheld token is absent from the whole line. The cap (list(), ambiguous.ts:23) slices element count after labeling, and labels are appended inside each element — so the count is token-based either way: labels neither overrun the cap nor drop tokens the base kept. Selection indices are identical to base.

C4 (record §4) "Content-token output stays byte-stable… ambiguous.test.ts:39, :66 and dedupe-tool.test.ts:215 must not change." — PROVEN. All three pins pass unmodified (diff hunk touches neither test). The new a content-only difference keeps its clause bytes pin asserts the full clause with toBe, which is stronger than the pre-existing toContains — see pin-strength note below.

C5 (record, Code truth) "contentTokens must not change. The fix is clause-level." — PROVEN. src/recall/dedupe.ts byte-identical base↔head (cmp clean); it is not in the diff's file list at all.

C6 (rejected option 1 / scope) "injected blocks, memory_status, viewer, memory_list never render the marker; option-1's bytes are out of scope." — PROVEN FROM THE FILE LIST, not from the claim. Only ambiguous.ts and its test changed, so format.ts and version.ts cannot have moved. ambiguousLine has exactly one call site (src/tools/recall.ts:121); storeVersion hashes JSON.stringify([m.ts, formatMemory(m)]) over row data — no import edge from the inject path to ambiguous.ts. The change cannot alter injected bytes.

C7 (rejected option 2) keyword tokens must stay in the clause. — PROVEN: head keeps python in the clause with its origin; the sides.length gate line is untouched by the hunk.

C8 (issue "Where") change belongs in the sides loop of ambiguousLine. — PROVEN: the single hunk is the sides.push in that loop; contentSets it consumes already existed at base :127 (#468), so the fix completes that precedent rather than adding a rule.

Scoping / index alignment (the class this shape risks most)

sets, contentSets, and positions are all aligned to members by construction (two .map()s and one parameter, no reordering between build and use), and the label reads contentSets[i] with the same i as sets.forEach((t, i) — the same member's content set. Stronger: a clause token is folded-unique, so it is in no other member's folded set and therefore in no other member's content set. Any "other member's set" index is false for every clause token, which means a wrong-index mutation cannot mislabel a keyword as bare — it can only mislabel visible content tokens as keywords, and only content-token pins can catch it.

Constructing that visible difference: m1 = content "alpha report generated daily", kw ["python"]; m2 = content "alpha report generated weekly". Correct clause: — only in 1: daily, python (keyword); only in 2: weekly. Fixed-index contentSets[0] renders only in 2: weekly (keyword); off-by-one renders only in 1: daily (keyword), python (keyword); only in 2: weekly (keyword). Both mislabels are exactly what the author's content-byte and mixed pins assert against, and the mutants confirm it.

Mutation outcomes (full suite per mutant, worktree-confined edits)

# Mutation Result Killed by
1 label every token killed new a content-only difference keeps its clause bytes; both mixed pins; pre-existing names both rows… (:39 substring breaks at the first comma once the first token gains a suffix)
2 remove the label killed exactly the three new pins: keyword-only origin, both-sides labeled, cap-keeps-labels
3 fixed index contentSets[0] killed same four as #1
4 wrong member (i+1) % n killed same four as #1

No survivors. No mutant needed an unrelated test for its kill — so no pin here is redundant. Mutant runs also produced 3–5 unrelated failures (lock-timeout scenario, tokenizer cost, negative-eval control, capture-refusal) at ~30 s timeouts; isolated re-runs on the mutant source pass 66/66 and 7/7 in 16 s / 7 s — load artifacts of my five concurrent suite runs, recorded here so the corrected result is on the record, not a mutant effect.

Fail-before re-measured independently: head test file on base source = 15 pass / 3 fail, the three failing on unlabeled clause bytes, not imports — matches the PR record exactly.

Beyond the author's range (constructed, observed clause strings, head)

  • Three members, keyword-only on every side: — only in 1: python (keyword); only in 2: ruby (keyword); only in 3: golang (keyword)
  • Mixed across a 3-member family (weekly content row 1 / keyword row 2; golang keyword row 3): — only in 2: daily; only in 3: nightly, golang (keyword) — shared mixed token absent everywhere; bare and labeled coexist in one clause
  • Keyword identical to a word in that row's own content: — only in 1: python (content wins, no label)
  • Keyword a substring of a content token (node kw, nodes in content): — only in 1: node (keyword) — truthful, the literal token node is keyword-borne; see remaining notes
  • Cap boundary keyword-only, 5 / exactly 6 / 7 unique: all shown labeled, no (+ more) / all 6 shown, no (+0 more) / 6 shown labeled + (+1 more), withheld token absent from the line
  • Cap boundary mixed content+keyword (2 content + 8 keyword unique): — only in 2: yankee, zulu, lima (keyword), mike (keyword), november (keyword), oscar (keyword) (+4 more) — content tokens bare even at the boundary; cap counts elements
  • Token content in both rows: never labeled (no (keyword) anywhere in the line)

Inherit-and-verify

  • ambiguous.test.ts:39, :66, dedupe-tool.test.ts:215, dedupe-scope-leak.test.ts:50-59: all pass at head; the three content-clause pins unmodified. contentTokens byte-identical base↔head.
  • Full suite at head, run myself: bun test ./test/ --parallel=4 --timeout=20000 → 1875 pass / 22 skip / 0 fail (1897 across 155 files, 15099 expect, 190.5 s). Matches the author's claim exactly.
  • typecheck, biome lint, biome format, lint:comments: all pass at head.
  • CI (gh pr checks 562): lint pass 10s · smoke pass 1m4s · smoke-stable pass 1m11s · test pass 56s · test-windows pass 3m19s. All registered; no polling needed.

Prose audit

Added lines grepped for issue refs, dates, narration: clean. The new source comment explains the constraint (findability; folded-uniqueness guarantee) rather than citing a ticket; test comments state contracts, with cross-references to sibling tests only.

Stated plainly for the record (not blockers)

  1. Pin strength, noted not fixed: the two pre-existing single-token pins (toContain("only in 1: python") at ambiguous.test.ts:66 and dedupe-tool.test.ts:215) also pass against a wrongly-suffixed python (keyword). The strict coverage lives in the new toBe clause pins and the :39 multi-token substring, so the invariant is guarded by multiple assertions — not a one-assertion risk, but the :66-style pins should not be mistaken for byte pins.
  2. The substring case (node (keyword) when nodes is visible) is truthful per token but the reader may conflate the pair; pre-existing tokenizer granularity, out of scope here.
  3. Each labeled token adds ~11 bytes to the clause; the cap counts tokens so line growth is bounded at 6 labels. Accepted by the option-3 decision; nothing to change.
  4. Unverified by construction, accepted on argument + file list: that no future import edge from src/inject/** into ambiguous.ts is maintained — that is #450-territory hygiene, not this diff's.

Nothing unfixed remains in scope; no mutation survived; all eight constraints proven. Approving. Not merging.

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

Copy link
Copy Markdown

🎉 This PR is included in version 0.37.3 🎉

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.

The AMBIGUOUS marker's evidence clause can name a keyword the reader is never shown

1 participant