fix(ocr): round-4 review — defensive poll + drop dead tracking columns

Round 4 review (PR #910), no blockers:
- poll(): a 2xx body with no `status` now fails fast (logged) instead of being
  treated as perpetually pending until the deadline; defensive page index
  (`p.get("index", i)`) so a malformed page degrades rather than KeyError-ing.
- Document on poll() that job_id is namespaced (embeds "/") so the gateway route
  must be a path-capture param (GET /v1/ocr/batch/{job_id:path}).
- Drop the vestigial `status` + `updated_at` columns from batch_ocr_jobs: a row
  only ever exists while pending (terminal jobs are deleted) and the live status
  comes from a fresh poll, so a stored mirror was permanently "pending" /
  redundant with submitted_at. Simplifies the migration, store, and dataclass.
- Tests: submit() ValueError on missing job_id; poll() missing-status → failed.

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 11:04:03 +02:00
co-authored by Claude Opus 4.8
parent 55630ba25c
commit 232684e881
5 changed files with 50 additions and 16 deletions
@@ -48,13 +48,12 @@ def upgrade() -> None:
# The gateway's namespaced batch job id ("<provider>/<batch_job_id>") —
# the only handle for polling (the gateway is stateless).
sa.Column("job_id", sa.Text(), nullable=False),
# Gateway-normalised status mirror (pending|succeeded|failed). Kept for
# observability; the live decision always comes from a fresh poll.
sa.Column("status", sa.Text(), nullable=False),
# Unix-epoch seconds. ``submitted_at`` anchors the poll deadline
# (DOCUMENT_OCR_BATCH_MAX_WAIT_SECONDS).
# (DOCUMENT_OCR_BATCH_MAX_WAIT_SECONDS). No status/updated_at column: a row
# only ever exists in the pending state (terminal jobs are deleted), and
# the live status always comes from a fresh poll — a stored mirror would
# be permanently "pending" and carry no information.
sa.Column("submitted_at", sa.BigInteger(), nullable=False),
sa.Column("updated_at", sa.BigInteger(), nullable=False),
sa.PrimaryKeyConstraint(
"user_id", "doc_id", "doc_type", "etag", name="pk_batch_ocr_jobs"
),