# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-should-an-instance-structure-its-symptom-index-to-route-unknown-exceptions-to-verified-boundaries.md # Remnant Warrant: https://corpusfetch.com/c/how-should-an-instance-structure-its-symptom-index-to-route-unknown-exceptions-to-verified-boundaries.warrant.json # Markdown SHA-256: 0d5d55d54368a4cf3ab31d42525c786c9eb8650bd12c808a44a9dc2b81ba6398 # Code AST SHA-256: a12d971071059c0c3f7cc800ae3fddc4e046cff0cc70cf304dbf1cfdc7b3e531 # Verified Classes: RoutingVerdict, ExceptionContext, SymptomBoundary, RoutingResult, SymptomIndexRouter # 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): EXACT_MATCH = auto() CONTEXT_MISMATCH = auto() NOT_FOUND_ESCALATE = auto() @dataclass(frozen=True) class ExceptionContext: exception_class: str error_code: str context_fingerprint: str @dataclass(frozen=True) class SymptomBoundary: boundary_id: str required_context: str @dataclass(frozen=True) class RoutingResult: verdict: RoutingVerdict boundary_id: str | None routing_digest: str class SymptomIndexRouter: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def compute_signature(cls, ctx: ExceptionContext) -> str: # Canonicalize the exception signature payload = f"{ctx.exception_class}:{ctx.error_code}:{ctx.context_fingerprint}" return cls._hash(payload) @classmethod def route_exception( cls, ctx: ExceptionContext, index: dict[str, SymptomBoundary] ) -> RoutingResult: signature = cls.compute_signature(ctx) # Gate 1: Exact match if signature in index: boundary = index[signature] if boundary.required_context != ctx.context_fingerprint: return RoutingResult( verdict=RoutingVerdict.CONTEXT_MISMATCH, boundary_id=None, routing_digest=cls._hash(f"MISMATCH:{signature}") ) return RoutingResult( verdict=RoutingVerdict.EXACT_MATCH, boundary_id=boundary.boundary_id, routing_digest=cls._hash(f"MATCH:{signature}") ) # Gate 2: Not found return RoutingResult( verdict=RoutingVerdict.NOT_FOUND_ESCALATE, boundary_id=None, routing_digest=cls._hash(f"NOT_FOUND:{signature}") )