Skip to content

feat(alerts): also send alerts to ntfy, Slack, Discord, Telegram or a JSON webhook - #2940

Merged
devswha merged 8 commits into
mainfrom
feat/alert-webhooks
Nov 5, 2026
Merged

devswha merged 8 commits into
mainfrom
feat/alert-webhooks

Conversation

@devswha

@devswha devswha commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2920

What

Settings → Alerts → Also send to: one destination this PC also posts its pane alerts to.

  • Presets: ntfy topic, Slack incoming webhook, Discord webhook, Telegram bot (token + chat id), or plain JSON to any URL.
  • The same events as push (needs input, needs permission, finished with Off / Long turns / Every turn, stopped on an error, terminal ended), with the destination's own choices. It goes through push's scheduler, so it gets the same waits, call-offs, mutes and "a window is in use" hold as a device.
  • A message names only the PC, the pane and what happened, plus a link that opens the pane (?pane=…&view=chat, machine= for another PC). The link base is the origin of the browser that saved the destination.
  • Send a test posts one test message. The last error ("HTTP 404", "no response") shows under the field.
  • Never floods: one post at a time and at most one waiting (a newer alert replaces the waiting one). Network, 429 and 5xx failures are retried after 5 s / 30 s / 120 s; other answers are not retried. Redirects are refused, and each post times out after 10 s.
  • The URL or token is stored in alert-webhook.json in the state dir through writePrivateState (0600). It is never answered back; the view shows only its host (discord.com/…). The secret field is an uncontrolled password input (src/AGENTS.md).
  • A watching device can read the masked view but cannot change it or send a test (the existing mutating && !ownPreferences rule). A Portal visitor cannot set one either: the routes are standing access, like push subscriptions.
  • A retry is dropped once the alert is no longer news (the pane changed, it was muted, a window is in use, the kind was turned off). A new destination ends the old one's backoff. Test posts go out one at a time. A save made over the relay keeps the link base saved before.

Routes (shared/alert-webhook.ts): GET/PUT/DELETE /api/alerts/webhook, POST /api/alerts/webhook/test.

Out of scope: an inbound bot (answering from Slack or Telegram), as the issue says. Including the question or answer text is left out entirely rather than added as an opt-in: push alerts do not carry that text today, so there is nothing to opt into yet.

Design: none of the reference apps (Codex, Claude, Paseo, T3 Code, Zed, Warp, Conductor) has outbound chat alerts. The form follows the app's own write-only secret pattern from Settings → Voice input → OpenAI API key (password field, Save, masked state), with Alerts' existing per-event controls reused.

Screenshots

390 and 1280, light and dark, captured from the demo by scripts/alert-webhook-demo-regression.ts (UI_EVIDENCE_DIR); the script also runs in the browser lane (scripts/ci-browser.sh).

Validation

  • bun test server/alert-webhook.test.ts server/open-access.test.ts server/dispatch.test.ts server/push.test.ts: 116 pass (alert-webhook: 17 now). Covers the format of each preset, masking and 0600, refused URLs and tokens, retry with a single waiting slot, no retry on 4xx, the routes, and push → webhook timing, choices and the in-use hold. The push integration test failed before the push.ts change.
  • bun test server/push.test.ts server/push-health.contract.test.ts server/conversation-push.contract.test.ts server/core/status.test.ts: 156 pass.
  • bun test src/lib/i18n.test.ts src/conventions.test.ts: pass.
  • bun run typecheck: pass.
  • bun scripts/alert-webhook-demo-regression.ts: PASS at 390/1280, light/dark.
  • bun run check fast: pass at the head (11892 unit tests, 0 fail).
  • Skipped: check full and the Windows/Mac jobs (left to CI).

Review round

omo and Codex (Terra, xhigh) reviewed 1a682b1. The fixes are in the next commit, each with a test that failed first:

  • Mask showed the last 4 chars, enough for a short ntfy topic (Codex HIGH, omo LOW): now the host only.
  • Retry after the alert stopped being news (MEDIUM): checked before every try.
  • New destination waited behind the old backoff (MEDIUM): a save or removal wakes it.
  • Unbounded concurrent tests (MEDIUM) and a stale test result after removal (LOW): one test at a time, recorded only for the same destination.
  • Relay origin saved as the link base (omo MEDIUM): ignored.
  • Portal visitor could leave a standing destination (omo MEDIUM): the routes are standing access.
  • Quick toggles could save out of order (omo LOW): one save at a time.
  • Codex re-review of c93e452 (HIGH): a destination outlived the access of whoever set it (open LAN after the gate closed, a revoked device). It now records its owner like a push subscription and asks push's canDeliver before every try, also after a restart.
  • omo + Codex re-review of d4b232a (MEDIUMs): a retry still went out after the terminal ended, after the status came back (A-B-A), or after a mute was undone. Push now bumps a per-pane epoch wherever it calls off an alert and on a mute, and a retry needs its epoch unchanged. A test of a new destination no longer shares the old destination's in-flight answer. The note and guide say the pane goes by its terminal title. Finished is disabled while a save is out. The tests wait on the fake destination's posts, not a polling loop.

CodeRabbit hit its review limit on this PR.

… JSON webhook

Settings -> Alerts -> Also send to: one destination this PC also posts its pane
alerts to, with its own alert choices, the same waits and holds as a device, a
test button and the last error. The URL or token is stored owner-only in the
state dir and only ever answered masked. One post at a time and at most one
waiting, retried with backoff on network/429/5xx failures.

Fixes #2920
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Summary

Summary by CodeRabbit

  • New Features
    • Configure selected pane alerts to also send to ntfy, Slack or Discord webhooks, Telegram, or a plain JSON URL.
    • Choose which alerts to forward, test the destination, and view delivery errors. Saved credentials are masked and remain on the PC; notifications include pane links without agent conversation content.
    • Use the new alert-destination settings in English, Japanese, Korean, and Simplified Chinese.
  • Documentation
    • Added setup details, delivery behavior, and a clarification that forwarded alerts are sent as plain text.
  • Tests
    • Added browser and server coverage for destination settings, secret masking, and delivery behavior.

Adds configurable outbound alert destinations for selected pane events. The server stores destination settings, sends formatted alerts, and tracks delivery outcomes. The Alerts settings page supports destination configuration and testing.

Changes: Outbound Alert Webhooks

Layer / File(s) Summary
Webhook contract and delivery service
shared/alert-webhook.ts, server/alert-webhook.ts, server/alert-webhook.test.ts
Defines the webhook settings and view types. The server validates and stores destinations, formats requests for each preset, masks secrets, and handles delivery retries and status. Tests cover request formats, settings, delivery behavior, and HTTP routes.
Alert scheduling and server routing
server/push.ts, server/core/status.ts, server/core/server-core.ts, server/dispatch.ts, server/open-access.test.ts, server/alert-webhook.test.ts
Connects webhook delivery to selected status, error, and ended alerts. Checks delivery eligibility and invalidates stale retries. Routes webhook requests and restricts mutating requests for Portal visitors.
Settings UI and regression coverage
src/components/AlertWebhookGroup.tsx, src/components/SettingsControls.tsx, src/components/SettingsDialog.*, src/lib/api.ts, src/lib/i18n/*, site/demo/transport.ts, scripts/alert-webhook-demo-regression.ts, scripts/ci-browser.sh, docs/guide.md, docs/development.md, changelog.d/alert-webhooks.md
Adds destination controls, API helpers, demo transport behavior, and translations. Browser regression coverage checks Telegram and Discord settings across viewport and theme variants. The guide and changelog describe the feature.

Estimated code review effort: 4 (Complex) | ~45 minutes

Severity of issue fixed: Medium

Possibly related PRs

  • devswha/ovis#1848: Adds shared pane muting, which webhook alert scheduling checks before delivery.
  • devswha/ovis#2923: Changes PC alert filtering keys used by the shared alert path that webhook delivery follows.

Suggested reviewers: rabbitson87, eddieparc

Merge Risk: Moderate · up to 0d79c

Resolve the destination autosave behavior before merging: changing an alert choice can redirect notifications without pressing Save. Delivery failures can also remain hidden, and some pane links and delivery restrictions are not honored. These are material configuration and notification-reliability risks, not evidence of a broad outage.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

- Mask a destination as its host only: an ntfy topic or a short path was readable from the last four characters.
- Drop a retry once the alert is no longer news (pane changed, muted, a window in use, kind turned off).
- A save or removal ends the old destination's backoff, so a new destination is not held behind it.
- One test post at a time; a test of a removed or replaced destination records nothing.
- Keep the saved link base on a relay request, whose origin opens nothing.
- Refuse webhook changes to a Portal visitor, as push subscriptions are (standing access).
- Settings: one preference save at a time.
The destination records who saved it, as a push subscription records its device
(a paired device, null for a local/token sign-in, absent for the open LAN), and
every try asks the same canDeliver push uses: a revoked device's or a closed open
LAN's destination gets nothing, also after a restart.
- push.ts bumps a per-pane epoch wherever it calls off an alert (a change, an end,
  a resync) and when a pane is muted; a webhook retry goes out only under the
  epoch it was sent in, so an ended terminal, a status that came back, or a mute
  undone resurrects nothing.
- A test of a new destination is its own, not the one still out for the old.
- Settings and the guide say the pane goes by its terminal title.
- Finished's choice waits while a save is out, like the switches.
- The tests wait for the fake destination's posts, not a polling loop.
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review status at 0d79cea: omo CLEAR. Codex (Terra, xhigh) found no HIGH. Its two reproduced MEDIUMs are in the follow-up issue #2943. The LOWs below are left as they are:

  • A new alert waits out the old alert's backoff (up to 120 s) when the old one is still retrying. It is still delivered. Fix idea: wake the backoff when send() replaces the waiting alert.
  • Opening and closing the app during a backoff does not cancel the retry. The retry is still accurate, because the pane did not change.
  • Flipping an alert switch on a saved destination also sends whatever is typed in the URL or token field (code reading).
  • The hooked map in push.ts keeps one small entry per pane that ever alerted, until that pane is muted.
  • A pane that changes while its title is being looked up can still get a stale alert. This is pre-existing: device push takes the same path on main.
  • ntfy and JSON destinations accept plain http:// to any host. Only a signed-in owner with drive access can set one.
  • paneLink leaves out the workspace, so the link of an ended pane cannot fall back to its workspace.

CodeRabbit did not review this PR (review limit reached).

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): bun run check fast passed at this head, omo CLEAR, Codex no HIGH (two reproduced MEDIUM edge cases filed as #2943), threads resolved. Opt-in (Settings > Alerts > Also send to), off by default. CodeRabbit was rate-limited, so the omo + Codex reviews stand in. Merged without waiting for GitHub CI.

@devswha
devswha merged commit 22a4b33 into main Nov 5, 2026
20 of 22 checks passed
@devswha
devswha deleted the feat/alert-webhooks branch November 5, 2026 09:47
devswha added a commit that referenced this pull request Nov 5, 2026
…ep a reachable link base (#2965)

Fixes #2943

Two edge cases of the alert webhooks (#2940), both reproduced first by a
test that fails on main.

### 1. A pending alert no longer reaches a destination set after it
arose
`server/push.ts` now records the destination's generation
(`AlertWebhook.generation()`, bumped by a save that changes the
URL/token/chat or by a removal) when it schedules a status or error
alert, and passes it with the alert. `send()` drops an alert whose
generation no longer matches. A save that only flips alert choices keeps
the generation, so it does not drop anything. Device push timers are
unchanged.

### 2. A loopback save keeps a reachable link base
`save()` keeps a saved base that another device can open when the save
comes from this PC's loopback address (relay saves already kept it). A
loopback base is still stored when nothing better is known.
`AlertWebhookView` gains `reachable_link`, and Settings → Alerts → Also
send to shows a hint when messages have no link a phone can open yet
(for example after a first save over the relay or from localhost). The
demo transport does the same check, so the existing demo regression now
asserts the hint.

### Validation
- `bun test server/alert-webhook.test.ts src/lib/i18n.test.ts
server/push.test.ts`: 124 pass (the two new tests fail on main: one
alert reached the new destination; `reachable_link` was missing and the
link pointed at 127.0.0.1).
- `bun scripts/alert-webhook-demo-regression.ts` with screenshots: PASS
at 390 and 1280, light and dark.
- `bun run check fast` at the head: pass (11953 unit tests, typecheck,
build).
- Not run locally: integration/browser lanes beyond the alert-webhook
demo regression, Windows.

A pre-PR Codex review found that an IPv4-mapped loopback origin
(`[::ffff:127.0.0.1]`, which `URL` writes as `[::ffff:7f00:1]`) still
counted as reachable, and that the demo's loopback check differed from
the server's; both are fixed in the second commit with a test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alerts: also send them to ntfy, Slack, Discord, Telegram or a webhook

1 participant