Skip to content

fix(api): prevent Slack notification failures when alert message exceeds 3000 chars - #3473

Merged
kodiakhq[bot] merged 3 commits into
ClickHouse:mainfrom
Tyagiquamar:fix/3452-slack-block-limit
Dec 2, 2026
Merged

kodiakhq[bot] merged 3 commits into
ClickHouse:mainfrom
Tyagiquamar:fix/3452-slack-block-limit

Conversation

@Tyagiquamar

@Tyagiquamar Tyagiquamar commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3452

Summary of changes

  1. Prevent Slack Webhook Notification Delivery Failures on Long Alert Messages:
    • Slack section blocks enforce a strict 3000-character limit on the text.text field.
    • For inline alerts, buildAlertMessageTemplateHdxLink generates a chart explorer link containing the entire serialized chartConfig in query parameters. On alerts with multiple series or complex queries, this URL exceeds 2500+ characters, causing *<${message.hdxLink} | ${message.title}>*\n${message.body} to surpass Slack's 3000-character limit and fail delivery with WEBHOOK_ERROR.
    • Added formatSlackSectionText and getFallbackHdxLink in packages/api/src/tasks/checkAlerts/transports/slack.ts:
      • If the formatted text exceeds 3000 characters, it falls back to the concise ${origin}/alerts link.
      • If the text still exceeds 3000 characters (e.g. from a very large message body), it safely truncates the body with an ellipsis (...) so total block text never exceeds 3000 characters.
  2. Tests:
    • Added comprehensive unit tests in packages/api/src/tasks/checkAlerts/transports/__tests__/slack.test.ts.

Signed-off-by: Mohd Quamar Tyagi 347892697+Tyagiquamar@users.noreply.github.com


Note

Low Risk
Scoped to Slack transport formatting and inline alert deep links; no auth or data-path changes.

Overview
Slack alert webhooks now cap section block text at 3000 characters via formatSlackSectionText, which truncates the message body with ... while avoiding split emoji pairs and re-closing Markdown code fences when the cut lands inside a block.

Inline alert notification links no longer use the chart explorer URL with a full serialized chartConfig query param. They use buildAlertDetailsLink (/alerts/{alertId} with padded from/to), shortening the link in the Slack header and aligning tests with that URL shape. New unit tests cover truncation and webhook formatting.

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

@changeset-bot

changeset-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ea3846b

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

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

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

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 25, 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.

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

Already reported on an earlier push — no new comments. 1 unchanged from an earlier push (already inline above).


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.

@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches Slack alert notifications sent through webhook channels.

The typed test fixtures and required changeset must be added before merging.

Fix All in Claude CodeFindings

  1. P2 Fallback links lose deployment paths ▶
  2. P2 Long titles break link formatting ▶
  3. P2 Channel fixture bypasses type checks ▶
  4. P2 Required changeset is missing ▶

Summary

Limits Slack section text to 3000 characters.

  • Slack alert messages fit within Slack’s 3,000-character section limit.

The prior reviewed commit is not an ancestor of the current head, so this review used the full PR diff.

Reviews (2) · Last reviewed commit: "fix(api): prevent Slack notification fai..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

Scope: fix(api): prevent Slack notification failures when alert message exceeds 3000 chars — Slack section-block truncation plus a reshaped inline-alert deep link (/chart?config= → /alerts/{id}). 9 files vs base 247b3db9.

Intent (advisory): Stop Slack WEBHOOK_ERROR when the alert section block passes Slack's 3000-char limit, by shortening the inline-alert link and truncating the body (code-fence- and emoji-aware).

🔴 P0/P1 — must fix

  • packages/api/src/tasks/checkAlerts/providers/default.ts:642 — Inline-alert notifications now deep-link to /alerts/{id}, a route AlertDetailPage redirects to /alerts (dropping alertId and the from/to window) whenever IS_ALERT_DETAILS_ENABLED is false, which is the default in production; the prior chart-explorer link worked regardless of that flag, so every inline-alert Slack CTA regresses to a context-less list in default deployments.
    • Fix: Gate link generation on the same flag and fall back to the flag-independent /chart?alertId= deep link when alert details are disabled, or land this only after the alert-details page is enabled by default.
    • adversarial, previous-comments, reliability

🟡 P2 — recommended

  • packages/api/src/tasks/checkAlerts/transports/slack.ts:49 — formatSlackSectionText subtracts only the header length from the body budget and never truncates the header itself, so a long user-controlled title (rendered from alert.name, uncapped) yields header + '...' exceeding 3000 and reintroduces the exact Slack rejection the PR targets.
    • Fix: Bound the title/header too and hard-cap the final composed string to MAX_SLACK_SECTION_LENGTH as a backstop, appending the ellipsis only when it fits the remaining budget.
    • correctness, adversarial, reliability, testing, kieran-typescript, maintainability
🔵 P3 nitpicks (3)
  • packages/api/src/tasks/checkAlerts/transports/slack.ts:34 — The surrogate guard only trims a lone trailing high surrogate, so a cut inside a ZWJ/flag/combining-mark grapheme cluster still leaves a broken glyph or dangling U+200D (cosmetic only).
    • Fix: Segment with Intl.Segmenter('grapheme') (or trim a trailing ZWJ/combining mark) before slicing if truncated-glyph fidelity matters.
    • correctness, testing, kieran-typescript, maintainability
  • packages/api/src/tasks/checkAlerts/transports/slack.ts:31 — truncateBody always reserves closing-fence room even when the body has no open code fence, truncating plain-text bodies ~4 chars earlier than the limit requires.
    • Fix: Compute the open-fence state first and reserve the closing-fence length only when the cut actually lands inside a fence.
    • maintainability, correctness
  • packages/api/src/tasks/checkAlerts/transports/__tests__/slack.test.ts:44 — The test hardcodes the reserved-length magic number 7 (3000 - header.length - 7), which will silently drift if ELLIPSIS/CLOSING_FENCE change.
    • Fix: Export the length constants and derive the reserved length from them in the test.

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

Resolved from prior review rounds: changeset .changeset/slack-block-limit.md present and valid (@hyperdx/api patch); test fixtures now typed via fromPartial<WebhookChannel>/Message (no any); the old getFallbackHdxLink/url.origin path-prefix concern is moot (function removed); header is prepended whole so link markup >* is never cut; no stale buildChartExplorerLink references and AlertChartConfig is still used in providers/index.ts.

Testing gaps:

  • No test for the header/title-alone exceeding 3000 chars (the P2 path); all cases use a short title.
  • No test asserts the /alerts/{id} link is reachable when IS_ALERT_DETAILS_ENABLED is off (production default) — the redirect regression is unverified.
  • handleSendSlackWebhook only exercises a short body; the end-to-end truncation/fence-reclose path is not asserted through the public handler.
  • New alert.id == null throw branch in template.ts and multi-codepoint/ZWJ emoji cuts are untested.

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

@Tyagiquamar
Tyagiquamar force-pushed the fix/3452-slack-block-limit branch from c18a0e9 to edd160a Compare October 25, 2026 14:17
@wrn14897

wrn14897 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@Tyagiquamar ping me if the PR is ready for another look

@Tyagiquamar
Tyagiquamar requested a review from a team as a code owner November 5, 2026 09:27
@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

@wrn14897 All tests and automated reviews are passing green, and I have added the changeset for @hyperdx/api in 2455498. The PR is ready for another look whenever convenient.

@brandon-pereira
brandon-pereira removed their request for review November 6, 2026 15:02
@pulpdrew
pulpdrew requested a review from a team as a code owner December 1, 2026 18:23

@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.

Stale Bugbot comment from a previous run.

@pulpdrew

pulpdrew commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Updated:

@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 146d114. Configure here.

@pulpdrew
pulpdrew force-pushed the fix/3452-slack-block-limit branch from 146d114 to fe04689 Compare December 1, 2026 19:36

@wrn14897 wrn14897 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

Tyagiquamar and others added 3 commits December 2, 2026 11:55
…eds 3000 chars

Fixes ClickHouse#3452

Slack section blocks enforce a strict 3000-character limit on the text field. Inline alert links encode large chartConfig objects in query params, causing the message block text to exceed 3000 chars and fail delivery with WEBHOOK_ERROR.

Format Slack section text using formatSlackSectionText, which falls back to the shorter /alerts link if the link causes an overflow, and truncates the body safely if necessary.

Signed-off-by: Mohd Quamar Tyagi <347892697+Tyagiquamar@users.noreply.github.com>
Signed-off-by: Mohd Quamar Tyagi <104281681+Tyagiquamar@users.noreply.github.com>
@wrn14897
wrn14897 force-pushed the fix/3452-slack-block-limit branch from 48681ae to ea3846b Compare December 2, 2026 03:55
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Dec 2, 2026 4:00am UTC
hyperdx-storybook Ready Ready Preview Dec 2, 2026 4:00am UTC

Request Review

@kodiakhq
kodiakhq Bot merged commit 1d17024 into ClickHouse:main Dec 2, 2026
30 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — ea3846b5 Deployed Dec 2, 2026 by vercel[bot]
Preview – hyperdx-storybook — ea3846b5 Deployed Dec 2, 2026 by vercel[bot]
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.

Slack notifications for inline alerts fail when the chart-explorer link passes Slack's 3000-character block limit

3 participants