Repository navigation
perf(alerting): fence a rule's state flush in one statement, run the tick tail together - #1552
Merged
Merged
Maple Review Bot / Maple / review
succeeded
Oct 19, 2026 in 2m 39s
Confidence 9/10 · No issues found
🟢 Confidence 9/10 · safe to merge
Lock order matches the edit path and all three fence outcomes are pinned by tests; only the row-lock wait itself is unexercised locally.
quality 100/100 · no findings · tests covered · risk medium · 2/2 new units observable
Replaces the alerting state flush with one claim-fenced upsertStatesUnderClaim statement and runs the tick's four tail steps together, cutting Postgres round trips. The fence keeps its old outcomes and is pinned by tests; safe to merge.
upsertStatesUnderClaimfences claim and rule withFOR SHAREin one statementflushRuleStatesdrops the five-statementwriteUnderClaimtransaction- The tail runs housekeeping, digests, the sweep and checks ingest together
ALERT_CHECK_INGEST_CONCURRENCYstays 4 beside the tail's Postgres work
Fixed since the last review
- ✅
F1 · Checks ingest at 6 takes the outbound slots the tail's Postgres work needs
Production impact
Production traffic of the changed files (last 7 days)
| File | Calls/day | Busiest operations |
|---|---|---|
packages/backend/src/services/alerts/AlertsService.ts |
1.5k | AlertsService.notifyIncidentDigests 846/day, 0.0% errAlertsService.ingestAlertChecks 655/day, 0.0% err |
What was checked
- Fence matches the edit path's claim-then-rule order (
AlertRulesService.ts:269); no deadlock cycle - Three new tests pin flush-when-held, re-claimed and edited (
AlertsService.test.ts:6511-6529) Orm.sqlbinds values as parameters with explicit casts;msToSqlTimestampis UTC ISO (platform/time.ts:20)
Observability coverage: 2 of 2 changes observable
| Change | Kind | Observable | Evidence |
|---|---|---|---|
| Fenced alert_rule_states upsert, one statement per rule | db query | yes | Runs inside the AlertsService.flushRuleStates span (AlertsService.ts:782) with maple.alerting.state_rows |
| Tick tail: housekeeping, digests, disabled-rule sweep, checks ingest | background steps | yes | Each keeps its own span (AlertsService.flushRuleStateHousekeeping:4577, notifyIncidentDigests:4591, ingestAlertChecks:4650) |
e215cc5 · Updated on every push. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.
Loading