Skip to content

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

Open
bcanvural wants to merge 3 commits into
ClickHouse:mainfrom
bcanvural:feat/alert-renotify-interval
Open

bcanvural wants to merge 3 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 alert notification dispatch and history persistence; incorrect interval logic could miss or duplicate webhooks, though behavior is opt-in and resolve paths are unchanged.

Overview
Adds an opt-in renotifyIntervalMinutes on alerts so sustained firing can throttle repeat webhooks instead of notifying on every evaluation window. Unset/null preserves current behavior; resolve notifications are unchanged.

The field is wired through common-utils validation, the Alert model, OpenAPI/external API, MCP clickstack_save_alert (omit keeps stored value, like note/window count), and UI advanced schedule controls plus AlertPropertiesSummary.

Evaluator behavior: lastNotifiedAt is persisted on alert history; trySendNotification carries it from the previous row, skips sends inside the interval (skipped_renotify), and updates it when a send is attempted. Grouped alerts track the interval per group; silence during firing does not reset the clock.

Provider/history reads now include lastNotifiedAt in aggregated previous history for the check.

Coverage includes checkAlerts integration (interval spacing, post-resolve re-alert, silence, per-group) and external API CRUD/validation (rejects 0).

Reviewed by Cursor Bugbot for commit c563d7c. 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: c563d7c

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.

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

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

Findings outside the changed lines

  • 🟡 P2 packages/app/src/components/AlertScheduleFields.tsx:827 — The re-notify NumberInput has no accessible label → The 'Re-notify every' text is a sibling Text that is not tied to the input, so screen readers announce an unlabeled number field. Pass aria-label="Re-notify interval in minutes", or use the NumberInput label prop.
🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/api/src/tasks/checkAlerts/__tests__/checkAlerts.int.test.ts:457 — Re-notify tests skip the grouped send counts, the evaluator path and the multi-window case → In 'keeps a separate interval for each group', assert how many webhook calls each group gets, not just lastNotifiedAt. A bug that writes the timestamp but still sends every tick (or never sends for group b) would pass today. Also add a case in evaluators.test.ts checking that trySendNotification returns false inside the interval, and a numConsecutiveWindows > 1 case. The PR says evaluator and multi-window alerts use this path, but neither has a test.

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.

The change is cleanly additive and mirrors the existing numConsecutiveWindows field end-to-end across schemas, models, internal/external APIs, OpenAPI, the MCP tool, and the React forms. The prior Cursor "silence resets re-notify interval" finding is resolved: the lastNotifiedAt carry-forward now runs before the silence early-return, and a regression test (keeps the interval across a short silence) guards it. The two items below are reliability refinements on an opt-in path, not merge blockers.

🟡 P2 — recommended

  • packages/api/src/tasks/checkAlerts/index.ts:1398 — A re-notify dispatch commits lastNotifiedAt to the current window before the dispatch try/catch, so a webhook failure at the interval boundary still advances the clock and suppresses every page for the full renotifyIntervalMinutes during a live incident.
    • Fix: Advance history.lastNotifiedAt only after a successful delivery, or leave the carried-forward value unchanged when all targets fail so the next tick retries.
    • reliability
  • packages/api/src/tasks/checkAlerts/index.ts:1370 — In a catch-up/backfill run that replays multiple windows into one ALERT history row, a resolve-then-rebreach within those windows is invisible to the carry-forward (which reads only the prior evaluation's row), so the new incident is throttled against the stale lastNotifiedAt and no page is sent.
    • Fix: Reset the carried-forward lastNotifiedAt when any bucket in the run resolved before the final ALERT, so the re-breach is treated as a fresh incident and notifies immediately.
    • correctness, adversarial
🔵 P3 nitpicks (2)
  • packages/api/src/tasks/checkAlerts/index.ts:1366 — The if (renotifyMinutes) guard on a number | null | undefined value also treats a stored 0 as unset, relying on the schema's min(1) invariant declared elsewhere.
    • Fix: Use if (renotifyMinutes != null) to drive the branch by presence rather than numeric truthiness.
  • packages/app/src/components/AlertScheduleFields.tsx:40 — The new prop is named renotifyIntervalName, dropping the Minutes suffix the adjacent numConsecutiveWindowsName prop keeps, so the field-path and name props no longer follow the sibling convention.
    • Fix: Rename to renotifyIntervalMinutesName to match the existing numConsecutiveWindowsName pattern.

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

Testing gaps:

  • No test for a failed webhook dispatch inside the re-notify interval (the P2 reliability risk is unverified).
  • No test for a catch-up/backfill evaluation containing a resolve between ALERT buckets (the P2 correctness risk is unverified).
  • The unset case asserts notification counts but never asserts lastNotifiedAt stays null on history rows.
  • No end-to-end test of a re-notify firing after a silence that spans the full interval (the carry-forward and the post-silence re-fire are each covered separately, not together).
  • The MCP layer never tests rejection of 0 (the external API does); the internal /alerts response is never asserted to include renotifyIntervalMinutes.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alerts re-notify on every evaluation while firing

2 participants