Fix OCR-sourced detection in pipeline_service.recheck()
ocr_only detection only matched page_reports status "ocr_only", not
"ocr_raw_words" - if every page of a recheck needed the per-page
raw-OCR-words fallback (Docling failed on all of them), this incorrectly
treated the recheck as non-OCR-sourced, letting it reach "Verified" when
there was no second engine to earn that on. Now checks membership in
("ocr_only", "ocr_raw_words").
Verified directly (not just via measure.py, which never exercises
recheck()): an all-ocr_raw_words page_reports now correctly surfaces the
ocr_source check and stays below Verified; a mixed ocr_only/ocr_raw_words
case does the same; a normal dual-engine case is unaffected - confirmed
both as a direct function call and through /api/recheck on the real
running app. measure.py confirms zero regression elsewhere.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
01cd607728
commit
081ab6ac50
23
CLAUDE.md
23
CLAUDE.md
|
|
@ -282,15 +282,20 @@ and the hardest case — the 2-page scanned-PDF OCR + per-page raw-OCR-words fal
|
|||
(`docs/scanned_statement_2page.pdf`) — came back byte-for-byte identical (17/17
|
||||
transactions, same signs, same balances, same per-page engine attribution).
|
||||
|
||||
One pre-existing latent bug found during this relocation, *not* fixed (Stage 1 was a
|
||||
zero-behavior-change move, not a bug-fix pass): `pipeline_service.recheck()`'s
|
||||
`ocr_only = any(pr.get("status") == "ocr_only" for pr in page_reports)` only checks for
|
||||
the `"ocr_only"` status value, not `"ocr_raw_words"` — if every page of a recheck's
|
||||
`page_reports` ended up `"ocr_raw_words"` (Docling failed everywhere, the per-page fallback
|
||||
rescued every page), this would incorrectly treat a genuinely OCR-sourced recheck as not
|
||||
OCR-sourced, letting it reach "Verified" when it shouldn't be able to. Carried over
|
||||
verbatim from the original `pipeline.py` — worth fixing in a dedicated pass, not bundled
|
||||
into a structural move.
|
||||
One pre-existing latent bug found during this relocation, fixed 2026-10-11 in a dedicated
|
||||
follow-up pass (deliberately not bundled into the structural move itself):
|
||||
`pipeline_service.recheck()`'s OCR-sourced check originally only matched the `"ocr_only"`
|
||||
page status, not `"ocr_raw_words"` — if every page of a recheck's `page_reports` ended up
|
||||
`"ocr_raw_words"` (Docling failed everywhere, the per-page fallback rescued every page),
|
||||
this incorrectly treated a genuinely OCR-sourced recheck as not OCR-sourced, letting it
|
||||
reach "Verified" when it shouldn't be able to. Now checks membership in
|
||||
`("ocr_only", "ocr_raw_words")`. Carried over verbatim from the original `pipeline.py`
|
||||
until this fix. Verified directly (not just via `measure.py`, which only exercises
|
||||
`pipeline_service.run()`, never `recheck()`): an all-`"ocr_raw_words"` `page_reports` now
|
||||
correctly surfaces the `ocr_source` check and stays below "Verified", a mixed
|
||||
`ocr_only`/`ocr_raw_words` case does the same, and a normal dual-engine `"ok"` case is
|
||||
unaffected — confirmed both as a direct function call and through `/api/recheck` on the
|
||||
real running app.
|
||||
|
||||
**Governing rule: never silently correct or exclude data.** This shows up in several
|
||||
concrete places, not just as an abstract principle:
|
||||
|
|
|
|||
|
|
@ -148,7 +148,14 @@ def recheck(transactions, page_reports, period_text=None, opening_balance=None,
|
|||
period_start = checks_service._parse_date(m.group(1))
|
||||
period_end = checks_service._parse_date(m.group(2))
|
||||
|
||||
ocr_only = any(pr.get("status") == "ocr_only" for pr in page_reports)
|
||||
# Both "ocr_only" (Docling succeeded) and "ocr_raw_words" (the
|
||||
# per-page fallback rescued a page Docling failed on) mean this
|
||||
# page's data came from OCR with no second engine to check it -
|
||||
# checking only "ocr_only" would wrongly treat a statement where
|
||||
# EVERY page needed the fallback as non-OCR-sourced, letting it
|
||||
# reach "Verified" when it shouldn't be able to (see CLAUDE.md's
|
||||
# "Key decisions & lessons" entry on this bug).
|
||||
ocr_only = any(pr.get("status") in ("ocr_only", "ocr_raw_words") for pr in page_reports)
|
||||
|
||||
return checks_service.run_all(
|
||||
transactions, page_reports,
|
||||
|
|
|
|||
Loading…
Reference in New Issue