Skip to content

fix: production runtime integrity, concurrency, and adapter selection - #2

Merged
technowizard merged 3 commits into
mainfrom
fix/production-hardening
Aug 1, 2026
Merged

fix: production runtime integrity, concurrency, and adapter selection#2
technowizard merged 3 commits into
mainfrom
fix/production-hardening

Conversation

@technowizard

Copy link
Copy Markdown
Owner

Summary

Post-merge audit found deployment-integrity, concurrency, and adapter-selection defects that made the system unsafe to run in production. This PR fixes all P0–P3 findings.

Changes

P0 — Production runtime integrity

  • Fixed docker-entrypoint.sh to honor `` so the worker container starts the worker, not the API
  • Added CMD to Dockerfile.prod for server default
  • Fixed DOCUMENT_STORAGE_PATHDOCUMENT_STORAGE_ROOT in both Compose files
  • Gated reset_demo_state crontab, reset service, and admin route behind DEMO_MODE=public

P1 — Concurrency and idempotency

  • Made quota checkAndIncrement atomic via INSERT ... ON CONFLICT DO UPDATE ... WHERE
  • Fixed posting PO double-decrement under concurrent delivery via early return
  • Switched IP hashing from createHash to createHmac

P1 — Adapter selection and correctness repairs

  • Added createDocumentStore and createProcessingAdapters factories selecting R2/OpenRouter from env
  • Fixed orphan cleanup query referencing nonexistent column
  • Fixed extraction rejection of text-only PDF pages
  • Shared inspectDocument validation between local and R2 stores

P2 — Defense in depth and CI

  • R2 store now enforces encrypted-PDF, active-content, and max-pages validation (parity with local)
  • CORS uses exact array membership instead of substring matching
  • Added .github/workflows/ci.yml with PostgreSQL service container
  • Extended Finance E2E through posting with ACC- reference assertion

P3 — Context and docs

  • Updated context/architecture.md to reflect shipped MVP status
  • Updated README for Playwright E2E, demo mode, and test command

Domain fix discovered during E2E

confirmAp was expanded to accept returned_for_correction in addition to awaiting_ap_review. The lifecycle transition table already permitted this, and the UI already allowed AP to edit from returned state, but the domain guard was missing.

Verification

  • Server: 232/233 (1 pre-existing failure on main)
  • Web: 46/46
  • E2E: 6/6 (E2E=1 pnpm test:e2e)
  • Typecheck, build, lint, format: green
  • Prod-shaped compose verified: worker starts worker, document survives API restart, processing cycle completes

Follow-ups (outside scope)

  • posting_failed retry returns 409 (needs retryPosting domain function)
  • Pre-existing processing integration test failure on main
  • CI workflow not yet validated in GitHub

…election

- Fix docker-entrypoint.sh to honor command args so worker starts the worker,
  not the API; correct script paths to match tsdown directory-preserving output
- Gate reset_demo_state crontab, reset service, and admin route behind
  DEMO_MODE=public with triple defense-in-depth
- Fix DOCUMENT_STORAGE_PATH -> DOCUMENT_STORAGE_ROOT in both Compose files
- Make quota checkAndIncrement atomic via INSERT ... ON CONFLICT DO UPDATE
  ... WHERE extraction_count < limit RETURNING
- Fix posting PO double-decrement under concurrent delivery via early return
- Switch IP hashing from createHash to createHmac
- Extract shared inspectDocument for local and R2 document validation parity
- Add createDocumentStore and createProcessingAdapters factories selecting
  R2/OpenRouter adapters from environment configuration
- Fix orphan cleanup query referencing nonexistent source_documents column
- Fix extraction rejection of text-only PDF pages
- Re-enable comma-separated CORS origins with exact matching
- Allow AP confirmation from returned_for_correction matching lifecycle table
- Finance approval scenario now covers approve -> AP post -> ACC- reference
- Finance return scenario uses INV-E2E-FIN with AP correction/reconfirmation
- E2E seeder creates AP confirmation for awaiting_finance_approval cases
- Seeder no longer calls production demo-reset endpoint
- Add .github/workflows/ci.yml with PostgreSQL service container for
  typecheck, lint, tests, and build on push and pull request
- Correct stale 'Playwright planned but not installed' to 'runs opt-in with E2E=1'
- Add E2E=1 pnpm test:e2e to Commands section
- Add DEMO_MODE guidance to deployment checklist
@technowizard
technowizard merged commit 0f5fc01 into main Aug 1, 2026
2 checks passed
@technowizard
technowizard deleted the fix/production-hardening branch August 1, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant