Repository navigation
Description
Summary
When the canary's Slack webhook post fails, the failure is logged and swallowed. The caller cannot tell — emit_transition is -> None — so it records the transition anyway, the cycle cursor advances, and continuing-red gating guarantees the alert is never retried. The alert is lost, and cumulative_transitions says it was delivered.
The exact path
services/canary_alerts.py — the post result is read, then dropped:
success, error = await slack_service.post_webhook(webhook_url, text, blocks=blocks)
if not success:
logger.warning(
"canary slack webhook failed for %s: %s (cycle continues, row persisted)",
invariant_id, error,
)The method is annotated -> None. success never leaves the function.
services/canary_service.py — the caller treats "did not raise" as "delivered":
try:
await CanaryAlerts.emit_transition(...)
transition_ids.append(inv_id)
except Exception:
logger.exception(...)Then, unconditionally:
self.cumulative_transitions += len(transition_ids)
self._write_prev_cycle_at(snapshot.snapshot_time)Why it is never retried
_is_green_to_red returns prev["snapshot_time"] < prev_cycle_at.
- Cycle N — invariant fires. The
canary_violationsrow persists (Slack is not involved)._is_green_to_red→True. Slack rejects the post. Warning logged, no raise.transition_ids.append(inv_id)runs. Cursor advances toT_N. - Cycle N+1 — invariant still firing. Latest persisted violation is now
T_N; cursor isT_N. Check isT_N < T_N→False→ continuing-red → no notification.
The alert is never sent, never retried, and the counter reports success.
The existing defense has exactly this hole
canary_service.py already comments the cursor write:
"Done AFTER notifications so a crash mid-emit doesn't advance the cursor and silence a real transition on retry."
The failure mode was anticipated — but only the raise path is defended. emit_transition swallows instead of raising, so it walks straight through the guard the comment describes.
Why it bites at the worst time
Rejection is most likely during a fleet-wide failure: most violations, largest payloads, closest to Slack's Block Kit limits (header 150 chars, section 3000, 50 blocks — a 400 drops the entire message). That is precisely the event the canary exists to report. #1880 added truncation that makes this much less likely, but "less likely" is not "handled".
The obvious fix is wrong — read this before implementing
Do not fix this by withholding the cursor on failure. _write_prev_cycle_at writes canary:last_cycle_at, a single cycle-global Redis key, not a per-invariant one. Not advancing it because one invariant's post failed makes every other invariant re-fire as a fresh transition on the next cycle — converting one lost alert into a fleet-wide alert storm. That is worse than the bug.
The fix needs per-invariant delivery state, tracked separately from the cycle cursor.
Acceptance criteria
-
emit_transitionreports delivery outcome to its caller instead of returningNoneunconditionally - A failed send is not counted in
cumulative_transitions— the counter must not report a delivery that did not happen - An undelivered transition is retried on a later cycle while the invariant is still red, without re-alerting invariants that were delivered fine, and without touching the cycle-global cursor (see above)
- Retry is bounded — a permanently misconfigured or revoked webhook must not retry every 5 minutes forever. Decide the policy here, in the issue, before implementing: capped attempts, backoff, or give up with a distinct ERROR log. An unbounded retry against a dead webhook is a new bug, not a fix
- A send that fails permanently and is given up on is visible — a distinct log line or counter, so "we stopped trying" is never silent, which is the whole failure class being fixed
- Regression test naming this issue: a stubbed
post_webhookreturning failure must leave the transition uncounted and re-attemptable on the next cycle.tests/test_canary_invariants.pyalready has theslack_capturefixture andTestCanarySlackEmitto build on
Technical notes
slack_service.post_webhookalready returns(success, error)and enforces a 5s timeout, so the signal exists — only the plumbing is missing.- Failing loudly instead of swallowing is not an option: the surrounding
except Exceptionin the transition loop would catch it, and a hung or failing webhook must never break the cycle. The fix is to return the outcome, not to raise. - Note the ordering interaction with Canary: 5 Phase-4 invariants alert with no name, runbook, or detail — including the critical credential-leak check (G-04) #1880: the
canary_violationsrow persists regardless of Slack, so no forensic data is lost by a failed send — only the notification is. That bounds the severity, and means retry state can key off the persisted row rather than needing a new durable store.
Activity
fix(canary): a rejected Slack post is undelivered, and gets retried (#…
fix(retention): the blast-radius guard refuses instead of raising, an…