-
Start the simulated hospital
-
Learning normal behaviour
-
All alerts healthy
-
Rules vs expected
-
Injecting faults
-
Glucose unit change caught
-
Alerts at risk
-
Potassium code change caught
-
AI triage and ground truth
-
72 h alert history
-
Two faults, two incidents
-
Incident list
-
Threshold typo caught instantly
-
Rule version diff
-
155 of 160 faults caught
Inspiration
Hospitals rely on clinical decision support (CDS) alerts: "warn the doctor if potassium is above 6.0", "flag a creatinine rise that suggests kidney injury". These rules sit at the end of a long chain: lab interface → code → value set → concept → rule. When anything upstream changes (a lab starts sending potassium under a new local code, glucose switches from mg/dL to mmol/L, someone types a threshold of 60 instead of 6.0), the alert usually doesn't crash. It just goes quiet. A silent alert looks exactly like a quiet day, so these breaks are typically found by clinicians, days or weeks later.
Software engineers would never run a production service without monitoring. We wanted to give clinical informatics teams the same thing for their alert rules: a canary that notices first.
What it does
CDS Canary watches a hospital's alert rules the way an SRE team watches production services. It first learns 28 days of normal behaviour, then monitors four layers and links them through a lineage graph (feed → code → value set → concept → rule):
| Layer | Watches | Typical detection |
|---|---|---|
| Execution | rule errors, patients skipped for missing values | ~15 min |
| Input data | unknown codes, nulls, unit changes, delays, volume, value distribution | 15–60 min |
| Output | each alert's hourly firing count and firing ratio vs its own baseline | hours |
| Config | every rule or value-set change, replayed against the last 7 days | immediately |
When something looks wrong, related signals are grouped into one incident that names the most upstream broken node (the root) and the alerts that are affected or at risk. A trained classifier then guesses the fault type (code remap, unit mismatch, feed outage…), and a template writes a short summary with recommended checks. The summary is checked so it can't invent numbers or give clinical advice.
A live dashboard shows every alert against its expected band, the incidents with their evidence, and each alert's 72-hour history. A Chaos page injects 8 realistic faults plus 1 harmless control (a patient surge) so you can watch it work. It's the "test button" on the smoke detector.
Educational simulation only: synthetic data, illustrative rules, no clinical use.
How we built it
A deterministic simulated hospital. 400 beds, ~100 admissions a day, lab/pharmacy/ADT feeds with real LOINC and RxNorm codes, and a daily 05:00 lab draw. Seeded randomness and integer sim time mean a seed plus a fault journal reproduces a run exactly. We chose simulation on purpose: no public dataset records when an alert silently broke, and we need that ground truth to score detection.
Detectors (NumPy ring buffers, 15/60-min windows), each compared with an hour-of-week baseline λ0 learned in warm-up:
- Poisson tail test on each hour's count
x:s = −log10 P(X ≥ x | λ0) - Poisson CUSUM for sustained shifts:
S(t) = max(0, S(t−1) + x·ln ρ − λ0·(ρ − 1)) - Silence: raises an alarm when
exp(−Σ λ0) < 10⁻³since the last firing - A binomial CUSUM on the firing ratio (fired / eligible), which separates "more patients" from "broken rule"
- Data contracts (unmapped codes, nulls, units, lag, feed silence, drift) and a config canary that replays 7 days through the old and new rule
Thresholds are never hand-tuned: make calibrate sets them from 20 healthy hospitals, with a Gumbel tail margin.
AI triage. ~40 features per incident, taken from detector outputs only. A gradient-boosted classifier with isotonic calibration, trained on 40 hospitals × 8 fault types; a fixed decision table is the baseline and the fallback.
Stack. Python 3.12, FastAPI, SQLite, scikit-learn; React + TypeScript, Tailwind, shadcn/ui, Recharts; live updates over SSE. One Docker image: docker compose up --build.
Evaluation
What and how. make eval tests 20 hospitals (seeds 101–120) never used for calibration or training. Each gets 14 healthy days, one 72-hour run per fault type (random time and magnitude) and a patient surge where nothing is broken. A fault counts as detected only if a malfunction incident opens on the broken part of the data path. We measure detection rate, time to detect, false incidents and triage accuracy, with 95% Wilson intervals.
Baselines (on the rules downstream of the fault): an SPC c-chart on daily alert counts with the Western Electric rules, and "alert if a rule hasn't fired in 24 h".
| Method | Faults detected (95% CI) | False alarms / 100 rule-days |
|---|---|---|
| CDS Canary | 155/160 = 96.9% (92.9–98.7%) | 0.12 |
| SPC c-chart | 109/160 = 68.1% (60.6–74.8%) | 3.99 |
| No firing in 24 h | 64/160 = 40.0% (32.7–47.7%) | 8.57 |
| Fault | Detected | Median time to detect |
|---|---|---|
| Threshold typo | 20/20 | 0 min |
| Terminology drift | 20/20 | 11 min |
| Unit mismatch | 20/20 | 30 min |
| Code remap | 20/20 | 98 min |
| Lab feed delay | 20/20 | 2.0 h |
| Missing values | 17/20 | 2.2 h |
| Feed outage | 19/20 | 2.8 h |
| Partial message loss | 19/20 | 9.2 h |
- Comparators: they took a median of 13–42 h when they detected the fault at all.
- Surge (control): 1 false malfunction in 20 surges; the rest were correctly labelled population shifts.
- Triage: 96.8% correct (macro-F1 0.968), against 86.5% for the decision table. Its only confusion was 5 lab delays called outages.
- Time of day: a median of 60 min for faults starting in the daytime; 3.8 h at night.
When the result stops being useful: at night, when there are few lab results; when only a small fraction of values go missing; for rare alerts (about one a day); and outside our simulator, since these are faults we designed in a hospital we simulated.
Challenges we ran into
- Telling "broken" from "busy". A flu surge also raises alert counts. We added a firing-ratio monitor and a rule that output-only deviations with a matching volume shift become population-shift notices, not malfunctions.
- Night-time blindness. Lab volume drops to almost nothing between 22:00 and 04:00, so a window can look normal simply because it's empty. Count floors now gate raising an alarm only; clearing requires the rate to actually return to normal.
- False alarms vs sensitivity. With the textbook CUSUM threshold $h = 5$, healthy hospitals alarmed every 600–900 hours and 15% of surges looked like malfunctions. Calibrating on 20 hospitals with a Gumbel margin fixed this without hand-tuning.
- Recovery that took days. After a 24-hour outage, an uncapped CUSUM sat far above its threshold and took days to clear, so we cap it at $h$ while an alarm is raised.
- Keeping ourselves honest. Detectors must never see the injected fault. An AST test fails the build if
detect/,incidents/or the classifier imports anything from the fault code. - Engineering surprises. The evaluation's 8 worker processes each spawned 8 BLAS threads and thrashed the CPU, so each worker is now limited to one thread. An unpinned Docker build pulled a new FastAPI release that crashed every request, so we now pin tested versions in a constraints file.
Accomplishments that we're proud of
- Catching 97% of faults on hospitals the system had never seen, mostly within hours, against 68% for a classic control chart.
- Reproducible end to end:
make evalregenerates every number in this write-up in about 80 seconds, from a clean clone. - A config canary that flags a mistyped threshold the moment it's saved, before a single patient is missed.
- An AI component that is useful but bounded: it explains, it never decides, and it can't invent numbers or give clinical advice.
What we learned
- Monitoring the inputs beats monitoring the outputs. The input-data layer caught most faults far earlier than any alert-count method, which is exactly where traditional approaches are slowest.
- A baseline must be honest about time. Hour-of-week seasonality, night-time volume and frozen baselines (never refit while running) mattered more than any fancy model.
- Evaluation design is half the project. Separate seed ranges for calibration, training and testing, clean twin runs and Wilson intervals turned "it seems to work" into a number we can defend.
- Simulation is a tool, not a shortcut. It gave us ground truth we couldn't get otherwise, and it also defines the limits of what we can claim.
What's next for CDS Canary
- Read-only ingestion of real alert logs (firing counts and rule versions) to learn baselines from real volumes.
- Run the 7-day canary replay in CI on every rule or value-set change, before it ships.
- FHIR and HL7 adapters for the feeds, plus authentication and multi-team support.
- An LLM-written narrative (Groq), held to the same grounding checks as the templates.
Who benefits, and who could be harmed
- Benefits: CDS and clinical informatics teams, who could find a broken alert in hours instead of weeks. Patients, indirectly, through fewer silently missing safety warnings.
- Could be harmed: a quiet dashboard trusted without validation on real data could give false reassurance, and noisy incidents could add alert fatigue for the team running it. It must never be used to make or change clinical decisions, and it shows no clinical advice.
Limitations
- Everything is simulated: the hospital, codes, volumes and rules. No real alert logs were used.
- The faults and detectors were designed by the same team, so the rates say nothing about failure modes we didn't imagine.
- The classifier learns this simulator's fault signatures; its real-world accuracy is unknown.
- Single process, no authentication, and engine state is not kept across restarts.
Built with, attribution and AI disclosure
- All patients and events are synthetic. LOINC® content © Regenstrief Institute, Inc. and the LOINC Committee; RxNorm codes from the U.S. National Library of Medicine.
- Libraries: FastAPI, Starlette, Uvicorn, Pydantic, SQLAlchemy, NumPy, SciPy, scikit-learn, PyYAML, React, Vite, Tailwind CSS, shadcn/ui, Recharts, TanStack Query, Zustand, React Router and lucide-react.
- AI tools: Claude Code (Anthropic) helped write code and documentation.
- Code: https://github.com/Zanaad/cds-canary