rag-service/openspec/changes/archive/2026-09-21-ocr-ingest-integration/tasks.md

79 lines
4.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Tasks: OCR Ingest Integration
## Forecast
Estimate: 3,400–4,300 lines.
Decision needed before apply: No
Chained PRs recommended: Yes
Chain strategy: feature-branch-chain
400-line budget risk: High
Tracker feature/ocr-ingest-integration is draft/no-merge and sole main target. PR1 targets tracker; children target predecessors. Coverage: 17 requirements/34 scenarios (O10/P12/V12).
### Units: command; harness; rollback
1 Migration: tsx --test tests/catalog/migration-002.test.ts; N/A schema-only; drop OCR schema
2 Repository: tsx --test tests/catalog/repository-ocr.test.ts; fake pool; revert candidate/leases
3 Extraction: tsx --test tests/parsers/pdf-pages.test.ts; PDF spike; revert parser/fixtures
4 Detection: tsx --test tests/ocr/detection.test.ts; mixed PDF; revert transforms
5 Service: pytest ocr-service/tests -k auth; curl 401/409; remove ocr-service
6 Render: pytest ocr-service/tests -k render; Docker PNG; revert wrapper/image
7 Client: tsx --test tests/ocr/client.test.ts; retry stub; revert client/artifacts
8 Dispatcher: tsx --test tests/ocr/dispatcher.test.ts; curl 202/status; revert routing
9 Review: tsx --test tests/ocr/review.test.ts; curl review/409; revert review/routes
10 Approval: tsx --test tests/ocr/approval.test.ts; playground approval; revert indexing/UI
11 Retention: tsx --test tests/ocr/retention.test.ts; fake-fs sweep; revert retention
12 Config: npm run check; N/A static-only; revert config/docs
13 E2E: npm test; production OCR flow; disable OCR flag
## 1 Persistence (Units 1–2; O2/O3)
- [x] 1.1 RED: duplicate pending, lease recovery, review transitions
- [x] 1.2 GREEN: `migrations/002_ocr_review.sql` schema and unique index
- [x] 1.3 GREEN: `src/modules/catalog/repository.ts` candidates and leases
- [x] 1.4 REFACTOR after green
## 2 Extraction (Units 3–4; P1–P4)
- [x] 2.1 Spike `scripts/spike-pdfjs.ts` for Node 22 parser
- [x] 2.2 RED: PDF-only routing; text files never execute; unsupported build/script formats; pages, blanks, hashes, risks
- [x] 2.3 GREEN: `tests/fixtures/ocr/` and `src/modules/parsers/parser-registry.ts`
- [x] 2.4 GREEN: `src/modules/ocr/detection.ts` thresholds
- [x] 2.5 GREEN: `src/modules/ocr/composition.ts` text, hashes, risks
## 3 OCR Service (Units 5–6; P5/P6)
- [x] 3.1 RED HTTP: bearer 401; idempotency/conflict 409; allowlist; limits 413/422; pressure 429; no-retry; integrity mismatch
- [x] 3.2 GREEN: `ocr-service/` API, queue, allowlist, limits, health
- [x] 3.3 GREEN: PaddleOCR 3.4.0, 200 DPI, schema, stub
- [x] 3.4 GREEN: `ocr-service/Dockerfile` pinned wheels/models/resources
## 4 Orchestration (Units 7–8; O1–O4)
- [x] 4.1 RED HTTP: flag-off 201; OCR 202/status; OCR-down fail-closed; catalog-down 503; retries/integrity
- [x] 4.2 GREEN: `src/modules/ocr/client.ts` retries and integrity
- [x] 4.3 GREEN: `src/modules/ocr/artifacts.ts` originals, manifest, sweep
- [x] 4.4 GREEN: `src/modules/ocr/dispatcher.ts` leases; `src/modules/catalog/reconciler.ts`
- [x] 4.5 GREEN: `src/modules/ingest/service.ts` branch; `src/app.ts` upload/status
## 5 Review (Units 9–10; V1–V4)
- [x] 5.1 RED: auth/premature access; atomic corrections/stale 409; new/reusable activation race; reject/no embeddings
- [x] 5.2 GREEN: `src/modules/ocr/review.ts` view, corrections, conflicts
- [x] 5.3 GREEN: `src/modules/ocr/indexing.ts` CAS; new/reusable activate_requested=true activates, false stays ready
- [x] 5.4 GREEN: rejection and `public/playground/` review UI
## 6 Retention/Deploy (Units 11–12; O5/V5)
- [x] 6.1 RED: TTL/CAS/resume/active protection; flag-off native-only and candidate invisibility
- [x] 6.2 GREEN: `src/modules/ocr/retention.ts`
- [x] 6.3 GREEN: `src/api/openapi.ts` OCR/status/review contracts
- [x] 6.4 GREEN: `src/config/env.ts`, `Dockerfile`; follow `docs/CONTRATO_CICLO_VIDA_Y_OCR.md` (read-only)
## 7 E2E (Unit 13; V6)
- [x] 7.1 E2E: native 201; scanned 202→review→approve→active; mixed
- [x] 7.2 E2E: resend, OCR-down fail-closed, catalog-down 503
- [x] 7.3 Gate: check, build, test, offline pytest
- [ ] 7.4 Production: flag-off verify→enable→FacturaTech 34 entries; CBG04a/FAT07/DSAU08/NSAV06