You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(canary): split _render_forensic — complexity 123, the highest in the backend — into one renderer per invariant #4459
_render_forensic in src/backend/services/canary_alerts.py is 407 lines with cyclomatic complexity 123, the highest of any function in the backend. Split it into one renderer per forensic section.
Context
Found by the /refactor-audit run of 2026-11-10. In the June 2026 audit the same function was 183 lines at complexity 66, so it has roughly doubled in five months. _render_message in the same file is 199 lines at complexity 53.
The function turns a canary violation into alert text. Every invariant's branch lives in one body, so a missing or wrong branch is hard to notice by reading. #1880 was that class: five invariants alerted with no name, runbook or detail.
Acceptance Criteria
Each invariant (or invariant family) has its own renderer function, selected through a registry keyed by invariant id
_render_forensic and _render_message are each under complexity 15
Before the split, a golden-output test captures the rendered text for every invariant in the catalog; it passes unchanged after the split
A test fails when an invariant in the catalog has no registered renderer and no explicit generic fallback
No change to alert text, severity or routing
Technical Notes
Read docs/memory/architecture/reliability.md first; it owns canary_alerts.py.
src/backend/canary/ is the invariant library; the registry should key on its ids and not on a second hand-kept list.
Activity
docs(reports): refactor audit 2026-11-10 — full src/ scan (#4461)