Skip to content

feat: implement durable hybrid OCR execution path #46

Description

@Sam123ben

Objective

Deliver the production-grade, reusable OCR execution path behind the existing provider-neutral API: authoritative immutable source binding, digital-PDF text extraction, bounded Rust preprocessing/local inference, confidence-based managed OCR fallback, normalized evidence output, deterministic validation, and durable Temporal orchestration.

Architecture decisions

  • Rust/Axum remains the public API and job-control boundary.
  • CNPG is authoritative for identity, workflow checkpoints, idempotency, outbox and audit metadata; GCS retains immutable documents/page artifacts/results; Valkey is a tenant-scoped non-authoritative cache/admission layer; Qdrant contains rebuildable derived memory only.
  • Before image OCR, the parser extracts embedded text from eligible digital PDFs with source coordinates and provenance. Pages requiring raster OCR follow bounded decode, quality assessment, orientation/geometry correction and local signed-model inference.
  • A managed Document AI provider is a policy-controlled fallback for low-confidence, handwriting, unsupported-script or complex-layout pages only. It is never invoked with caller-controlled provider URLs/credentials and is subject to residency, health, cost and tenant policy.
  • A dedicated Temporal namespace named document-intelligence-<environment> is mandatory. Workflow histories and inputs remain identifiers-only; source bytes, OCR text, signed URLs and secrets never enter Temporal.
  • Model runtime stays provider/model-neutral and Rust-native. No third-party OCR source/runtime is copied or named in repository artifacts. Model artifacts must be legally approved, signed, digest-pinned and benchmark-promoted before use.

Delivery slices

  • Persist/load immutable accepted source locator scoped to product, tenant and job; prove cross-tenant/object substitution fails closed.
  • Add bounded source-page rendering/extraction adapter and page-source contract; preserve original page geometry.
  • Implement concrete signed-model detector/recognizer runtime, bounded CPU/GPU pools and output contract validation after artifact approval.
  • Add confidence/calibration routing and managed fallback with circuit breaker, per-tenant quota and cost telemetry.
  • Wire checkpointed pages into Temporal activities/finalization; qualify cancellation, retries, 300-page partial recovery, replay/versioning and namespace isolation.
  • Add sandbox synthetic/adversarial fixtures, golden-dataset benchmarks, DevAI trace/evaluation gates and redaction assertions.
  • Add reviewed GitOps sandbox workload and Kargo promotion gate only after the preceding runtime/evaluation evidence passes.

Acceptance evidence

A disposable sandbox document must complete upload inspection, immutable promotion, parser/text extraction or rasterization, recognition/fallback, evidence/result artifact, validation and redacted trace. Required adversarial coverage: cross-tenant source substitution, stale object generation, decompression/pixel limits, invalid model output, malformed provider response and prompt-injection text. Promotion requires agreed CER/WER, critical-field, latency, memory, cost and safety thresholds.

Explicit non-goals

This issue does not select model weights, create/rotate secrets, alter production Temporal namespaces, or authorize a production rollout. Those actions remain separately reviewed and gated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions