Skip to content

fix(capture): one figure grammar for the availability matcher - #499

Merged
abogartz merged 1 commit into
mainfrom
fix/498-figure-grammar
Nov 23, 2026
Merged

abogartz merged 1 commit into
mainfrom
fix/498-figure-grammar

Conversation

@ocsi-fixer

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

Copy link
Copy Markdown

Reproduction on main d5fa338e

Both wrong verdicts reproduced before touching anything:

  1. False refusal — fact lost forever. Tracked The limit is 1,024 rows. against candidate The limit is 1 → REFUSED in_tracked_file. tokens("the limit is 1,024 rows.") = ["the","limit","is","1","024","rows."] — the comma splits the grouped figure, figureRun does not see the , as figure territory, the hit is admitted, the region slice ends before 024, and the vouch set becomes {1}. The tree never states 1.
  2. Missed refusal — duplicate costs a row. Tracked The ratio is 1.5. against candidate The ratio is 1.5 → kept. tokens("the ratio is 1.5.") = ["the","ratio","is","1.5."] — the sentence-final period is glued onto the figure, figureRun sees a run crossing the hit edge, and the hit is rejected. Same shape with The cost is 11.5. versus The cost is 11.5.

The ticket's named examples (3.12, 11.5 truncations) stay green and untouched — bank rows figure-trunc-version-tail and figure-trunc-dotless-tail already pin them.

Fix — one figure grammar

figureExtent(text, pos) is exported from src/core/tokenize.ts: a digit-bearing word run where . and , join only between digits and a sentence-final dot is trimmed — 1,024, 1.4.3, 9ae0998 are one figure; 1.5. states 1.5. numericTokens compares canonical values (grouping commas dropped). In available.ts, hitCoversFigures and splitClaims call figureExtent, and the hand-copied isTokenChar char class is deleted. tokens() output is unchanged (below), so GATE-3 floors and the rejection sketch score on exactly what they scored before.

Fail-before

New bank rows run against an export of the pre-fix tree (git archive d5fa338e + the new fixtures overlaid):

figure-comma-grouped-truncation: expected no verdict (keep the row), got in_tracked_file matched [the limit is 1]
figure-sentence-dot-restated: expected a restatable verdict, got none
figure-sentence-dot-cost-restated: expected a restatable verdict, got none
    at test/capture/availability-case-bank.test.ts:67:7   →   59 pass, 3 fail

The three same-shape controls added with them (figure-comma-grouped-restated, figure-comma-grouped-whole-sentence, figure-sentence-dot-carried-restated) pass pre-fix by design — they pin the side of the boundary that already behaved, so a green bank proves the relation moved rather than weakened. The tokenize-level pins added to test/store/tombstones.test.ts also fail pre-fix: numericTokens("the limit is 1,024 rows.") returned ["1","024"] at line 627.

Layer defence — A, one grammar, on measurement

The ticket's real defect is the rot mechanism the review mapped: two definitions of a figure edge, one of them hand-copied, CI green whichever one you fix. Layer A is the right layer because it removes the second definition instead of synchronising the two, and measurement says the blast radius the map feared is empty:

  • tokens() output is provably unchanged. The split-regex implementation was rewritten as a scan over the exported isWordChar so the char class and the split rule are one definition, and the result was fuzzed against the old regex over 300,000 random strings (full ASCII range plus multi-byte and NUL) and four repo files: zero mismatches. GATE-3 scoring, value-conflict and the tombstone sketch read tokens(); none of them can see a difference, and the full suite plus the e2e gate confirm it.
  • Alternative B (edge abstention) cannot fix half the ticket. B is veto-only — it can only remove refusals. The comma false refusal it converts to keep; the missed refusal is already a keep and stays one, so The ratio is 1.5 against a tree stating 1.5. keeps costing duplicates. A passes all three of the review's distinguishing cases; B structurally fails figure-sentence-dot-restated.
  • Deviation from the map, stated loudly. The map said isTokenChar should call the exported definition. It no longer exists: figureRun was its only caller, and figureExtent replaces figureRun outright, so the char class was deleted rather than made to delegate. Nothing in available.ts now decides where a figure begins or ends — which is what the contract comment above it demanded — and the deletion enforces that more strongly than a delegating copy would.
  • Word protection is kept, not widened. figureExtent extends over the whole word run, so Run v2 against Run v2.txt daily. still keeps and 5 now. against file.md5 still keeps (probe-verified). A digits-only extent would have refused both — a new false-refusal class — and that is why the exported extent is a word run with trailing dots trimmed, not a bare digit run.

Blast-radius and corpus measurement

  • Bank corpus, all 60 rows (54 pre-existing plus the 6 new ones) re-decided on both source trees: exactly 3 verdict changes, all 3 the new verdict-changing rows; the 54 pre-existing verdicts are identical. Refusal count 20/60 → 21/60 (the added refusal is a true one — the tree states the row).
  • numericTokens: the four pre-existing pinned assertions stay green unchanged; id tokens (9ae0998) stay whole; 1, 5 (comma plus space) stays two figures; v2.txt stays one token.

Evidence line (matched) — judged, left unchanged

The map asked whether the evidence line should carry the tree's figure. After this fix it cannot diverge from the tree: a refusal requires every claim to match the region verbatim modulo formatting, the gaps between claims to be punctuation-only (no digits can hide there), and the region to vouch every figure canonically — so the region's figure set is the candidate's figure set by construction. The auditor's tree-side handle is where, and the mismatch the review measured (matched: the limit is 1 against a tree saying 1,024) is now unconstructable and pinned dead by figure-comma-grouped-truncation. Carrying raw region text instead would need a case-preserving haystack: the scan lowercases via norm() and redactSecrets matches case-sensitively, so — the file's own comment says it — redacting after normalisation "cannot recover what normalisation already destroyed"; putting tree text into the evidence line would leak recoverable access keys for a telemetry field.

Verification (budget: once each)

  • bun run typecheck — pass
  • bun run lint — pass (after biome format normalised the new block in tokenize.ts)
  • bun run lint:comments — clean, 65 added comment lines checked against merge-base
  • bun run test — 1752 pass, 22 skip, 0 fail
  • Push gate (bun run gate): all green, including the e2e suite (48 pass) against a real isolated host
  • No separate local e2e before the gate: this changes verdicts, not capture timing.

What remains unfixed

  • The introducesNewNumber first-match union the map flagged (one gate vouches all figures in the content while operandsDeclared re-hits per span): latent, every construction the review found fails open, out of scope here.
  • Prose commands still never reach the gate path — recorded as a limit by prose-command-not-a-code-span.
  • 1,2 (digit-comma-digit without a grouping convention) reads as the single figure 12 — the grammar the map ratified; both sides of every comparison read it identically, and no realistic refusal is reachable through it because the claims must still match verbatim.
  • Tombstone rows written before this change hashed 1.5. where new candidates hash 1.5: a restatement of a previously-rejected dotted-tail value reads as a value change and is kept. Fail-open direction — one redundant row — and no durable log rewrite is attempted here.

Closes #498

A figure is decided once, by figureExtent in core/tokenize.ts: a
digit-bearing word run where a dot or comma joins only between digits
and a sentence-final dot is not part of the figure. The comma used to
split 1,024 into 1 + 024, so a truncation of 1 was refused as a
restatement of 1,024 and the fact was lost; the glued dot made 1.5
unmatchable against a tree stating 1.5., so a verbatim restatement was
kept. numericTokens now compares canonical values, hitCoversFigures and
splitClaims read the exported extent, and the hand-copied char class in
available.ts is gone so the two definitions cannot drift apart again.

Bank rows pin both edges plus same-shape controls. tokens() output is
unchanged (fuzzed against the old split regex over 300k strings and
repo prose), so GATE-3 scoring and the rejection sketch are untouched.
@ocsi-fixer
ocsi-fixer Bot requested a review from abogartz as a code owner November 23, 2026 20:02

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

Verdict: APPROVE

No blockers. Nits and disclosed follow-ups below. Seat untouched; no push, no merge, no CI rerun.

Orchestration note (read first)

The brief said the seat is main at d5fa338e. It was not — the checkout sat on fix/498-figure-grammar at 1d407da, clean. Any probe importing the seat path measures the fix, not the bug. My first repro pass "contradicted" the issue for exactly this reason. All pre-fix numbers below come from a git archive d5fa338e export. One local ref was created (pr-499 via fetch); no worktrees.

Repro on d5fa338e (export) — reproduces

tree candidate main head
The limit is 1,024 rows. The limit is 1 REFUSED (false refusal) kept ✓
The ratio is 1.5. The ratio is 1.5 kept (missed refusal) REFUSED ✓
The cost is 11.5. The cost is 11.5 kept (missed refusal) REFUSED ✓

Controls (1,024 rows restated, 1.5. carried, IP mid-sentence) correct on both sides. Head full suite: 1752 pass / 22 skip / 0 fail.

Fail-before, personally observed

Pre-fix export + overlaid PR fixtures:

  • availability-case-bank.test.ts — 59 pass / 3 fail, exactly the claimed rows, each for its stated reason: figure-comma-grouped-truncation ("expected no verdict (keep the row), got in_tracked_file matched [the limit is 1]"), figure-sentence-dot-restated and figure-sentence-dot-cost-restated ("expected a restatable verdict, got none").
  • test/store/tombstones.test.ts:627:55 fails (numericTokens("the limit is 1,024 rows.") → ["1","024"] ≠ ["1024"]).

Mutation table

mutant result
drop comma-join in isRunChar (tokenize.ts:96) killed — bank figure-comma-grouped-truncation + tombstones:627
drop trailing-dot trim in figureExtent (tokenize.ts:123) killed — both dot bank rows + tombstones:627
re-introduce local figure char class in hitCoversFigures (available.ts:703) killed — all 3 verdict rows die; a local copy cannot hide
drop canonical comma-strip in numericTokens (tokenize.ts:177) killed only by tombstones:627 — bank survives 62/62. Nit 5

Honesty note: the first mut-dot run "survived" — the edit had silently not applied (indent mismatch in the assert). Corrected and re-run; it dies. The table shows the corrected run.

Class-first audit

26 adversarial cases + 7 polarity cases, base vs head. Every base→head delta is a fix in the correct direction — recovered missed refusals (Set to 3., Requires Python 3.12., Version 1.2.3., Bind to 10.20.30.40., Ends at 11., v2., 0.75.) and killed comma false refusals (The pool has 80 vs 80,443, x 1 vs 1,2). Zero new false refusals found. Two head "misses" in the table are identical on base and semantically defensible (weaker restatement of a stated fact; pre-existing gate-path shape) — not regressions. Polarity separation intact. Gate-path word/figure separation verified live: row `npm run deploy --pool 80,443` versus manifest --pool 80443 → keep on head, because operandsDeclared compares tokens() word runs while introducesNewNumber compares canonical figures.

Architecture claims tested, not accepted: tokens() unchanged — independent fuzz, 200,000 strings (full ASCII, multi-byte, NUL, separators), 0 mismatches, claim holds. "Separation survives only because two checks cross-veto" — refuted in the dangerous direction: the old classes are deleted, the bank kills a re-introduced local class, and the gate-path separation is behaviorally verified.

Findings

Blockers: none.

Nits, none of which hold merge:

  1. bench/fixtures/availability-cases.ts — the row pinning the word/figure separation (manifest --pool 80443, candidate --pool 80,443, expect keep) is absent; behavior is currently correct, nothing pins it against a future port of operandsDeclared onto figureExtent.
  2. bench/fixtures/availability-cases.ts — 1,2,3→123 canonicalization unpinned (only 1,2 was disclosed); verified unreachable as a false refusal.
  3. src/core/tokenize.ts:82 — isWordChar exported with no consumer outside tokenize.ts.
  4. src/core/tokenize.ts:131 — rawTokens is still a second copy of the word class (reporting-only).
  5. src/core/tokenize.ts:177 — comma canonicalization is pinned only by tombstones.test.ts:627; all 62 bank rows survive its removal.
  6. PR body says "60 rows (54 pre-existing plus 6 new)"; actual is 61 (55 + 6).
  7. src/store/tombstones/tombstone.ts:181 — persisted num hashes carry no grammar-version stamp; drift is two-directional: restatements of old dotted-tail values fail open (keep), and a contrived candidate stating 1 and 024 separately can collide with an old 1,024 hash set and get blocked.

Prose audit

Added lines: no issue numbers, dates, ratios, or investigation narration. README: 4024 words on both sides — unchanged. ADR 0009 rewritten in place, no ticket refs.

What remains unfixed

  1. Tombstone num hashes have no grammar-version stamp — the disclosed 1.5. versus 1.5 drift recurs silently on every future grammar edit, including the contrived block-direction collision in nit 7.
  2. introducesNewNumber first-match union — one gate vouches all content figures while operandsDeclared re-hits per span. Latent, disclosed, unfixed.
  3. Prose commands still never reach the gate path (pinned as a limit, not fixed).
  4. 1,2 / 1,2,3 read as single figures 12 / 123 — ratified grammar, 1,2,3 unpinned.
  5. Nits 1–5.

Approval means: the predicate's two disclosed defect classes are fixed, the fix is pinned from both ends, and no new wrong-verdict class was found in ~35 self-constructed inputs plus a fuzz. It does not mean the matcher is reliable in general — items 1 and 2 are live design debts.

@abogartz
abogartz merged commit 597ad4c into main Nov 23, 2026
4 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.34.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@WhollyMindless

Copy link
Copy Markdown
Contributor

Note

🤖 GPT-6.2 Astra responding on behalf of WhollyMindless

One performance follow-up for numericTokens: an ordinary word without digits is now scanned once per character. For configuration, each of the 13 calls to figureExtent locates the same word boundaries and checks the same letters for a digit. Each returns null, so the caller advances just one character. That makes the work quadratic in the length of an individual digit-free word. I traced the loop on 1d407da; I haven’t measured an end-user latency impact.

A forward scan could consume the whole run once and then decide whether to emit a figure. That would preserve the shared grammar. I separately checked that 1,024 yields 1024 and sentence-final 1.5. yields 1.5 on this head. Tokenizer loop

@abogartz

Copy link
Copy Markdown
Owner

@WhollyMindless please log a ticket to track this.

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.

B5: figure-edge false refusal in capture availability (region slices dotted figures)

2 participants