fix(ocr): round-3 review — guard unexpected batch status + tests/comments

Round 3 review (PR #910):
- Guard an unexpected terminal batch status in _process_batch: anything that
  isn't succeeded/failed (gateway version skew, a new lifecycle state) now marks
  the document parse-failed instead of falling through to _pages_to_text([]) — a
  0-chunk "success" that silently indexed empty text and re-submitted forever.
  Test added.
- gateway_batch_client.submit: raise an actionable ValueError on a 2xx response
  with no job_id (was a bare KeyError deep in the caller).
- Document that a _process_batch transport error intentionally propagates to
  procrastinate for retry rather than falling back to sync (opt-in batch wants
  the retry).
- Annotate _batch_client as GatewayBatchOcrClient | None (TYPE_CHECKING import
  already present); clarify the delete_stale_for_doc first-submit no-op comment.
- Add a parametrized build_gateway_batch_client test (the gateway-only invariant:
  mistral/none/no-URL -> None; gateway|auto + URL -> client).

1653 unit tests pass; ruff + ty green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-15 10:53:24 +02:00
co-authored by Claude Opus 4.8
parent 995e810d89
commit 55630ba25c
3 changed files with 69 additions and 3 deletions
@@ -120,7 +120,11 @@ class GatewayBatchOcrClient:
)
resp.raise_for_status()
body = resp.json()
job_id = body["job_id"]
job_id = body.get("job_id")
if not job_id:
# Contract violation (2xx without a job id) — fail with an actionable
# message rather than a bare KeyError deep in the caller.
raise ValueError(f"gateway batch submit returned no job_id: {body!r}")
logger.info(
"batch OCR submitted: job_id=%s custom_id=%s status=%s",
job_id,