Scoring + dispatch
A geometric-mean alert score, gated by the data-quality flag and routed by severity band to email, in-app, and/or webhook.
flowchart TD
NEW["New diagnosis persisted"]
NEW --> DQ{"alertingDisabled?"}
DQ -->|"Yes"| TRACK{"tracking_issue?"}
TRACK -->|"Yes"| PASS["Pass through
(tracking always alerts)"]
TRACK -->|"No"| SUPPRESS["Suppress all alerts"]
DQ -->|"No"| SCORE
subgraph SCORE["alert_score = geometric mean (4th root)"]
S1["impact
recoverableRevenue % of MRR"]
S2["confidence
rank-1 userFacingConfidence"]
S3["actionability
0.1 / 0.7 / 1.0 by template count"]
S4["freshness
decay on detected_at"]
S1 & S2 & S3 & S4 --> GEOM["(S1·S2·S3·S4)^0.25"]
end
GEOM --> THRESH{"Severity band?"}
THRESH -->|"critical / high"| FULL["Email + In-app + Webhook"]
THRESH -->|"medium"| INAPP["In-app only"]
THRESH -->|"low"| NONE["Inbox only (no alert)"]
PASS --> INAPP
FULL --> REC[(posthog_alerts)]
INAPP --> REC
style GEOM fill:#c8e6c9
style SUPPRESS fill:#ffcdd2
style REC fill:#fff8e1,stroke:#FFC107