Repository navigation
Send an alert webhook when a connector keeps failing - #976
helpcodeai merged 2 commits into
Conversation
Detects a connector failing repeatedly (configurable threshold over a sliding window) and dispatches a signed webhook or Slack message, with a cooldown so a sustained outage sends one alert, not one per call. - New AlertsModule: per-org webhook config (OrgSettings), encrypted secret shown once, GET/PUT/DELETE + POST .../test admin endpoints. - Detection hooks into AuditService.logInvocation ahead of the repeat-failure dedup check, so a fast-repeating identical failure still counts toward the threshold. Fire-and-forget; never affects the MCP call path. - Sliding-window counter and cooldown via Redis (incr/expire), with an in-memory fallback when Redis isn't configured. - Dispatch is HMAC-signed and SSRF-guarded; the webhook URL ignores the env/DB connector allowlists so a workspace can't point it at a host allowed for an unrelated reason (ssrf.util.ts/outbound-http.ts gain an opt-in skipAllowlists flag for this). - Docs: new section in docs/operations/observability.md. Relates to HelpCode-ai#857.
|
Hi @keysersoft, PR 1 for the connector-failure alert webhook is up here. While working on it I noticed #857 (and the whole #840-867 range, including the October Challenge issue #846) is no longer accessible — just a 404, not sure if that was intentional. Do you still want this feature added, or has priority changed? Happy to keep going as-is if so. |
|
Hi @mirkopoloni , do we need this, because the issue is not showing , should I delete this or ? |
|
@rangarajan19 yes, we still want it, please keep going. The issue is now #1006, and the October Challenge list is #997. I'll review this PR in the next days. The CodeQL warning on |
- Cache the webhook config per organization for a minute, so failed calls of organizations without a webhook cost no database read. - Heal a failure counter whose EXPIRE was lost instead of never alerting again. - On Cloud, require https and skip the SSRF allowlists; self-hosted keeps the operator's allowlist, so an internal chat server can receive alerts. - Escape the connector name and vendor error in Slack messages. - Look the connector up inside the failing organization only. - Log undelivered alerts (without the URL), validate the URL and bound the numbers, throttle the test endpoint. - Docs: restore the 'Correlating across pipelines' heading, replay-safe verification snippet, describe the window as starting at the first failure.
|
Merged, thanks @rangarajan19! I pushed a few review fixes on top so this could go in today:
The UI card (PR 2) is next whenever you're ready. Please keep the field names and defaults from this PR. |
Summary
Backend half of #857 (PR 1 of the planned split, UI card to follow in PR 2): detects a connector failing repeatedly within a sliding window and dispatches a signed webhook (or Slack message), with a cooldown so a sustained outage sends one alert, not one per call.
Changes
AlertsModule: per-organization webhook config stored viaOrgSettingsService, signing secret generated server-side and encrypted (AES-256-GCM, AAD-bound to the org), shown once. Admin endpoints:GET/PUT/DELETE+POST .../testat/api/admin/settings/alert-webhook.AuditService.logInvocation, firing before the repeat-failure dedup check added since this plan was discussed, so a fast-repeating identical failure (the common case for a real outage) still counts toward the threshold instead of being silently skipped. Fire-and-forget: a dispatch failure is caught and logged, never affects the MCP call path.RedisService(incr/expire), with an in-memory fallback when Redis isn't configured. Dispatch fires only when the counter hits the threshold exactly, and the cooldown key is written before the dispatch goes out, so two failures crossing the threshold at the same moment can't both fire.X-AnythingMCP-Signature) and goes through the existing SSRF-guarded outbound path. The webhook URL deliberately ignores both the env (SSRF_ALLOWED_HOSTS) and the admin-editable DB allowlist —ssrf.util.ts/outbound-http.tsgain an opt-inskipAllowlistsoption for this, since those allowlists exist for connectors to reach a specific internal host for their own reason, and a webhook target must not inherit that trust.docs/operations/observability.md— payload shape, headers, a Node verification snippet.PR 2 (the Alerts card on
/settings/admin) will follow once this is reviewed.Testing
npm testinpackages/backend)New:
src/alerts/alerts.service.spec.ts,src/alerts/alerts.controller.spec.ts, and additions tosrc/audit/audit.service.spec.tscovering threshold→one dispatch, cooldown suppressing the next, cross-org isolation, signature verification, dispatch errors never affectinglogInvocation, SSRF (private IP and the cloud metadata address rejected even when allowlisted), and non-admin → 403.Ran from
packages/backend:All clean; 747 tests passing in the scoped run above (the files this PR touches and everything that depends on them).
Related Issues
Relates to #857