Model/docs/adr
Khalim Conn-Kowlessar 48a488d1e9 refactor(orchestration): wire stages onto the UnitOfWork; per-stage commit (#1138)
Replaces the handler's whole-pipeline Session (one transaction across all
three stages, connection pinned during Ingestion's external IO) with a
Unit-of-Work per stage (ADR-0012, added here). Each stage runs its batch in
one unit and commits once; any property raising aborts the batch and the
subtask fails noisily.

- BaselineOrchestrator(unit_of_work, rebaseliner): one unit for the batch,
  commit once. Raise on a pre-SAP10 property leaves the unit uncommitted.
- IngestionOrchestrator(unit_of_work, epc_fetcher, geospatial_repo,
  solar_fetcher): fetch/write split — phase 1 fetches the whole batch (EPC /
  coords / solar) with NO unit open; phase 2 writes in one unit and commits.
  The connection is never held during external IO. Geospatial S3 repo stays
  injected (reference data, not transactional).
- Handler: module-scoped engine (pool reused across warm invocations) + a UoW
  factory; whole-pipeline `with Session` gone. `build_first_run_pipeline`
  composes on the factory. Source clients still behind the raising seam.
- ADR-0012 records the decision (per-stage boundary, all-or-nothing batch,
  idempotent re-run, fetch/write split, module-scoped engine). Modelling stub
  left untouched (no-op, no DB) per the ADR.

Tests: orchestrators on a shared FakeUnitOfWork (assert persisted batch +
exactly-once commit + no-commit-on-raise). New real-DB E2E integration test:
real PostgresUnitOfWork, Ingestion writes the EPC → Baseline reads it back
through the repo → re-run replaces, not duplicates (1 EPC row, 1 baseline row
after two runs). 121 pass in tests/; pyright strict clean; AAA.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 09:54:47 +00:00
..
0001-two-source-paths.md added architechtural decisions, added to prd 2026-05-13 21:26:18 +00:00
0002-property-aggregate-root.md added architechtural decisions, added to prd 2026-05-13 21:26:18 +00:00
0003-strict-ingestion-modelling-separation.md docs(ara): composable stage-orchestrator design (ADR-0011 + ADR-0003 amend + CONTEXT) 2026-05-30 19:26:17 +00:00
0004-baseline-performance-lodged-effective-pair.md feat(baseline): BaselineOrchestrator + BaselinePerformance aggregate (#1135) 2026-05-30 21:21:34 +00:00
0005-multi-phase-scenarios-per-phase-recompute.md scaffolding for ml pipeline 2026-05-16 14:15:56 +00:00
0006-deterministic-kwh-no-baseline-ml.md scaffolding for ml pipeline 2026-05-16 14:15:56 +00:00
0007-kwh-as-ml-target.md scaffolding for ml pipeline 2026-05-16 14:15:56 +00:00
0008-physics-as-feature.md docs: ADR-0008 physics-as-feature + v16.0.0 schema bump 2026-05-17 11:20:40 +00:00
0009-deterministic-sap-calculator.md refactor: move docs/sap-spec/ contents into domain/sap10_calculator/ 2026-05-26 13:17:18 +00:00
0010-sap10-calculator-spec-target-and-validation.md refactor: move docs/sap-spec/ contents into domain/sap10_calculator/ 2026-05-26 13:17:18 +00:00
0011-composable-stage-orchestrators.md docs(ara): composable stage-orchestrator design (ADR-0011 + ADR-0003 amend + CONTEXT) 2026-05-30 19:26:17 +00:00
0012-unit-of-work-per-stage-batch-transaction.md refactor(orchestration): wire stages onto the UnitOfWork; per-stage commit (#1138) 2026-05-31 09:54:47 +00:00