Skip to content

feat(alerts): add an opt-in re-notify interval for firing alerts - #3863

Merged
kodiakhq[bot] merged 5 commits into
ClickHouse:mainfrom
bcanvural:feat/alert-renotify-interval
Dec 1, 2026
Merged

kodiakhq[bot] merged 5 commits into
ClickHouse:mainfrom
bcanvural:feat/alert-renotify-interval

Conversation

@bcanvural

@bcanvural bcanvural commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2464. Builds on #2754 by @niladrix719, which has been idle since July and now conflicts with main.

What

An alert can set renotifyIntervalMinutes. While it keeps firing, it notifies at most once every that many minutes. A new breach after a resolve notifies at once, and resolve notifications are unchanged.

It is opt-in: unset keeps today's behaviour of notifying on every evaluation. This is the difference from #2754, which changed the default to "notify once". The setting is in the UI under the alert's advanced schedule settings, in the internal and external APIs, and in clickstack_save_alert. As with the note and the window count, an MCP update that omits it keeps the stored value.

How

Each alert history record stores lastNotifiedAt. A suppressed evaluation copies it forward, so the check only needs the previous evaluation's record, which getPreviousAlertHistories already returns. The check is in trySendNotification, so threshold, grouped and evaluator alerts all go through it, and each group of a grouped alert keeps its own time.

Two things work the same way as today's fired flag and resolve notification:

  • A notification counts as sent once dispatch was attempted, even if the webhook later fails. A failure is reported in the alert's execution errors and is not retried before the interval ends.
  • A catch-up run that covers a resolve and a new breach counts as one incident. No resolve is sent for it either.

Tests

  • checkAlerts.int.test.ts: unset notifies on every evaluation; a 10 minute interval with 5 minute windows notifies, skips, notifies, skips, with lastNotifiedAt carried forward; a new breach after a resolve notifies inside the interval.
  • External API: set, read, clear, and reject 0.

Note

Medium Risk
Changes firing notification cadence in the alert evaluation pipeline (opt-in), which can affect paging noise if misconfigured; resolve paths and default behavior stay the same.

Overview
Alerts gain an opt-in renotifyIntervalMinutes setting end-to-end (shared Zod schema, Mongo model, internal/external OpenAPI, MCP clickstack_save_alert, and alert modals). When set, sustained ALERT state still evaluates every window but webhook repeats are capped to at most once per N minutes; null/unset preserves today’s notify-on-every-evaluation behavior, and resolve notifications are unchanged.

The checker persists lastNotifiedAt on alert history (per group for grouped alerts), copies it from the previous firing row when still in ALERT, and trySendNotification skips dispatch inside the interval (with a skipped_renotify metric). A new breach after OK still notifies immediately, and the UI adds the control under advanced schedule settings with a warning when N is shorter than the evaluation interval.

Reviewed by Cursor Bugbot for commit 481b2ba. Bugbot is set up for automated code reviews on this repo. Configure here.

An alert can set renotifyIntervalMinutes: while it keeps firing, it notifies
at most once every that many minutes. Unset keeps notifying on every
evaluation. Each history record carries lastNotifiedAt forward, so the check
in trySendNotification only reads the previous evaluation.

Closes ClickHouse#2464

Co-authored-by: Niladri Adhikary <niladrix719@gmail.com>
@bcanvural
bcanvural requested a review from a team as a code owner November 30, 2026 13:19
@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

@bcanvural is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 481b2ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Minor
@hyperdx/app Minor
@hyperdx/api Minor
@hyperdx/otel-collector Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

2 finding(s): 🔴 0 P0/P1 · 🟡 1 P2 · 🔵 1 P3

1 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom.

🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/app/src/components/AlertScheduleFields.tsx:882 — New warning text uses raw c="yellow" instead of the semantic Text variant → Repository conventions (Semantic component variants) say to use <Text variant="warning"> for status text and not raw palette colors like c="yellow", which also has poor contrast in light mode. Replace c="yellow" with variant="warning".

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@pulpdrew
pulpdrew self-requested a review November 30, 2026 13:24

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit ba6f7de. Configure here.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a tightly-scoped, well-tested opt-in feature. The prior Cursor Bugbot "silence resets the interval" concern is verifiably fixed (carry-forward runs before the silence early-return, asserted by a dedicated test), the field is wired consistently across common-utils → model → both OpenAPI specs → internal/external routers → MCP, and agent-native parity holds (the MCP tool and external API can set, read, and clear the value with the same semantics and guidance as the UI). The two P2 items below are the same underlying behavior — worth a decision, not a merge blocker.

🟡 P2 -- recommended

  • packages/api/src/tasks/checkAlerts/index.ts:1398 -- history.lastNotifiedAt is advanced before the dispatch try/catch at line 1411, so a webhook delivery that fails (or returns all targets in failures) still starts the re-notify interval and suppresses re-pages for up to N minutes; unlike the unset default, which re-attempts every evaluation, the opt-in path turns a transient delivery outage into an N-minute silence.
    • Fix: Advance lastNotifiedAt only when at least one target was dispatched without throwing, so a fully-failed delivery is retried on the next evaluation rather than throttled.
    • reliability, testing
  • packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts:11511 -- no test exercises a dispatch failure with renotifyIntervalMinutes set; every re-notify test mocks postMessageToWebhook to resolve, so a regression that moved the lastNotifiedAt assignment after successful dispatch (or vice-versa) would silently change paging behavior and stay green.
    • Fix: Add a case that rejects postMessageToWebhook on the first evaluation and asserts the resulting lastNotifiedAt and whether the next in-interval evaluation re-notifies.
🔵 P3 nitpicks (2)
  • packages/api/src/tasks/checkAlerts/index.ts:1368 -- the re-notify logic seeds lastNotifiedAt from previousMap in one if (renotifyMinutes) block, then re-fetches the history and reads/overwrites it in a second block after the silence early-return, so correctness depends on the ordering and on getOrCreateHistory returning the same mutable record both times — an invariant a future refactor could break silently.
    • Fix: Capture const history = getOrCreateHistory(group) once and add a short comment that the seed must run before the silence return so silenced evaluations still persist the carried-forward timestamp.
  • packages/api/openapi.json:39 -- the multi-sentence renotifyIntervalMinutes description is hand-duplicated and already slightly reworded across openapi.json, the external v2 JSDoc, the MCP .describe(), and the UI tooltip, so the four copies will drift as the behavior is clarified.
    • Fix: Source the user-facing copy from a shared constant where each layer permits it, rather than maintaining four hand-written variants.

Reviewers (12): correctness, testing, maintainability, project-standards, agent-native, learnings-researcher, api-contract, reliability, security, adversarial, previous-comments, kieran-typescript.

Testing gaps:

  • No coverage of renotifyIntervalMinutes combined with numConsecutiveWindows > 1 (the PENDING→ALERT transition, and the outage-induced re-PENDING case the author deferred as a follow-up).
  • No coverage of enabling renotifyIntervalMinutes on an already-firing alert (previous ALERT record has no lastNotifiedAt).
  • No coverage of a catch-up/backfill run spanning multiple windows (or a resolve-then-rebreach within one run) with the interval set.
  • No coverage of the re-notify throttle through a non-threshold evaluator path, and no HTTP-boundary test rejecting non-integer/negative values (only 0 is asserted).

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

Ungrouped alerts and stale grouped alerts get their previous state from
getLatestAlertHistories and the last-evaluation fallback, not from
getPreviousAlertHistories, so the re-notify interval never applied to them.
Also tests a grouped alert's per-group interval and the MCP save rules, and
documents the new false return for evaluators.
@bcanvural

Copy link
Copy Markdown
Contributor Author

Round 1, fixed in 29fc30b:

  • claude-review P1: ungrouped alerts and stale grouped alerts now get lastNotifiedAt from getLatestAlertHistories and from the last-evaluation fallback. The two provider tests for those loaders now check it.
  • deep-review P2 (tests): added a grouped case, where each group keeps its own interval, and the MCP keep / replace / clear cases.
  • claude-review P3: the evaluator docs now name the re-notify case.

No change for these:

  • deep-review P2 (failed dispatch): a notification counts once dispatch is attempted, as fired does today. With the queued dispatcher a failure is only known later, so not counting it would mean feeding delivery results back into the history. The failure still shows in the alert's execution errors.
  • P3 (silence): an alert that was silenced notifies when the silence ends. That seems the right default, since nobody was told while it was silenced.
  • P3 (rounding): checks run once per window, so a repeat comes at the first check at or after the interval. An interval shorter than the window means every check.
  • P3 (prop name): kept renotifyIntervalName from feat(alerts): add re-notify interval as option, stop notifying on every evaluation #2754.

@bcanvural

Copy link
Copy Markdown
Contributor Author

@pulpdrew here's the PR we discussed in #2464. It's opt-in: unset keeps today's behaviour.

A silenced evaluation returned before the re-notify check and wrote no
lastNotifiedAt, so a silence shorter than the interval made the alert
notify again as soon as it ended. The time is now carried forward first.
The MCP schema reuses alertRenotifyIntervalMinutesSchema.
state === AlertState.ALERT ? alert.renotifyIntervalMinutes : undefined;
if (renotifyMinutes) {
const previous = previousMap.get(computeHistoryMapKey(alert.id, group));
getOrCreateHistory(group).lastNotifiedAt =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — lastNotifiedAt is lost when a still-breaching evaluation lands in PENDING, so the next ALERT notifies before the interval ends

Carry lastNotifiedAt forward wherever fired is carried for PENDING (the history.fired = previous?.fired === true branches at ~1687, ~1765, ~1825), and accept previous.state === PENDING && previous.fired in the check here. Today trySendNotification only runs for ALERT, and only reads the value back when previous.state === ALERT. With numConsecutiveWindows > 1, an evaluation that comes after a runner delay longer than (M-1) windows finds fewer than M-1 rows in getRecentAlertHistories. That row is written as PENDING without lastNotifiedAt, so the next ALERT evaluation notifies straight away even when, say, a 24h interval has not passed.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one. It needs numConsecutiveWindows > 1 and a runner delay longer than the windows it counts, and the effect is one early repeat after that delay. Covering it means carrying the time through the PENDING branches too, which I'd rather do in a follow-up if wanted.

@bcanvural

Copy link
Copy Markdown
Contributor Author

Rounds 2 and 3. Fixed in c563d7c:

  • deep-review P2 (silence): you're right, and I was wrong in round 1. A silence shorter than the interval brought the next notification forward. The last notification time is now carried forward before the silence check, with a test.
  • claude-review P3: the MCP schema reuses alertRenotifyIntervalMinutesSchema.

No change for these:

  • deep-review P2 (failed dispatch, catch-up run): as in round 1, both work the way fired and the resolve notification already do. Both are in the PR description.
  • claude-review P2 (no accessible label on the re-notify input): a one-line fix. I'll add it with the next change a maintainer asks for, rather than start another bot round for it.
  • P3 (no maximum): a value too large for a date makes the check fall back to notifying on every evaluation, which is today's behaviour.
  • P3 (0 read as unset): every layer rejects 0, and unset is the right reading anyway.
  • P3 (shared projection for the four loaders, useWatch inside AlertScheduleFields, prop name): these follow how fired and numConsecutiveWindows are wired today, and the prop name comes from feat(alerts): add re-notify interval as option, stop notifying on every evaluation #2754. Changing them would widen this PR.
  • claude-review P3 (more tests): skipped.

From here I'll only fix P0/P1 bot findings.

@pulpdrew

Copy link
Copy Markdown
Contributor

@pulpdrew here's the PR we discussed in #2464. It's opt-in: unset keeps today's behaviour.

Thanks! I will take a look this week

control={control}
name={renotifyIntervalName}
render={({ field }) => (
<NumberInput

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we show a warning or error here if the renotifyInterval is less than the alert interval, to make it clear that the alert will not renotify every eg. 1 minute if the alert is only evaluated every 5 minutes?

If the various MCP/API/Tooltip descriptions could indicate this where a warning can't, that would also be good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8fa9bd0. The field now shows a warning when the value is below the alert interval, for example "This alert is evaluated every 5 minutes, so it can't re-notify more often than that." The tooltip, MCP and external API descriptions now say that a value below the alert interval has no effect.

I made it a warning rather than an error because a shorter value is harmless: it behaves the same as leaving the field blank. Happy to make it a validation error if you'd prefer.

@pulpdrew pulpdrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one ask for validation/warning on renotif interval < alert interval

…erval

The alert only notifies when it is evaluated, so a shorter re-notify
interval has no effect. Show a warning under the field and say so in the
tooltip, MCP and external API descriptions.
{renotifyIntervalName &&
renotifyIntervalMinutes != null &&
alertIntervalMinutes != null &&
renotifyIntervalMinutes < alertIntervalMinutes && (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Warning only covers values below the interval; values that aren't a multiple of it are silently rounded up

trySendNotification (packages/api/src/tasks/checkAlerts/index.ts:1390-1398) only runs on window-aligned evaluations. So on a 15m alert, a 20-minute interval actually re-notifies every 30 minutes, with no warning. Either extend the warning to renotifyIntervalMinutes % alertIntervalMinutes !== 0 and state the effective interval (Math.ceil(r / i) * i), or step the NumberInput by the alert interval.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@pulpdrew pulpdrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if (renotifyMinutes) {
const previous = previousMap.get(computeHistoryMapKey(alert.id, group));
getOrCreateHistory(group).lastNotifiedAt =
previous?.state === AlertState.ALERT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — lastNotifiedAt is dropped whenever a firing incident passes through a PENDING row, so the next ALERT notifies inside the interval

The carry-forward only runs when trySendNotification(ALERT) is called and the previous row is ALERT. PENDING rows (index.ts:1685, 1763, 1823) never get lastNotifiedAt. A firing alert can drop to PENDING: with numConsecutiveWindows > 1, getConsecutiveWindowHistories (index.ts:2283) skips ERROR rows, so a single failed query mid-incident leaves too few lookback rows. That gives ALERT → PENDING (fired=true carried) → ALERT, and the new ALERT sees a PENDING previous row, clears lastNotifiedAt, and re-notifies at once. Fix: copy previous.lastNotifiedAt onto PENDING rows when fired is carried forward, and on the ALERT path accept a previous row whose state is ALERT or PENDING with fired === true. Add a checkAlerts test with numConsecutiveWindows + renotifyIntervalMinutes that crosses a PENDING row.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@kodiakhq
kodiakhq Bot merged commit 4d26b57 into ClickHouse:main Dec 1, 2026
26 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alerts re-notify on every evaluation while firing

2 participants