Skip to content

fix(alerts): v2 rules report last_evaluated_at for healthy rules - #2326

Merged
Makisuo merged 1 commit into
mainfrom
fix/alert-rules-last-evaluated-at
Nov 7, 2026
Merged

Makisuo merged 1 commit into
mainfrom
fix/alert-rules-last-evaluated-at

fix(alerts): last_evaluated_at reflects every evaluation, not only er…

72a6dd9
Select commit
Loading
Failed to load commit list.
Maple Review Bot / Maple / review succeeded Nov 7, 2026 in 1m 17s

Confidence 10/10 · No issues found

🟢 Confidence 10/10 · safe to merge. Aggregation, both callers and the GET route that reads it, plus the new tests, all check out; nothing to fix.
no findings · tests covered · risk medium · 1/1 new units observable

Makes last_evaluated_at the newest evaluation across a rule's state rows instead of only error rows, and gives the PATCH response the same state list and GET already had. A contained read-path fix with tests on both the service and the wire.

  • evaluationStatesByRule takes evaluatedAt from the newest state row and the error from the newest row carrying one
  • loadEvaluationStates replaces the inline list query and filters by ruleId for the edit path
  • upsertRuleRow now loads evaluation state, so the v2 PATCH response reports last_evaluated_at

Production impact

Telemetry this change adds and removes (1)
  • ➕ span name AlertRulesService.loadEvaluationStates · packages/backend/src/services/alerts/AlertRulesService.ts:460
What was checked
  • A successful tick does clear the row's error (last_error = excluded.last_error, AlertsService.ts:847), so keeping the newest error row does not pin stale errors on fresh rows
  • GET /v2/alerts/rules/{id} resolves through listRules (alert-rules.http.ts:480), so retrieve and list cannot disagree
  • The new org_id = ? and rule_id = ? read is served by the alert_rule_states primary key (orgId, ruleId, groupKey); the state map is still filtered by OrgId
Observability coverage: 1 of 1 changes observable
Change Kind Observable Evidence
alert_rule_states read (loadEvaluationStates) db query yes Wrapped in Effect.fn("AlertRulesService.loadEvaluationStates"); dbExecute logs failures with the ambient span name

72a6dd9 · Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.