claude/zealous-lovelace-cbc97f
safeviewing older commit8f01e3b · incrementalPR #215reviewed 2026-07-07 16:58 UTC0H · 0M · 0L · 1IThe branch
- Purpose
- Add a scheduled nightly reconcile-and-repair backstop for the utility_contract_overview read-model (ADR-020 follow-up). The read-model is trigger-maintained but trigger-bypass paths (replication, bulk load, pg_restore) can leave it drifted; this adds detection, repair, and audit logging.
- Goal
- Implement utility_contract_overview_reconcile() SQL function + pg_cron schedule + TS wrapper + drift watchdog; make drift observable (expect always 0).
- Sub-goals
- SG-1: SQL reconcile function (SECURITY DEFINER, repair via _refresh, pg_notify on drift)
- SG-2: Audit log table (utility_contract_overview_reconcile_runs)
- SG-3: pg_cron nightly schedule (extension-guarded, skip on no pg_cron)
- SG-4: TS wrapper runOverviewReconcile (mechanism-agnostic, EventBridge fallback path)
- SG-5: Integration test (trigger-bypass injection → detect → repair → audit row)
- SG-6: Independent CI drift watchdog GHA workflow
- SG-7: ADR-020 follow-up marked implemented; CLAUDE.md updates
The changes (whole branch)
- What
- This incremental commit (loop-review fix) narrows runOverviewReconcile's parameter from DbOrTx to Database. The matching unit test stub type is updated to Database accordingly.
- Why
- runOverviewReconcile calls a SQL function that creates a TEMP TABLE ON COMMIT DROP and holds pg_advisory_xact_locks — both transaction-scoped. If called inside a caller's existing transaction, the temp table and up to 2000 advisory locks would be held for the outer transaction's entire lifetime, blocking concurrent feeder triggers. Narrowing to Database enforces at the type level that callers must pass a root handle, not a tx.
- Areas
- .github/workflows+124−0domains/utility/src/utility-contract-overview+401−2packages/database/drizzle+215−0packages/database/src/schema+73−0scripts/db+67−0docs/ADRs+6−2
- Blast
- 15 files, +14095/−4 across utility domain, database schema, GHA workflows, and docs. All changes are expand-only (no destructive DB ops). Migration is squawk-clean.
pg_cron not enabled on staging/prod yet — required out-of-band step post-merge per PR description
➖typecheck· CI not reachable via token; assumed passing per PR description➖tests· No CI access; unit + integration test files updated alongside the fix➖coderabbit· No .coderabbit.yaml in repo
Findings · 1
conventions1
info
Exception to DbOrTx-first query convention is justified but undocumented at the convention level
domains/utility/src/utility-contract-overview/utility-contract-overview.queries.ts:592
domain-patterns.md says query first params should be DbOrTx. This is a deliberate, well-commented exception. No action needed in the code; the inline comment covers it. Flagging for awareness only.
History · 8 commits
- df474d4needs attentionincremental2H · 3M · 6L2026-07-22 23:12
- 8b749afneeds attentionincremental0H · 1M · 3L2026-07-14 17:58
- 8f01e3bsafeincremental0H · 0M · 0L2026-07-07 16:58current
- 6fb3b0aneeds attentionincremental0H · 1M · 3L2026-07-06 16:26
- b7dc960needs attentionincremental0H · 1M · 4L2026-07-04 02:25
- c0927dfneeds attentionincremental0H · 2M · 3L2026-07-03 06:34
- 1328ef5needs attentionincremental1H · 4M · 5L2026-07-03 06:26
- 4c3d40dneeds attentionfull6H · 15M · 12L2026-07-03 06:05