All workCase study 02 / 03

DeepBell

Catches what breaks in a running app, finds the likely cause and writes the incident report. A mini SRE lab in FastAPI: it detects anomalies in its own CPU and memory, fires alert rules, traces each incident to a likely cause, writes incident reports and restores from snapshots.

Year
2026
Built with
FastAPI · LangChain · Docker
Proof
144 tests · CI passing
Source
github.com/vishnuatgit/DeepBell
Code on GitHub Download PDF
DeepBell's live console during the guided demo: a memory-leak incident is open, the How it works pipeline has lit up Sample, Detect and Report, and the guided demo is on step 5 of 8

(01)The problem

Why it exists

DeepBell runs the whole incident loop on one small service.

Background threads sample the service's own CPU and memory every 2 s. A baseline check plus an Isolation Forest flags anomalies and opens de-duplicated incidents, each incident gets a written report, and rolling SQLite snapshots give one-click rollback.

A capped fault-injection lab (the Chaos Lab) lets you break it on purpose, and every incident records when it started, was detected and resolved, so detection and recovery are timed.

(02)How it works

From the README
DeepBell detect, report, recover loopCapped faults from the Chaos Lab or the guided demo affect the service. A background thread samples its own CPU and memory every 2 seconds; a baseline check plus an Isolation Forest flags anomalies; two anomalous samples in a row open a de-duplicated incident; a report is written by Gemini through LangChain, or by a built-in template; recovery releases the memory or rolls back a SQLite snapshot. Each incident keeps a timeline with its time to detect and time to recover. Chaos Lab capped faults: CPU, leak, corrupt DB 1 Sample own CPU + memory every 2 s 2 Detect baseline check + Isolation Forest Incident 2 in a row opens, de-duplicated 3 Report Gemini via LangChain or a template 4 Recover release memory or roll back Snapshots SQLite every 30 s if changed, last 10 each step lands on the incident timeline, which times detection and recovery DeepBell detect, report, recover loopCapped faults from the Chaos Lab or the guided demo affect the service. A background thread samples its own CPU and memory every 2 seconds; a baseline check plus an Isolation Forest flags anomalies; two anomalous samples in a row open a de-duplicated incident; a report is written by Gemini through LangChain, or by a built-in template; recovery releases the memory or rolls back a SQLite snapshot. Each incident keeps a timeline with its time to detect and time to recover. Chaos Lab capped faults: CPU, leak, corrupt DB 1 Sample own CPU + memory every 2 s 2 Detect baseline check + Isolation Forest Incident 2 in a row opens, de-duplicated 3 Report Gemini via LangChain or a template 4 Recover release memory or roll back Snapshots SQLite every 30 s if changed, last 10

Dashed bracket: each step lands on the incident timeline, which times detection and recovery.

  1. Sample. Every 2 s the watchdog reads the process's CPU % and resident memory with psutil and stores the sample.

  2. Detect. The detector scores the sample. Two anomalous samples in a row open an incident; three normal ones close it. A query every 2 s catches a corrupted database.

  3. Alert. Rules in alert_rules.json are checked on every sample (pending, firing, resolved) and can notify a Slack or Discord webhook from a background queue, so the sampler never waits.

  4. Report. Opening an incident starts a report in a background thread: Google Gemini through LangChain when a key is configured, a built-in template otherwise.

  5. Explain. Each incident gets one timeline (fault, alerts, anomaly, report, restore) and a likely cause with its evidence and a confidence level, labelled a heuristic.

  6. Recover. Releasing the leaked memory lets the samples return to the baseline, which closes the incident; restoring a snapshot makes the database readable again.

(03)Key decisions

6 choices
  1. A baseline check before the Isolation Forest

    A sample is a candidate only when CPU is at least 15 points above the baseline or memory at least 30 MB above it; an Isolation Forest (100 trees) must then confirm it. On its own, the forest flagged ordinary jitter.

  2. One incident per fault

    Two anomalous samples open an incident and three normal ones close it, with one incident and one report per fault kind at a time. While an incident is open its samples stay out of the baseline, so a held leak never becomes the new normal.

  3. AI reports with a built-in fallback

    Reports come from Gemini through LangChain when a key is set, and from a deterministic template otherwise or when the call fails. Every report is labelled with what wrote it.

  4. Snapshots kept apart from incident history

    The SQLite database is copied every 30 s when it changed (newest 10 kept, each integrity-checked). Incident history lives in a separate metrics.db, so corrupting or rolling back the app database never rewrites it.

  5. Safe to run as a public demo

    Every fault has caps and a cooldown: a CPU spike lasts 1 to 5 s, a leak holds at most 120 MB and is freed after 5 minutes, and a request during a cooldown gets a 429 with Retry-After. Public demo mode turns off the crash fault and the API-key endpoint.

  6. Standard metrics, explainable causes

    /metrics exposes the same signals in Prometheus format (incidents, detection and recovery times, faults, alerts), with a Docker Compose stack and a provisioned Grafana dashboard. The likely cause comes from simple rules, such as a matching fault within 10 s of the first anomalous sample, and never claims more certainty than its evidence.

(04)Proof

Tests · CI · stack
pytest tests, no network, Gemini stubbed
144
CI on Python 3.11 and 3.12, with a Docker build
Passing
between samples of its own CPU and memory
2 s

The tests use temporary directories, disable the background threads or drive them with a fake clock, and replace the Gemini call with stubs. Measured on a laptop, in six runs of the guided demo (method in the README), the leak was detected 2 to 4 s after it was injected and resolved 10 to 13 s after detection (demo measurements on a laptop, not production numbers). Alert rules run on a fake clock against a fake webhook, and end-to-end tests follow a real memory leak from the fault to the alert, incident, likely cause, report and metrics. A seeded benchmark of the real detector (20 jitter streams, 30 runs per fault, method in the README) found 0 false incidents in 3.3 simulated hours, 4 s detection and 100% recovery (p95 6 s). CI runs

  • Python 3.11, 3.12
  • FastAPI
  • Uvicorn
  • SQLite
  • psutil
  • scikit-learn
  • NumPy
  • LangChain
  • Google Gemini API
  • Jinja2
  • Chart.js
  • Prometheus
  • Grafana
  • pytest
  • Ruff
  • Docker
  • GitHub Actions

(05)How it was built

Software development lifecycle
  1. Plan. Requirements come from the major-project proposal. Static-threshold monitoring only alerts, so recovery is slow and root causes need manual log reading.

  2. Design. One FastAPI process with a module per job: detection, incidents, snapshots, alert rules and correlation. Incident history has its own SQLite file, so a rollback never rewrites it.

  3. Build. Pinned dependencies, Ruff lint and format checks, and pull requests since October 2026.

  4. Test. 144 tests with a fake clock and a stubbed Gemini. End-to-end runs inject real faults, and CI smoke-tests the Docker image in public demo mode.

  5. Deploy. Docker on Render in public demo mode. A merge to main deploys only after the checks pass, and Render watches /healthz.

  6. Maintain. Prometheus metrics, a Grafana dashboard for local runs, and in-app alert rules that move through pending, firing and resolved.

Done: an automated acceptance check ran the main user tasks on the live demo at phone and desktop sizes, and every issue an accessibility scan (axe-core) found was fixed, both on 2026-11-09. Not done yet: testing with real users and a staging environment. Latest change, taken through every stage: a dependency scan found 48 known advisories in the runtime pins. They were upgraded (FastAPI, LangChain, scikit-learn, Jinja2 and others) with the whole test suite passing, and OSV.dev now reports none. The fix was made on a branch, tested, merged through a pull request after CI passed, and deployed. Full SDLC write-up

(06)Screenshots

From the repository
Key numbers and live charts after a guided demo run: median time to detect and to recover, CPU and memory with the learned baseline, the alert line, flagged samples and shaded incident spans, and the 30-minute status strip
The overview: CPU and memory against the learned baseline, with incidents shaded.
Incidents view: a memory-leak incident with its time to detect, time to recover, lifecycle bar and timeline
An incident: time to detect, time to recover and its timeline.
DeepBell incident view for CPU spike #1: detected in 9 s and recovered in 8 s, a Likely cause panel with high confidence naming the Chaos Lab CPU busy loop with its evidence, and the merged timeline of the fault, the first anomalous sample and the alerts
An incident’s likely cause, with its evidence and the merged timeline.
DeepBell Alerts view: four rules (High CPU, Memory above baseline, Watchdog flagging samples, Database unhealthy) with their states, and recent changes from pending to firing to resolved
Alert rules and their recent state changes, from pending to firing to resolved.

(07)Limitations

Honestly
  • It monitors only itself, on two signals (CPU and resident memory). It is a practice lab for incident response; it does not replace a monitoring tool.
  • Fixed minimum deviations (15 CPU points, 30 MB), so smaller spikes and slow leaks are deliberately ignored.
  • Snapshots are not point-in-time recovery: you can restore one of the last 10, taken at most every 30 s, and a rollback loses whatever changed since.
  • No authentication. Public demo mode disables the dangerous endpoints and caps the rest, but any visitor can inject the capped faults.
  • Single worker. Open incidents, cooldowns and leaked memory live in one process, and the measured times say nothing about a production system.
  • Alerts and causes are simple. Rules are read at startup and alert history lives in memory; the likely cause sees only injected faults, CPU, memory, alerts and the database check, at 2 s resolution.
Code on GitHub
Next case study SupplyTrace

A modular pipeline that ingests raw XML invoices, validates them with deterministic rules, flags duplicates and routes doubtful ones to a review queue, with an experimental ML risk score and a vendor directory.