Skip to content

fix(app): show webhook body template compile errors in the editor - #3350

Merged
kodiakhq[bot] merged 3 commits into
mainfrom
brandon/brandon-json-parsing-issue
Oct 14, 2026
Merged

kodiakhq[bot] merged 3 commits into
mainfrom
brandon/brandon-json-parsing-issue

Conversation

@brandon-pereira

@brandon-pereira brandon-pereira commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

The webhook form now compiles the body template as you edit it and shows the Handlebars error under the editor, with its line and column. A template that doesn't compile used to save without any feedback, and the problem only surfaced when an alert failed to deliver (visible in server logs).

The common case is JSON-escaping quotes inside a Handlebars expression:

"status": "{{#if (eq state \"ALERT\")}}firing{{else}}resolved{{/if}}"

That's valid JSON but not a valid template. The form now shows Template error on line 1, column 29 with Handlebars' parse message. The intended template, {{#if (eq state "ALERT")}}, is invalid JSON as written but compiles, so it shows no error.

  • The check runs 300 ms after typing stops, so the error doesn't flash while a {{ … }} is half-typed. Empty bodies are skipped, since they fall back to the service's default template. Slack bodies are skipped too; Slack never renders the body.
  • getWebhookTemplateError in common-utils uses Handlebars.precompile. Delivery's extra eq helper only matters at render time, so stock Handlebars reports the same compile errors delivery would hit.
  • The docs example in alert-webhook-template-variables.md used the escaped-quote pattern itself and would not have compiled; it's fixed, and the page now explains how to quote strings inside {{ … }}.

Screenshots or video

Before After
Screenshot 2026-10-09 at 3 32 34 PM Screenshot 2026-10-09 at 3 32 02 PM

How to test on Vercel preview

Preview routes: /team

Steps:

  1. Click the button with data-testid="add-webhook-section-button" to open the webhook form.
  2. Select the "incident.io" service type.
  3. In the body editor, enter {"status": "{{#if (eq state \"ALERT\")}}firing{{/if}}"} and wait a moment.
  4. Verify an error titled "Template error on line 1, column 29" appears under the editor.
  5. Replace the body with {"status": "{{#if (eq state "ALERT")}}firing{{/if}}"} and verify the error disappears.

References

Compile the webhook body template as the user edits it (debounced) and show
the Handlebars error, with its line and column, under the editor. A broken
template, e.g. JSON-escaped quotes inside a helper call, previously gave no
feedback until an alert failed to deliver.
@vercel

vercel Bot commented Oct 9, 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 Oct 14, 2026 10:17pm UTC
hyperdx-storybook Ready Ready Preview Oct 14, 2026 10:17pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d15a797

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 Patch
@hyperdx/app Patch
@hyperdx/api 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

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 124 in total (1.71%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge as an editor-feedback change.

Summary

The webhook editor now shows template compile errors after a 300 ms pause, including their line and column.

  • Webhook editors show where a body template fails to compile.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into brandon/brandon..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 416 passed • 1 skipped • 1160s

Status Count
✅ Passed 416
❌ Failed 0
⚠️ Flaky 1
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🟡 Tier 3 — Standard

Introduces new logic, modifies core functionality, or touches areas with non-trivial risk.

Why this tier:

  • Cross-layer change: touches frontend (packages/app) + shared utils (packages/common-utils)

Review process: Full human review — logic, architecture, edge cases.
SLA: First-pass feedback within 1 business day.

Stats
  • Production files changed: 3
  • Production lines changed: 107 (+ 118 in test files, excluded from tier calculation)
  • Branch: brandon/brandon-json-parsing-issue
  • Author: brandon-pereira

To override this classification, remove the review/tier-3 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Oct 9, 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:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • 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
    severity. Reply with one sentence; if it is critical, 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 critical · 🟠 2 major · 🔵 1 minor

2 posted as inline comment(s) on the changed lines. 1 listed below.

Findings outside the changed lines

  • 🟠 packages/app/src/components/TeamSettings/WebhookForm.tsx:426 — The body editor still lints raw JSON, so it disagrees with the new template check in both directions → In the body editor (WebhookForm.tsx:424-427), the json() + linter(jsonLinterWithEmptyCheck()) extensions still parse the raw text as JSON. The template the docs now recommend, {{#if (eq state "ALERT")}}, gets a red JSON lint error even though getWebhookTemplateError accepts it. The escaped \"ALERT\" form passes the JSON lint but now shows the new Handlebars error. Drop the JSON parse linter from the body editor (headers can keep it), or make it skip text inside {{ … }}, so users don't get two contradictory signals.

Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found. The change is well-scoped and well-tested: getWebhookTemplateError parses with stock Handlebars.precompile, and delivery (packages/api/src/tasks/checkAlerts/transports/generic.ts:214-227) compiles with createHandlebarsWithHelpers() using the same parser and { noEscape: true }, so the compile-error surface shown in the editor matches what delivery would hit for the common eq case. Error-location extraction is null-safe and degrades to a message-only error if Handlebars internals change. The prior Greptile P2 (test asserted before the 300 ms debounce) is fully resolved in e13fe6ae.

🟡 P2 — recommended

  • packages/app/src/components/TeamSettings/WebhookForm.tsx:143 — The inline error is display-only and derived from a 300 ms-debounced body; the save button is not gated on bodyError, so a user who pastes an invalid template and saves within the debounce window (or ignores the warning) still persists a broken body — the same silent save the feature set out to surface.
    • Fix: On submit, evaluate getWebhookTemplateError against the current (non-debounced) body and block or confirm the save when it returns a non-null error.
🔵 P3 nitpicks (3)
  • packages/common-utils/src/core/handlebarsEnv.ts:188 — Recovering the parse-error column by reading the undocumented global Handlebars.Parser.lexer.yylloc couples this code to Handlebars internals that may move across upgrades; it degrades gracefully to a message-only error and the column is test-guarded, but the coupling is worth a pinned-version note.
    • Fix: Add a comment pinning the behavior to the current handlebars version so a future bump that drops the column is caught deliberately.
  • packages/app/src/components/TeamSettings/__tests__/WebhookForm.test.tsx:190 — The valid-body test waits on a real 400 ms setTimeout, adding wall-clock time and mild flake risk under a loaded CI runner.
    • Fix: Drive the debounce with fake timers (jest.useFakeTimers / advanceTimersByTime) instead of a real delay.
  • packages/app/src/components/TeamSettings/WebhookBodyValidation.tsx:5 — The errorTitle branches for a missing line ('Template error') and missing column ('... on line N') are not exercised by any test.
    • Fix: Add a unit test for WebhookBodyValidationAlert covering the line == null and column == null title variants.

Reviewers (8): correctness, adversarial, kieran-typescript, testing, maintainability, julik-frontend-races, project-standards, previous-comments.

Testing gaps:

  • No test asserts that a Slack webhook with an invalid body shows no error (the service === Slack skip branch in WebhookForm.tsx:146 is uncovered).
  • The WebhookBodyValidationAlert title fallbacks (missing line/column) 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

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

Could we possibly add validation to the API endpoint for this too?

I also think it may be worth having a /validate endpoint similar to our dashboards which allow us to validate configs like this during plan time in terraform.

@brandon-pereira

Copy link
Copy Markdown
Member Author

Could we possibly add validation to the API endpoint for this too?

I also think it may be worth having a /validate endpoint similar to our dashboards which allow us to validate configs like this during plan time in terraform.

Agreed - not in the PR description but I was planning to add backend validation for API/MCP/etc in the next PR :)

@brandon-pereira

Copy link
Copy Markdown
Member Author

@jordan-simonovski pt 2: #3365

@kodiakhq
kodiakhq Bot merged commit 807cd9a into main Oct 14, 2026
29 checks passed
kodiakhq Bot pushed a commit that referenced this pull request Oct 14, 2026
…v2/webhooks/validate (#3365)

Builds on #3350 (base is that branch; retarget to `main` once it merges).

## Why

#3350 shows Handlebars compile errors in the webhook form, but saving still goes through, and the External API v2 and MCP never checked the body. A body that doesn't compile fails on every alert delivery. This rejects it at write time. It also adds the `/validate` endpoint requested on #3350 so Terraform can check webhook configs at plan time.

## What changed

- Generic and incident.io body templates that don't compile now get a 400 on create, update and test, with the Handlebars message plus line/column, e.g. `Invalid webhook body template (line 1, column 29): Parse error on line 1: …`. Slack and empty bodies are skipped.
  - Internal API: `POST /webhooks`, `PUT /webhooks/:id`, `POST /webhooks/test` (rejects before sending).
  - External API v2 and MCP `clickstack_save_webhook` get the check through `createWebhook`/`updateWebhook`. MCP returns it as a user error.
- New `POST /api/v2/webhooks/validate`, modelled on `POST /api/v2/dashboards/validate`. It parses with `externalWebhookCreateSchema`, runs the same URL and body checks as create, never saves, and always returns 200 with `{ valid, errors: [{ path, message }], normalized }`. It doesn't check name uniqueness. `openapi.json` is regenerated.
- The check only compiles the template. It deliberately doesn't render it and parse the output as JSON.
- The MCP `body` description and `docs/alert-webhook-template-variables.md` now say these templates are rejected.

## Tests

`make dev-int FILE=webhooks`: 154 passed. Coverage:
- 400 on create and update for the internal API, External API v2 and MCP
- `/test` rejects without sending
- `{{#if (eq state "ALERT")}}…` still saves
- `/validate`: valid, invalid body, URL and body errors together, schema errors, 401 without a key

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — d15a797b Deployed Oct 14, 2026 by vercel[bot]
Preview – hyperdx-storybook — d15a797b Deployed Oct 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge review/tier-3 Standard — full human review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants