Alert on SQL Culprits and Deploy Regressions, Not 40 Blocked Victims

Why standard wait and session alerts page on-call for victims instead of root causes, and how Culprit's pluggable notifier sends one auto-resolving PagerDuty, Slack, or Teams alert with the culprit SQL.

If you have ever been on database on-call, you know the 3 AM alert storm: PagerDuty fires for API checkout latency, then fires for 38 blocked sessions on orders-prod, then fires for connection pool exhaustion. Every single alert names INSERT INTO dbo.order_items, which usually runs in 1.2 ms.

INSERT INTO dbo.order_items is innocent. It is sitting at the back of a lock queue behind SPID 61, where a background job ran UPDATE dbo.orders inside BEGIN TRAN, hit a slow webhook retry in Python, and left the transaction sitting idle in transaction for four minutes.

Paging an engineer with 40 victim queries wastes the first fifteen minutes of an outage just walking blocking_session_id pointers by hand. And as we saw when comparing Microsoft Database Hub vs. Culprit + ADX, gating basic alert rules behind paid Fabric Data Activator CUs adds insult to injury.

Collapse 40 victims into 1 culprit before the alert fires

In Culprit’s collector pipeline, blocking chains, metadata-lock sandwiches (LCK_M_SCH_M queued behind a long reader while blocking every new LCK_M_SCH_S caller), deadlocks, memory-grant starvation, and plan flips are reduced to single root-cause episodes in CulpritIncidentsV1 and CulpritChangesV1.

Take deadlocks. Instead of alerting “Deadlock count > 0” and leaving you to hunt down .xel files or ring buffers, the collector parses the deadlock XML (or PostgreSQL log / MySQL INNODB STATUS), redacts SQL literals, and records both the killed victim and the surviving lock holder:

Live .xdl deadlock graphHover a session or lock node to trace the cycle
Open in Culprit Explain ↗
Opposite orderPasted

Two transactions locked billing.ledger_entries and billing.subscriptions in opposite order and waited on each other; session 88's transaction was rolled back.

Holds Xholds XWants Uwants UHolds Xholds XWants Uwants Ubilling.subscriptions (PK_subscriptions · row) held by X · wanted as Ubilling.subscriptionsPK_subscriptions · rowbilling.ledger_entries (IX_ledger_sub_period · row) held by X · wanted as Ubilling.ledger_entriesIX_ledger_sub_period · rowUPDATE billing.ledger_entries SET settled_at = SYSUTCDATETIME() WHERE subscription_id = @sub_id AND period_key = @period;Session 88rolled backstripe-webhook-worker · a…UPDATE billing.ledger_en…UPDATE billing.subscriptions SET balance_cents = balance_cents - @paid WHERE id = @sub_id;Session 134invoice-reconciler · app_…UPDATE billing.subscript…
holds wantsHover or focus a box to follow its locks.

Session 88 held billing.subscriptions and wanted billing.ledger_entries; session 134 held billing.ledger_entries and wanted billing.subscriptions. With the same order in both, the second would simply wait instead of deadlocking.

How to fix it

  1. Touch tables and rows in the same order everywhere

    Make every code path that changes billing.ledger_entries and billing.subscriptions do it in one order (for example, always the parent row first, and rows sorted by key). Then the second transaction waits instead of deadlocking.

  2. Keep transactions short

    Do reads, validation and outside calls before the transaction starts; hold locks only for the writes.

  3. Retry the victim

    A deadlock victim can be retried safely; the application should catch error 1205 and run the transaction again.

Who was involved

Session 88rolled back
stripe-webhook-worker · app_billing@billing-pod-04 · read committed
UPDATE billing.ledger_entries
SET settled_at = SYSUTCDATETIME()
WHERE subscription_id = @sub_id
  AND period_key = @period;
Session 134
invoice-reconciler · app_reconciler@reconcile-cron-01 · repeatable read
UPDATE billing.subscriptions
SET balance_cents = balance_cents - @paid
WHERE id = @sub_id;
Live @culpritsql/plan-viewer graph: stripe-webhook-worker (SPID 88) locked PK_subscriptions then waited on IX_ledger_sub_period, while invoice-reconciler (SPID 134) locked IX_ledger_sub_period under REPEATABLE READ and waited on PK_subscriptions.

Hover either session node above: the incident record already knows that stripe-webhook-worker (SPID 88) and invoice-reconciler (SPID 134) acquired PK_subscriptions and IX_ledger_sub_period in opposite order, which statement lost, and how to reorder the transaction.

Three warehouse alert streams (plus collector health)

When you run culprit collect queries --config archive.json --name Prod, Culprit generates four distinct query helpers for ADX or ClickHouse so different classes of problems route cleanly:

Generated HelperWhat triggers itTypical routing
ProdRecordedIncidentAlertsDuringActive/resolved episodes in CulpritIncidentsV1 (blocking chains, deadlocks, PAGELATCH_EX, THREADPOOL, memory grants)PagerDuty + #db-incidents Slack
ProdNewRegressionsDuringCulpritChangesV1 queries that got slower or switched plans past impact threshold (enriched with culprit mark deploy timestamps)#eng-releases Slack / Teams
ProdNewHighFindingsDuringNewly observed high-severity actionable findings in CulpritFindingsV1 (e.g. log-reuse-blocked, XID wraparound, missing index)GitHub Issues / #db-tuning
ProdStatusNow / ProdStatusStale collector heartbeats, revoked VIEW DATABASE PERFORMANCE STATE, or incomplete readsPlatform / infra ops channel

If your team already triggers DRI pages from Azure Monitor Scheduled Query Rules (over ADX) or Grafana Alerting (over ClickHouse), you can call those helpers directly without running a separate alert binary:

// ADX DRI alert query (deduplicate by TargetId, OriginalScopeId, OriginalSource, EpisodeId, ControllerVersion)
ProdRecordedIncidentAlertsDuring("billing-prod", ago(5m), now())
| project FirstRecordedObservation, TargetId, OriginalScopeId, OriginalSource, EpisodeId, ControllerVersion, Mechanism, VictimSummary, DeveloperAction
-- ClickHouse DRI alert query (+ pair with ProdStatusNow for collector staleness)
SELECT FirstRecordedObservation, TargetId, OriginalScopeId, OriginalSource, EpisodeId, ControllerVersion, Mechanism, DeveloperAction, 1 AS AlertValue
FROM ProdRecordedIncidentAlertsDuring(resource = 'billing-prod', window_from = now64(9, 'UTC') - INTERVAL 5 MINUTE, window_until = now64(9, 'UTC'));

For the full list of automatic wait/DMV investigations, all 18 *V1 warehouse tables, and the ProdStatusNow dead-collector query, see 24/7 SQL Root-Cause Investigations, Warehouse Tables, and DRI Alerts.

Pluggable culprit-notify without bloated SDKs or duplicate pages

To deliver those alerts without Fabric Activator or Grafana Enterprise, we built culprit-notify around a pure state machine (AlertEvaluator) and five tiny channel crates (slack, teams, pagerduty, webhook, github-issues).

1 dedup key Keyed on (TargetId, OriginalScopeId, OriginalSource, EpisodeId, ControllerVersion)
Auto-resolve IncidentResolved events close the matching PagerDuty incident automatically
Zero vendor SDKs Pure JSON formatting over one bounded HTTPS transport with secret zeroization

Why does that five-part deduplication key matter?

In real collectors, an active blocking episode emits new revisions as wait time grows, or you might upgrade Culprit’s rules_version and backfill historical warehouse captures. Because AlertEvaluator tracks (TargetId, OriginalScopeId, OriginalSource, EpisodeId, ControllerVersion) anchored to FirstRecordedObservation (stored atomically on disk or via conditional ETag in Blob/S3), a long-running incident never re-pages on revision updates, backfills older than your novelty window stay silent, and PagerDuty auto-resolves the exact dedup_key the moment the blocker clears.

Validate your routing config offline (verifying HTTPS origins and secret references without opening sockets), then evaluate batches on a cron or Kubernetes job:

culprit collect notify validate --config /etc/culprit/notify.json
culprit collect notify evaluate --config /etc/culprit/notify.json --input alerts-batch.json

If your org uses an internal incident bus, Opsgenie, or Jira, culprit-notify-webhook signs every JSON payload with X-Culprit-Signature-256 (HMAC-SHA256), or you can register a custom Rust NotificationSink in twenty lines via NotifierBuilder::with_sink.

Include a deep link to culprit-archive-web in the Slack/Teams template, or wire the webhook into culprit agent triage-warehouse so regressions automatically draft a lint-sql-verified fix PR.