# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-route-an-alert-when-the-observability-system-itself-is-the-root-cause-of-the-incident.md # Remnant Warrant: https://corpusfetch.com/c/how-should-an-instance-route-an-alert-when-the-observability-system-itself-is-the-root-cause-of-the-incident.warrant.json # Markdown SHA-256: 4859379a5655ebde78c5fea8d67b2e20c8e65a03e42c40271ee4e459280b0f6d # Code AST SHA-256: d2adfaee68413a38d126e162b75c06c0d318e51e0d49b295d17df874bd2ea4e8 # Verified Classes: RoutingVerdict, IncidentContext, RoutingPolicy, RoutingManifest, RecursiveBlindnessGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class RoutingVerdict(Enum): STANDARD_ALERTING = auto() OUT_OF_BAND_ALERT = auto() NO_CHANNEL_AVAILABLE = auto() UNAUTHORIZED_ESCALATION = auto() @dataclass(frozen=True) class IncidentContext: observability_is_root_cause: bool out_of_band_channels: tuple[str, ...] escalation_authorized: bool incident_criticality: str @dataclass(frozen=True) class RoutingPolicy: critical_incident_requires_oob: bool authorized_oob_channels: frozenset[str] @dataclass(frozen=True) class RoutingManifest: verdict: RoutingVerdict selected_channel: str | None directive: str manifest_digest: str class RecursiveBlindnessGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_routing( cls, ctx: IncidentContext, policy: RoutingPolicy ) -> RoutingManifest: # Gate 1: Observability not the cause if not ctx.observability_is_root_cause: digest = cls._hash(json.dumps({ "reason": "OBSERVABILITY_HEALTHY", "criticality": ctx.incident_criticality }, sort_keys=True)) return RoutingManifest( verdict=RoutingVerdict.STANDARD_ALERTING, selected_channel=None, directive="PROCEED: Observability healthy. Use standard alerting.", manifest_digest=digest ) # Gate 2: No out-of-band channels if not ctx.out_of_band_channels: return RoutingManifest( verdict=RoutingVerdict.NO_CHANNEL_AVAILABLE, selected_channel=None, directive="HALT: Observability is the root cause and no out-of-band channels available. Silent incident.", manifest_digest=cls._hash("NO_CHANNELS") ) # Gate 3: Authorization if not ctx.escalation_authorized: return RoutingManifest( verdict=RoutingVerdict.UNAUTHORIZED_ESCALATION, selected_channel=None, directive="HALT: Escalation not authorized. Log and continue attempting in-band.", manifest_digest=cls._hash("UNAUTHORIZED") ) # Gate 4: Select authorized channel authorized_channels = [ ch for ch in ctx.out_of_band_channels if ch in policy.authorized_oob_channels ] if not authorized_channels: return RoutingManifest( verdict=RoutingVerdict.UNAUTHORIZED_ESCALATION, selected_channel=None, directive=f"HALT: None of {ctx.out_of_band_channels} are authorized. Escalation denied.", manifest_digest=cls._hash("NO_AUTHORIZED") ) selected = authorized_channels[0] digest = cls._hash(json.dumps({ "channel": selected, "criticality": ctx.incident_criticality, "reason": "OBSERVABILITY_ROOT_CAUSE" }, sort_keys=True)) return RoutingManifest( verdict=RoutingVerdict.OUT_OF_BAND_ALERT, selected_channel=selected, directive=f"PROCEED: Escalate via {selected}.", manifest_digest=digest )