Track incidents, bug reports, and performance
Slabs captures runtime crashes, dead-letter jobs, slow routes, slow jobs, and user bug reports into one SQLite or PostgreSQL table (slabs_incidents) with zero external services. Every record maps 1-to-1 to a single source_file (slabs/<feature>/<action>.rs or jobs/<name>.rs), and every matching tracing log event includes a structured slab_file field so humans and coding agents jump straight to the owning Transaction Script.
Active failures inbox (slabs_incidents / slabs.incident.v1)
Every runtime signal writes to slabs_incidents using the slabs.incident.v1 schema:
| Category | kind values | Trigger |
|---|---|---|
| Runtime crashes | http_5xx, panic, job_dead | Unhandled 5xx response, caught handler panic, or dead-lettered background job (including jobs dead-lettered after invalid JSON payloads). |
| Performance bottlenecks | slow_request, slow_job | HTTP request or background job exceeding its millisecond latency threshold. |
| User bug reports | user_bug_report | Submitted by your application’s own slabs/support/report_bug.rs slab generated with slabs new bug-report. |
Each incident hashes its kind, source_file, route, and normalized error into a deterministic fingerprint and moves through three lifecycle states (open, resolved, and reopened):
| Status | Meaning | Next transitions |
|---|---|---|
open | New active failure awaiting a fix. | resolved (manual resolve or stale auto-close) |
resolved | Fixed and optionally tagged with resolved_in_sha, or closed after the stale inactivity window. | reopened (if the same fingerprint fires again) |
reopened | Previously resolved failure that recurred on a later request or job run. | resolved (manual resolve or stale auto-close) |
Deduplication and auto-close rules keep the inbox focused on live failures:
- Repeating an
openorreopenedincident incrementsoccurrences, updateslast_seen_at, and appends torecent_occurrences_jsonwithout creating duplicate rows or sending repeat webhooks. - Repeating a
resolvedincident transitions it toreopened, clearsresolved_in_sha, incrementsoccurrences, updateslast_seen_at, and emits anincident.reopenedwebhook. - Querying with
status=active(the default) returns bothopenandreopenedrows ordered bylast_seen_at DESC. - Stale auto-close transitions any
openorreopenedincident with no new hits forSLABS_INCIDENT_STALE_DAYSdays (default30; set0to disable) toresolved. - Every row stores
source_file,route_pattern,git_sha,context_json,detail,repro_hint, andrecent_occurrences_json. - Structured
tracinglogs tag HTTP failures, panics, slow routes, and job errors withslab_file = "<source_file>"so log aggregation andslabs_incidentsshare the same file key.
Pinpoint regressions with recent occurrence history
Each incident stores a capped 10-entry JSON ring buffer in recent_occurrences_json. Whenever a matching fingerprint fires, Slabs appends an entry with four fields and drops the oldest entry once the list exceeds 10 items:
[
{
"seen_at": "2026-12-03T01:12:08.412019Z",
"git_sha": "8a4f2c1",
"request_id": "req_01JXYZ9A2B3C4D5E6F7G8H9J0K",
"latency_ms": 642
}
]
Reading recent_occurrences_json shows the exact deploy git_sha where a crash or latency regression started, along with the request_id and latency_ms of the last 10 hits.
Scaffold a user-owned bug report slab
Slabs does not ship a framework widget or client JavaScript bundle for bug reporting. Instead, generate a self-contained, user-owned slab inside your own repository:
slabs new bug-report
This command creates slabs/support/report_bug.rs without editing any existing file. Because the file lives in your slabs/ directory, slabs-build discovers it at compile time and you control its route, authentication guard, styling, and tests:
- Renders a zero-JS HTML/HTMX multipart form accepting a bug description and up to 3 image, video, or file attachments.
- Stores uploaded attachments safely with
ctx.storage.put_scoped("bug_report", ...)so each blob is scoped to bug reports and served with sandboxed headers. - Captures the authenticated
user_idon the server, a sanitizedRefererpath, and theUser-Agentheader without trusting client-supplied identity fields. - Records a
user_bug_reportincident directly intoctx.incidentswith the stored attachment blob IDs attached to the incident payload. - Includes co-located
#[cfg(test)] mod testsverifying form validation, attachment uploads, and incident persistence.
Measure per-route performance and catch query scans
1. Inspect fixed-bucket latency histograms at /_slabs/metrics
Slabs tracks request counts, 5xx counts, slow request counts, and fixed-bucket p50, p95, and p99 latency histograms per route, mapped directly to source_file. Request Prometheus text format by default, or pass Accept: application/json for structured JSON:
curl -H "Authorization: Bearer $SLABS_METRICS_TOKEN" \
-H "Accept: application/json" \
https://app.example.com/_slabs/metrics
Tune slow-operation and stale-incident thresholds with environment variables:
| Variable | Default | Effect |
|---|---|---|
SLABS_SLOW_REQUEST_MS | 500 | Records a slow_request incident when a non-streaming HTTP request meets or exceeds this duration in milliseconds. Excludes /_slabs/*, SSE, and WebSocket upgrades. |
SLABS_SLOW_JOB_MS | 5000 | Records a slow_job incident when a background job meets or exceeds this duration in milliseconds. |
SLABS_INCIDENT_STALE_DAYS | 30 | Auto-resolves open and reopened incidents with no occurrences for this many days. Set to 0 to disable stale auto-close. |
2. Assert indexed query plans in co-located tests
Call Db::explain_query_plan inside a slab’s #[cfg(test)] mod tests block to run SQLite EXPLAIN QUERY PLAN against a read-only SELECT or WITH statement and fail CI if a query regresses to a full table SCAN:
#![allow(unused)]
fn main() {
#[cfg(test)]
mod tests {
#[tokio::test]
async fn messages_query_uses_room_index() {
let app = crate::test_app().await;
let plan = app
.ctx
.db
.explain_query_plan(
"SELECT id, body FROM messages WHERE room_id = 'room_1' ORDER BY created_at DESC LIMIT 50",
)
.await
.unwrap();
assert!(
plan.iter().any(|line| line.contains("USING INDEX")),
"expected indexed lookup, got plan: {plan:?}"
);
assert!(
!plan.iter().any(|line| line.starts_with("SCAN ")),
"unexpected full table scan: {plan:?}"
);
}
}
}
Consume incidents over HTTP, webhooks, and the CLI
1. Four-endpoint Bearer-protected HTTP API
Slabs exposes four JSON and blob endpoints under /_slabs/incidents, protected by a constant-time Authorization: Bearer $SLABS_METRICS_TOKEN check (in staging and production, these routes return 404 when SLABS_METRICS_TOKEN is unset):
| Method | Path | Behavior |
|---|---|---|
GET | /_slabs/incidents?status=active|open|reopened|resolved|all&limit=50 | Lists incidents ordered by last_seen_at DESC. Defaults to status=active (open plus reopened). |
GET | /_slabs/incidents/{id} | Returns one incident’s full metadata, source_file, context_json, recent_occurrences_json, attachment IDs, and a ready-to-paste repro_test Rust test skeleton. |
GET | /_slabs/incidents/{id}/attachments/{blob_id} | Streams a scoped bug-report attachment blob stored for that incident with safe download headers. |
POST | /_slabs/incidents/{id}/resolve | Transitions the incident to resolved with an optional JSON body {"resolved_in_sha": "<git_sha>"}. |
# List active (open and reopened) incidents
curl -H "Authorization: Bearer $SLABS_METRICS_TOKEN" \
"https://app.example.com/_slabs/incidents?status=active"
# Fetch one incident plus its ready-to-paste repro_test skeleton
curl -H "Authorization: Bearer $SLABS_METRICS_TOKEN" \
https://app.example.com/_slabs/incidents/inc_01JXYZ...
# Resolve after deploying the fix
curl -X POST \
-H "Authorization: Bearer $SLABS_METRICS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"resolved_in_sha":"8a4f2c1"}' \
https://app.example.com/_slabs/incidents/inc_01JXYZ.../resolve
2. Signed slabs.incident.v1 webhooks
Forward incident lifecycle transitions to Linear, Jira, GitHub Issues, or an automated agent trigger by setting two environment variables:
export SLABS_INCIDENT_WEBHOOK_URL="https://hooks.example.com/slabs-incidents"
export SLABS_INCIDENT_WEBHOOK_SECRET="replace-with-a-random-32-byte-secret"
Slabs sends an SSRF-validated POST request only on state transitions (incident.opened, incident.reopened, and incident.resolved), skipping noisy occurrence increments on already-active incidents:
X-Slabs-Protocol: slabs.incident.v1X-Slabs-Event: incident.opened | incident.reopened | incident.resolvedX-Slabs-Signature: sha256=<hmac-sha256-hex>(sent whenSLABS_INCIDENT_WEBHOOK_SECRETis set)
Downstream receivers can key external issues by the deterministic fingerprint field so Linear, Jira, or GitHub Issues update the same ticket when an incident reopens or resolves.
3. CLI commands and skills/fix-incident/SKILL.md
Engineers, CI scripts, and coding agents can inspect and resolve incidents from the terminal using SLABS_URL and SLABS_METRICS_TOKEN (or --url and --token):
# List active (open and reopened) incidents
slabs incidents list --json
# Filter by a specific status (active, open, reopened, resolved, or all)
slabs incidents list --status reopened --limit 20
# Inspect per-route p50/p95/p99 latency, job queue stats, and active incident count
slabs incidents perf --json
# Read full metadata, source_file, recent_occurrences_json, and the repro_test skeleton
slabs incidents show inc_01JXYZ...
# Mark an incident resolved after deploying the fix
slabs incidents resolve inc_01JXYZ... --sha 8a4f2c1
Pair these commands with skills/fix-incident/SKILL.md so a coding agent pulls the active inbox with slabs incidents list --json, inspects slabs incidents show <id>, opens only source_file and schema.sql, pastes and completes the repro_test regression test, implements the fix, runs slabs check, and calls slabs incidents resolve <id> --sha <sha>.