Skip to content

fix(alerts): bound the size of chat notifications while they are rendered - #36258

Closed
manerow wants to merge 1 commit into
mainfrom
fix/alerts-render-budget
Closed

manerow wants to merge 1 commit into
mainfrom
fix/alerts-render-budget

Conversation

@manerow

@manerow manerow commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

Slack, Microsoft Teams and Google Chat alerts turn the notification's HTML into Markdown and then parse that Markdown. Neither step had a size limit:

  • Tables. Every table row is padded to the widest row. A table with one wide row and many short ones therefore becomes rows x columns cells, which can be far larger than the HTML it came from.
  • Code blocks. The fence around a code block was chosen without checking the code itself, so code containing ~~~~ could end the block early. Whatever followed was then read as Markdown, including tables.
  • Deep nesting. Every nesting level (for example a quote inside a quote) repeats a prefix on every line below it, so depth multiplies the output.
  • Links. A link target containing a space, a parenthesis or a newline broke out of the link.

The only limit, 50,000 characters, was checked after the conversion had already been done in memory.

What this changes

Everything stays in the renderer (alerting/content/render), with the numbers in one place, RenderLimits:

  • HTML longer than 200,000 characters is refused, and elements nested deeper than 48 levels are flattened into their parent.
  • A table's full size is computed before it is written, together with what was written before it, and refused past 50,000 characters.
  • Before parsing, Markdown is refused if its tables could hold more than 50,000 cells. A table never crosses a blank line, so each block of lines holds at most its line count times its widest line's cell count.
  • A code fence is now a run of backticks longer than any run inside the code, which is the CommonMark rule. The code's language name may only use letters, digits, _, + and -.
  • Spaces, control characters and parentheses in a link target are percent-encoded.

When a budget is exceeded, rendering throws RenderBudgetExceededException (an IllegalArgumentException). The event is recorded as failed with that reason, and the alert moves on to the next event. That is what already happens today for Markdown over 50,000 characters. Every other conversion error behaves as before.

What users see

Nothing, for normal notifications. Slack, Teams and Google Chat all reject messages far smaller than these limits, so nothing that could have been delivered is refused. A notification over the budget shows up in the alert's failed events with a reason that names the budget.

Tests

  • RenderBudgetTest (unit): 12 cases. 9 failed on main before this change (for example, 500 nested quotes rendered 8,007,000 characters). The others check that an ordinary 20 x 10 table, normal pipe characters and non-ASCII link targets render exactly as before.
  • ChatRenderBudgetIT (integration): a Slack alert receives an oversized table, records one failed event naming the budget, and still delivers the next event.
  • Unchanged and passing: all 426 alerting unit tests, and AlertTickOutcomesIT, DispatchScenariosIT, AlertDeliveryIT, NotificationTemplateResourceIT and TemplateTestSendIT on MySQL.

A backport to 2.0 follows in a separate PR, with the same code in notifications/channels.

RetriggerView in GreptileConfidence Score: 4/5

Fix the table estimate before merging so small notifications containing fenced code are not dropped.

Findings

  1. P1 Small code notifications fail ▶

Summary

Adds limits while chat notifications are converted and parsed.

  • Chat alerts stop rendering when their content exceeds a fixed budget.
  • Code and link contents stay inside their Markdown boundaries.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  H[Notification HTML] --> B[Check HTML size and limit depth]
  B --> C[Convert to Markdown]
  C --> T[Check Markdown length and estimated cells]
  T -->|Within budget| P[Parse and render chat message]
  B -->|Over budget| F[Record event delivery failure]
  C -->|Table over budget| F
  T -->|Over budget| F
  F --> N[Continue with next event]
Loading

Reviews (1) · Last reviewed commit: "fix(alerts): bound the size of chat noti..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner October 26, 2026 13:56
@manerow
manerow requested a review from mohityadav766 October 26, 2026 13:56
@manerow manerow added safe to test Add this label to run secure Github workflows on PRs backend labels Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

Comment on lines +83 to +89
void aLinkTargetKeepsItsNonAsciiCharacters() {
String html = "<a href=\"https://example.com/café x\">text</a>";

String markdown = ADAPTER.adapt(html).strip();

assertEquals("[text](https://example.com/café x)", markdown);
}

@gitar-bot gitar-bot Bot Oct 26, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Bug: Non-ASCII link test expects a raw space the encoder now escapes

encodeLinkTarget percent-encodes every c <= ' ', so href="https://example.com/café x" is rendered as [text](https://example.com/café%20x). aLinkTargetKeepsItsNonAsciiCharacters asserts [text](https://example.com/café x) with a literal space, so the test fails every run. It also contradicts aLinkTargetCannotStartANewLine, which expects a%20b. Fix the expected value so the test checks what it means to check: non-ASCII characters are left alone while the space is encoded.

Expect the space to be encoded and the 'é' to be kept:

assertEquals("[text](https://example.com/café%20x)", markdown);

Was this helpful? React with 👍 / 👎

Comment on lines +6 to +9
public static final int MAX_MARKDOWN_CHARS = 50_000;
public static final long MAX_TABLE_CELLS = 50_000L;
public static final int MAX_HTML_CHARS = 200_000;
public static final int MAX_HTML_DEPTH = 48;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Quality: New render budgets and fail-and-continue rule are not recorded

This PR adds new limits that were judgment calls, and docs/decisions/ has no record covering them. Nothing in the record set mentions alert rendering budgets. Per the repository's decision-record policy, the record would state: "Chat notification rendering refuses HTML longer than 200,000 characters, flattens elements nested deeper than 48 levels, refuses tables whose padded size or whose parsed Markdown cells exceed 50,000, and a refused notification throws RenderBudgetExceededException, so the event is recorded as failed and the alert moves on to the next event." The source is the description: "HTML longer than 200,000 characters is refused and elements nested deeper than 48 levels are flattened", "refused before parsing if its tables could hold more than 50,000 cells", and "the event is recorded as failed and the alert moves on to the next event". The repo squash-merges, so the rationale ("limits are above what Slack, Teams and Google Chat accept") would otherwise be lost. Add one record under docs/decisions/ and cite it from RenderLimits as ADR:<date>-<slug>.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 0 closed / 2 findings

🟡 Medium risk · Bounding chat-alert rendering could mark unusually large but otherwise valid notifications as failed, preventing their delivery.

Adds size budgets to chat notification rendering for Slack, Teams and Google Chat: HTML over 200,000 characters is refused, nesting deeper than 48 levels is flattened, and tables are capped at 50,000 cells, with overruns recorded as failed events. Changes requested before merge. The non-ASCII link test expects a raw space that the new encoder percent-encodes, so it will fail on every run and its expected value needs correcting. The new render limits and fail-and-continue behavior also need a decision record under docs/decisions/, cited from RenderLimits.

⚠️ Bug: Non-ASCII link test expects a raw space the encoder now escapes

📄 openmetadata-service/src/test/java/org/openmetadata/service/alerting/content/render/RenderBudgetTest.java:83-89 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/HtmlToMarkdownAdapter.java:226-233

encodeLinkTarget percent-encodes every c <= ' ', so href="https://example.com/café x" is rendered as [text](https://example.com/café%20x). aLinkTargetKeepsItsNonAsciiCharacters asserts [text](https://example.com/café x) with a literal space, so the test fails every run. It also contradicts aLinkTargetCannotStartANewLine, which expects a%20b. Fix the expected value so the test checks what it means to check: non-ASCII characters are left alone while the space is encoded.

Expect the space to be encoded and the 'é' to be kept
assertEquals("[text](https://example.com/café%20x)", markdown);
⚠️ Quality: New render budgets and fail-and-continue rule are not recorded

📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/RenderLimits.java:6-9 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/RenderBudgetExceededException.java:3-4 📄 openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/HtmlToMarkdownAdapter.java:49-50

This PR adds new limits that were judgment calls, and docs/decisions/ has no record covering them. Nothing in the record set mentions alert rendering budgets. Per the repository's decision-record policy, the record would state: "Chat notification rendering refuses HTML longer than 200,000 characters, flattens elements nested deeper than 48 levels, refuses tables whose padded size or whose parsed Markdown cells exceed 50,000, and a refused notification throws RenderBudgetExceededException, so the event is recorded as failed and the alert moves on to the next event." The source is the description: "HTML longer than 200,000 characters is refused and elements nested deeper than 48 levels are flattened", "refused before parsing if its tables could hold more than 50,000 cells", and "the event is recorded as failed and the alert moves on to the next event". The repo squash-merges, so the rationale ("limits are above what Slack, Teams and Google Chat accept") would otherwise be lost. Add one record under docs/decisions/ and cite it from RenderLimits as ADR:<date>-<slug>.

🤖 Prompt for agents
Code Review: Adds size budgets to chat notification rendering for Slack, Teams and Google Chat: HTML over 200,000 characters is refused, nesting deeper than 48 levels is flattened, and tables are capped at 50,000 cells, with overruns recorded as failed events. Changes requested before merge. The non-ASCII link test expects a raw space that the new encoder percent-encodes, so it will fail on every run and its expected value needs correcting. The new render limits and fail-and-continue behavior also need a decision record under `docs/decisions/`, cited from `RenderLimits`.

1. ⚠️ Bug: Non-ASCII link test expects a raw space the encoder now escapes
   Files: openmetadata-service/src/test/java/org/openmetadata/service/alerting/content/render/RenderBudgetTest.java:83-89, openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/HtmlToMarkdownAdapter.java:226-233

   `encodeLinkTarget` percent-encodes every `c <= ' '`, so `href="https://example.com/café x"` is rendered as `[text](https://example.com/café%20x)`. `aLinkTargetKeepsItsNonAsciiCharacters` asserts `[text](https://example.com/café x)` with a literal space, so the test fails every run. It also contradicts `aLinkTargetCannotStartANewLine`, which expects `a%20b`. Fix the expected value so the test checks what it means to check: non-ASCII characters are left alone while the space is encoded.

   Fix (Expect the space to be encoded and the 'é' to be kept):
   assertEquals("[text](https://example.com/café%20x)", markdown);

2. ⚠️ Quality: New render budgets and fail-and-continue rule are not recorded
   Files: openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/RenderLimits.java:6-9, openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/RenderBudgetExceededException.java:3-4, openmetadata-service/src/main/java/org/openmetadata/service/alerting/content/render/HtmlToMarkdownAdapter.java:49-50

   This PR adds new limits that were judgment calls, and `docs/decisions/` has no record covering them. Nothing in the record set mentions alert rendering budgets. Per the repository's decision-record policy, the record would state: "Chat notification rendering refuses HTML longer than 200,000 characters, flattens elements nested deeper than 48 levels, refuses tables whose padded size or whose parsed Markdown cells exceed 50,000, and a refused notification throws `RenderBudgetExceededException`, so the event is recorded as failed and the alert moves on to the next event." The source is the description: "HTML longer than 200,000 characters is refused and elements nested deeper than 48 levels are flattened", "refused before parsing if its tables could hold more than 50,000 cells", and "the event is recorded as failed and the alert moves on to the next event". The repo squash-merges, so the rationale ("limits are above what Slack, Teams and Google Chat accept") would otherwise be lost. Add one record under `docs/decisions/` and cite it from `RenderLimits` as `ADR:<date>-<slug>`.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

Comment on lines +48 to +55
for (String line : markdown.lines().toList()) {
boolean blank = line.isBlank();
cells += blank ? linesInRun * widestRow : 0;
linesInRun = blank ? 0 : linesInRun + 1;
widestRow = blank ? 0 : Math.max(widestRow, pipesIn(line) + 1L);
}
cells += linesInRun * widestRow;
if (cells > RenderLimits.MAX_TABLE_CELLS) {

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.

P1 Small code notifications fail

requireTableCellsWithinBudget counts pipes inside fenced code as table columns. A fenced block containing one line of 250 pipes followed by 200 lines of x is under 700 characters, but its estimate exceeds 50,000 cells. The adapter preserves this code, so the chat notification now throws and is not sent, even though it contains no table.

Exclude fenced code from the estimate and add a regression test for this case.

@manerow

manerow commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Folded into PR #36279, which now carries all the alerting bounds in one change.

@manerow manerow closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant