fix: OCR escalation falls back to tier-1 result when OCR can't run
OCR is an enhancement, not a gate. Previously, escalating a scanned doc to the OCR tier returned the OCR result unconditionally -- so with DOCUMENT_OCR_ENABLED =true but no backend configured (no gateway URL / no MISTRAL_API_KEY) the OCR processor returned success=False and the whole document was marked failed and skipped: strictly worse than leaving OCR off (where it would at least index the tier-1 text). Now the registry keeps the tier-1 fast result when the OCR escalation doesn't succeed (no backend, API down, empty output), logging a warning. A misconfiguration degrades gracefully instead of dropping scanned docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
3bd1b46d9c
commit
4dbf362261
@@ -117,6 +117,20 @@ async def test_ocr_escalation_on_empty_text(monkeypatch):
|
||||
esc.assert_called_once()
|
||||
|
||||
|
||||
async def test_ocr_failure_falls_back_to_fast(monkeypatch):
|
||||
# OCR enabled but the backend can't run (no creds / API down) -> keep the
|
||||
# tier-1 result instead of failing the document.
|
||||
monkeypatch.setattr(reg_mod, "get_settings", lambda: _Settings(ocr=True))
|
||||
monkeypatch.setattr(reg_mod, "record_document_escalation", MagicMock())
|
||||
r = _registry(
|
||||
(_Fake("fast", "fast", text=""), 20),
|
||||
(_Fake("ocr", "ocr", text="", success=False), 5),
|
||||
)
|
||||
res = await r.process(b"%PDF-1.7", "application/pdf")
|
||||
assert res.processor == "fast"
|
||||
assert res.success is True
|
||||
|
||||
|
||||
async def test_no_ocr_escalation_when_disabled(monkeypatch):
|
||||
monkeypatch.setattr(reg_mod, "get_settings", lambda: _Settings(ocr=False))
|
||||
r = _registry(
|
||||
|
||||
Reference in New Issue
Block a user