fix/job-active
needs attentionviewing older commitce2dc3e · incrementalPR #314reviewed 2026-07-16 00:44 UTC0H · 1M · 1L · 2I- Purpose
- Enforce optimistic concurrency control at the database layer for utility-contract writes and ensure post-write failures force a real ROLLBACK.
- Goal
- After this branch: updateWithVersion enforces version predicate; ensureContractFromBillsShell throws to roll back on post-write failures; ContractVersionConflictError surfaces on OCC; integration test pins atomicity.
- Sub-goals
- SG-1: Active-first RPU resolution + evidence-driven reactivation
- SG-2: Guard demotion write + close review-round-1 test gaps
- SG-3: Enforce OCC in updateWithVersion WHERE + rollback-on-abort
- What
- updateWithVersion gains version predicate in WHERE clause; EnsureContractAbort pattern converts return-err-after-write to throw-to-rollback in ensureContractFromBillsShell; statusWriteError diagnoses null as version conflict vs row-gone; ContractVersionConflictError added to EnsureContractFromBillsError.
- Why
- Without OCC, concurrent writers silently overwrote each other. Without throw-to-rollback, returning err after a partial write committed partial state (two-active-contracts corruption).
- Areas
- domains/utility/src/utility-contract+418−17domains/cross-domain/src/__tests__+301−2apps/platform/src/api/handlers+19−5docs/development+205−0services/utility/bills/cfe/src/handlers+3−1
- Blast
- 19 files, +1261/−38 across the branch. Core: utility-contract shells (+175/−7), tests (+550/−7). No schema migrations.
Findings · 4
correctness1
updateContractShell maps OCC null to databaseError — handler's 409 branch is dead code
domains/utility/src/utility-contract/utility-contract.shells.ts:229
Since this commit, updateWithVersion enforces version = currentVersion in the WHERE clause. A concurrent write between the shell's fetch and update returns null. updateContractShell maps null to ContractErrors.databaseError('update') (500), but the mapper and handler both expect ContractVersionConflict (409). Fix: after null, call findById(tx, id) — if row exists emit versionConflict, else databaseError.
conventions1
preResolvedCtx inline type in runEnsureContractFromBills is verbose
domains/utility/src/utility-contract/utility-contract.shells.ts:643
Long inline object type for preResolvedCtx parameter. Minor readability concern; no correctness impact.
tests1
No OCC rollback test for the TerminateAndReplace path
domains/utility/src/utility-contract/__tests__/ensure-contract-evidence.integration.test.ts:432
ReactivateContract + demotion OCC is tested. TerminateAndReplace steps 3a and 3b both now use throw new EnsureContractAbort but have no rollback test.
improvement1
tariffCode1 fix is a real bug fix — prior uniq('TAR') would produce UnknownTariff
domains/cross-domain/src/__tests__/cfe-job-intent.integration.test.ts:1038
uniq('TAR') generated a random code not in the tariff table, making commitCfeJobIntentShell fail with UnknownTariff instead of exercising the swap logic.
History · 6 commits
- 3e1361aneeds attentionincremental0H · 1M · 0L2026-07-16 01:14
- c7b4e31needs attentionincremental0H · 1M · 5L2026-07-16 01:03
- 2099ea7needs attentionincremental0H · 3M · 5L2026-07-16 00:53
- ce2dc3eneeds attentionincremental0H · 1M · 1L2026-07-16 00:44current
- df0ef09needs attentionincremental0H · 2M · 3L2026-07-16 00:23
- d4a8d84needs attentionfull0H · 3M · 5L2026-07-16 00:04