OCR: gate the WritePad fallback on reading quality and make it attributable/toggleable #11
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!11
Loading…
Reference in a new issue
No description provided.
Delete branch "agent/ocr-writepad-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?
Part of #4 (which is Part of #2). This is work item 3 of 3. The WritePad WASM reader (
src/ocr/writepad.ts) is a hidden fallback insidebuiltinmode that leaks partial-junk readings aboveWRITEPAD_TRUST, and its confidence is a poor discriminator between good and bad reads. Gate it on reading quality, and expose it so "junk" can be attributed and turned off.Measured evidence (reproduce it; I ran this during investigation)
Reading bundled-font cursive strokes via
WritePad.load()thenengine.read(strokes, lexicon), with a lexicon containing all the sentence's words:The problem: a near-perfect read ("meeting is an Monday", CER 0.05) scores 0.682 and is rejected, while a partial-junk read ("…po,frjunql5", CER 0.32) scores 0.720 and is accepted. WritePad's own confidence does not rank reads by correctness, so bumping
WRITEPAD_TRUSTalone cannot separate good from junk — it would throw away the good 0.682 read too. This is why #4 calls for a quality gate, not a threshold bump.What to do
A. Quality gate (required)
Add a gate in
WritePad.read()(or where its result is consumed) that requires the reading to be made of recognisable words, not just score high. Concrete, measurable options (pick one, justify against the table):lexicon(vault vocabulary). "the quick brown po,frjunql5" →po,frjunql5(and arguablypo,frjunql5) not known → fails; "meeting is an Monday" → all known → passes. This directly inverts the current mis-ranking.read().wordsKnown()already exists inwritepad.ts:130; thechoose()path already knows which words are vault-known. Reuse that signal rather than re-deriving it.WRITEPAD_TRUSTonce the quality gate carries the weight — if you lower it, the gate must prevent the junk from the table above from passing. State the final (threshold, gate) pair and why.B. Expose WritePad (design decision — recommendation below)
Today WritePad is invisible:
recognizeLocally()(src/main.ts:1702) silently falls to it when the letter reader is belowOCR_TRUST. Make it attributable and switchable. Recommended (simplest, lowest-risk): add a boolean settingocrUseWritePad(defaulttrueto preserve current behaviour), shown insrc/settingschema.tsunder the OCR section withvisibleWhen: { key: "ocrMode", equals: "builtin" }, help text explaining it reads joined-up writing and can be turned off if it produces junk. Gate the fallback inrecognizeLocallyon it. (The sibling diagnosability MR !9 already surfaces which reader fired, so the two together let a user see WritePad firing and switch it off.) If you instead judge a distinctocrModedropdown option cleaner, that is acceptable — document the choice in the MR.C. Red-gate fixture + test
Add to
writepad.test.ts: renderwrite("the quick brown fox jumps", "allure", 0.5), build a lexicon from its words, and assert that after the quality gate the result is rejected (null, or below-trust / gated-out) — i.e. does not return "the quick brown po,frjunql5". It must fail on today's code (0.720 passes) before your change. Also add a positive case: a cursive read whose words are all vault-known is kept (guard against the gate silently rejecting everything — a false "clean"). The existingchoosetests atwritepad.test.ts:66must still pass.Scope boundary
src/ocr/writepad.ts,src/main.ts(recognizeLocally wiring), settings (settingsmodel.ts+settingschema.ts),writepad.test.ts.main.ts:recognizeLocallyand the settings schema. Recommended merge order: !9 first, then rebase this on it (!9 refactorsrecognizeLocallyto return{text, by, score}, which this builds on cleanly). If this lands first, !9 rebases instead — no logic conflict, just adjacent edits.Validation contract
nix develop -c npx vitest run src/__tests__/writepad.test.ts→ PASS, including the new red-gate test (fails onmain) and the positive keep-case.nix develop -c npm test→ PASS.nix develop -c npm run build→ clean.Note: no
flake.nixin this repo — run directly:npm cithennpx vitest run src/__tests__/writepad.test.ts(Node 24 on PATH). Verified during investigation.Part of #4.
claude referenced this pull request2026-10-20 15:22:09 +02:00
✅ Agent run completed
7s · 1 turns · $3.06 · pushed
agent/ocr-writepad-gate· session saved — new comments resume this runclaude referenced this pull request2026-10-20 15:22:46 +02:00
claude referenced this pull request2026-10-20 15:22:46 +02:00
WritePad's confidence does not rank reads by correctness: a partial-junk read ("the quick brown po,frjunql5", 0.72) out-scores a near-perfect one, so WRITEPAD_TRUST alone cannot separate good from junk. Add a quality gate in WritePad.read() that requires at least two-thirds of a reading's own words (those the vault could index, length >= 2) to be vault-known — this rejects the 0.60-known junk while keeping the 1.0-known good read and still tolerating one unknown word in three. choose() now carries the known/token counts so the gate reuses the signal it already computes. Expose the fallback as a new boolean setting ocrUseWritePad (default true, builtin mode only) so a user who sees it producing junk can turn it off; recognizeLocally only falls to WritePad when it is on. Co-Authored-By: Claude Opus 4.8 <[email protected]>What changed
WritePad.read()(src/ocr/writepad.ts): a reading is now rejected unless ≥ 2/3 of its vault-indexable words (length ≥ 2) are vault-known. WritePad's confidence doesn't rank reads by correctness, so this inverts the mis-ranking: junk"the quick brown po,frjunql5"(0.72, 0.60 known) is dropped, while"meeting is on Monday"(0.74, 1.0 known) is kept — and one unknown word in three is still tolerated.choose()now returnstokens/knowncounts so the gate reuses the signal it already computes.WRITEPAD_TRUSTkept at 0.7 (the gate carries the discrimination the threshold can't; lowering it wasn't needed — the good read already clears 0.7). Gate only applies when a lexicon is passed, so existing no-lexicon reads are unchanged.ocrUseWritePad(defaulttrue,settingsmodel.ts+settingschema.ts, visible only inbuiltinmode): lets a user turn the cursive fallback off if it produces junk.recognizeLocallyinmain.tsonly falls to WritePad when it's on. (Pairs with !9's "which reader fired".)Verify
nix develop -c npx vitest run src/__tests__/writepad.test.ts→ 8 pass, incl. the new red-gate test (verified it fails onmain— returns the 0.72 junk instead ofnull) and the positive keep-case (guards against the gate rejecting everything).npm test→ 655/655.npm run build→ clean. No per-MR CI pipeline runs on this repo; verification is the local validation contract, all green.Follow-ups
recognizeLocally(my change adds&& this.settings.ocrUseWritePadto theelsebranch) — no logic conflict; whichever lands first, the other rebases cleanly.claude referenced this pull request2026-10-20 16:34:09 +02:00
claude referenced this pull request2026-10-20 16:34:09 +02:00
claude referenced this pull request2026-10-20 18:57:33 +02:00
claude referenced this pull request2026-10-20 18:59:19 +02:00