mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 04:32:42 +00:00
Extracting lab values from a stored document still sent the whole text in one call. A multi-page report produced more JSON than one call's output ceiling, the answer was cut mid-fact, the parse failed twice, and the read came back as 422 "Couldn't read the document. Try a clearer copy." The lab scan had already learned to read the same report a page or a part at a time, but each surface carried its own copy of the read, so the document path never got it. It also ran under the shared 60 s timeout, dropped every fact past 120 (or every fact when one did not match the schema), and charged a flat reservation. The read now lives once, in lib/documents/ocr-read.ts and ocr-plan.ts: the per-read limits, the corrective retry, the salvage of a cut answer's complete rows, the wire re-check and budget reservation before each read, and the planning of a PDF a page at a time and text in parts at line boundaries. The lab scan and the document extraction (the extract route, its background run and the lab auto-staging) both read through it, and the background run plans its reads on the same deadline as a lab scan. The per-read budget moves to a shared metered budget. The document path validates the answer fact by fact, keeps the lab scan's row cap (400), and says why nothing came back: 422 documents.inbound.outputLimit when the reads stopped at the output limit, 429 when the budget refused them, extractFailed only for answers that were not the schema. A run whose reads were cut or not reached reports `incomplete` on its result. A guard holds the class: the output ceiling is set only in the core, both surfaces read through runOcrReads, both runs share the deadline, and a lab read and a document read go out under the same limits. Refs #1257
3.3 MiB
3.3 MiB