fix(ocr): built-in reader must not accept symbol junk on real cursive (OCR_TRUST leaks on owner ink) #35
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
daniel/obsidian-remarkable-round-trip!35
Loading…
Reference in a new issue
No description provided.
Delete branch "agent/builtin-symbol-junk-gate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Related to #4 and #14. This is a follow-up to #4, which closed after being calibrated on synthetic data only. The first real capture of the owner's hand shows the leak #4 was meant to close.
Why
The owner's first real test sheet is in the repo at
handwriting-samples/test-sheets/2026-10-21-001026/handwriting-test-2026-10-21-001026.json. It has 18 lines of fast, joined cursive. The built-in reader accepted 2 of the 18 lines as pure symbol junk:Größe: 42 cm × 18 cm, Preis 12,50 €/IäI→✗rl…,%«%.Jl€Frage: ja oder nein? (siehe #14)@:@+m«↑@&↑3]Root cause:
OCR_TRUST = 0.78(src/ocr/recognize.ts:497) was calibrated on bundled-font fixtures, where cursive junk topped out at about 0.739. Junk on real ink reaches 0.788.recognize.ts:483-495already notes that symbol glyphs match cheaply. The owner's hand store now has symbol templates (@ → ✗ « ↑ % €…, 118 glyphs incapture.hand.glyphs), so joined strokes get tiled with them at high confidence.recognizeLocally(src/main.ts:1775), an accepted built-in reading means WritePad is never asked. On p2-06, WritePad would have producedFrage'oja oder rams.. (siehe # l4)and passed its own gate.Raising
OCR_TRUSTagain is ruled out. #4 said "do not blind-bump a constant", and the junk confidences (0.78–0.79) overlap the synthetic print floor (about 0.83) too closely to buy real margin.What to change
src/ocr/recognize.tsexport const OCR_MAX_SYMBOLS = 0.3.export function builtinTrusted(r: Recognition | null): boolean. It returnsr !== null && r.confidence >= OCR_TRUST && symbolFraction(r.text) <= OCR_MAX_SYMBOLS.symbolFraction= (non-whitespace chars that are not\p{L}or\p{N}) ÷ (non-whitespace chars). Use 1 for an empty string.OCR_TRUSTcomment:later → done ✓, not now ✗at about 0.21 andFrage: ja oder nein? (siehe #14)at about 0.19.src/main.ts— usebuiltinTrusted(result)in both places that currently compare againstOCR_TRUST:recognizeLocallyat about line 1775, so a rejected built-in reading falls through to WritePad.accepted:), so future captures record the same decision an import makes.OCR_TRUSTimport from main.ts if it becomes unused.scoreAbove(result.confidence, OCR_TRUST)still needs it, so keep it where it is still used.src/__tests__/recognize.test.ts(or a new small test). It covers:builtinTrustedrejects the two literal captured readings above at confidence 0.79.TEST_SHEET_PROMPTS(src/ink/handsheet.ts:71) at confidence 0.9.src/__tests__/fixtures/handwriting.tsmust stay trusted.Constraints and decisions
WRITEPAD_MIN_KNOWNwould also reject legitimate print that is mostly numbers and dates, such asTermin am 14.03. um 9:30 Uhr. The symbol gate needs no vault words, so it also works in the offline replay.OCR_TRUST,WRITEPAD_TRUST,WRITEPAD_MIN_KNOWN, or the order of readers.CAPTURE_FORMAT/ version 1).Scope boundary
NOT in scope:
Validation contract
builtinTrusteddoesn't exist or the junk is accepted.npx vitest run src/__tests__/recognize.test.ts→ PASS.npx vitest run→ whole suite PASS. In particular, the print fixtures inrecognize.test.ts/ocr.test.tsstay trusted.npm run build(tsc + esbuild) → exit 0, andnpx eslint srcis clean.HANDWRITING_CAPTURE=handwriting-samples/test-sheets/2026-10-21-001026/handwriting-test-2026-10-21-001026.json npx vitest run src/__tests__/testcapture.test.ts.🤖 Generated with Claude Code
claude referenced this pull request2026-10-21 00:18:52 +02:00
✅ Agent run completed
3m43s · 24 turns · $0.60 · pushed
agent/builtin-symbol-junk-gate· session saved — new comments resume this runWhat changed
src/ocr/recognize.ts: addedOCR_MAX_SYMBOLS = 0.3and a purebuiltinTrusted(r), which requires confidence ≥OCR_TRUSTand a symbol fraction ≤ 0.3. The symbol fraction is the share of non-space characters that are neither\p{L}nor\p{N}, and it is 1 for empty text. The calibration is documented next to the constant.OCR_TRUST,WRITEPAD_*, the reader order and the capture format are unchanged.src/main.ts:recognizeLocallyand the test-sheetaccepted:field now usebuiltinTrusted, so a rejected built-in reading falls through to WritePad. TheOCR_TRUSTimport stays becausescoreAbovestill uses it.recognize.test.ts: three new cases.TEST_SHEET_PROMPTSentry is trusted at 0.9, and still rejected just belowOCR_TRUST.PRINT_SAMPLESstay trusted.Verify
builtinTrusted is not a function).recognize.test.ts11/11 pass. The fullvitest rungives 778 pass / 0 fail / 1 skipped.npm run buildexits 0 andeslint src/is clean. No CI pipeline has run on this branch yet.later → done ✓, not now ✗), then 0.185 (Frage: …,Größe: …).Termin am 14.03. um 9:30 Uhrscores 0.130.2026-10-21-001026: p2-05 (0.7836) and p2-06 (0.7880) change fromaccepted=truetofalse. None of the other 16 items is accepted.HANDWRITING_CAPTUREreplay (no vault words, reported but not asserted): built-in mean CER is 94.8% captured vs 94.5% replayed, WritePad 29.6% vs 30.7%. On p2-06, WritePad now replays"Fragi 'oju odor namr..c side # 14)"(50.0% CER). The replay prints CER only, not confidences.Follow-ups
None. WritePad's accuracy on this hand and the neural reader stay in #14.
claude referenced this pull request2026-10-21 00:25:54 +02:00
claude referenced this pull request2026-10-21 01:04:37 +02:00
claude referenced this pull request2026-10-21 06:46:03 +02:00
claude referenced this pull request2026-10-21 06:46:04 +02:00