Repository navigation
fix(capture): one figure grammar for the availability matcher - #499
Conversation
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.
There was a problem hiding this comment.
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-restatedandfigure-sentence-dot-cost-restated("expected a restatable verdict, got none").test/store/tombstones.test.ts:627:55fails (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:
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 ofoperandsDeclaredontofigureExtent.bench/fixtures/availability-cases.ts—1,2,3→123canonicalization unpinned (only1,2was disclosed); verified unreachable as a false refusal.src/core/tokenize.ts:82—isWordCharexported with no consumer outsidetokenize.ts.src/core/tokenize.ts:131—rawTokensis still a second copy of the word class (reporting-only).src/core/tokenize.ts:177— comma canonicalization is pinned only bytombstones.test.ts:627; all 62 bank rows survive its removal.- PR body says "60 rows (54 pre-existing plus 6 new)"; actual is 61 (55 + 6).
src/store/tombstones/tombstone.ts:181— persistednumhashes carry no grammar-version stamp; drift is two-directional: restatements of old dotted-tail values fail open (keep), and a contrived candidate stating1and024separately can collide with an old1,024hash 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
- Tombstone
numhashes have no grammar-version stamp — the disclosed1.5.versus1.5drift recurs silently on every future grammar edit, including the contrived block-direction collision in nit 7. introducesNewNumberfirst-match union — one gate vouches all content figures whileoperandsDeclaredre-hits per span. Latent, disclosed, unfixed.- Prose commands still never reach the gate path (pinned as a limit, not fixed).
1,2/1,2,3read as single figures12/123— ratified grammar,1,2,3unpinned.- 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.
|
🎉 This PR is included in version 0.34.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Note 🤖 GPT-6.2 Astra responding on behalf of WhollyMindless One performance follow-up for 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 |
|
@WhollyMindless please log a ticket to track this. |
Reproduction on
maind5fa338eBoth wrong verdicts reproduced before touching anything:
The limit is 1,024 rows.against candidateThe 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,figureRundoes not see the,as figure territory, the hit is admitted, the region slice ends before024, and the vouch set becomes{1}. The tree never states1.The ratio is 1.5.against candidateThe 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,figureRunsees a run crossing the hit edge, and the hit is rejected. Same shape withThe cost is 11.5.versusThe cost is 11.5.The ticket's named examples (
3.12,11.5truncations) stay green and untouched — bank rowsfigure-trunc-version-tailandfigure-trunc-dotless-tailalready pin them.Fix — one figure grammar
figureExtent(text, pos)is exported fromsrc/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,9ae0998are one figure;1.5.states1.5.numericTokenscompares canonical values (grouping commas dropped). Inavailable.ts,hitCoversFiguresandsplitClaimscallfigureExtent, and the hand-copiedisTokenCharchar 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):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 totest/store/tombstones.test.tsalso 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 exportedisWordCharso 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 readtokens(); none of them can see a difference, and the full suite plus the e2e gate confirm it.The ratio is 1.5against a tree stating1.5.keeps costing duplicates. A passes all three of the review's distinguishing cases; B structurally failsfigure-sentence-dot-restated.isTokenCharshould call the exported definition. It no longer exists:figureRunwas its only caller, andfigureExtentreplacesfigureRunoutright, so the char class was deleted rather than made to delegate. Nothing inavailable.tsnow 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.figureExtentextends over the whole word run, soRun v2againstRun v2.txt daily.still keeps and5 now.againstfile.md5still 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
numericTokens: the four pre-existing pinned assertions stay green unchanged; id tokens (9ae0998) stay whole;1, 5(comma plus space) stays two figures;v2.txtstays one token.Evidence line (
matched) — judged, left unchangedThe 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 1against a tree saying1,024) is now unconstructable and pinned dead byfigure-comma-grouped-truncation. Carrying raw region text instead would need a case-preserving haystack: the scan lowercases vianorm()andredactSecretsmatches 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— passbun run lint— pass (afterbiome formatnormalised the new block intokenize.ts)bun run lint:comments— clean, 65 added comment lines checked against merge-basebun run test— 1752 pass, 22 skip, 0 failbun run gate): all green, including the e2e suite (48 pass) against a real isolated hostWhat remains unfixed
introducesNewNumberfirst-match union the map flagged (one gate vouches all figures in the content whileoperandsDeclaredre-hits per span): latent, every construction the review found fails open, out of scope here.prose-command-not-a-code-span.1,2(digit-comma-digit without a grouping convention) reads as the single figure12— 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.1.5.where new candidates hash1.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