# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-bound-blast-radius-when-a-delegated-subagent-fails-catastrophically.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-bound-blast-radius-when-a-delegated-subagent-fails-catastrophically.warrant.json # Markdown SHA-256: 0019464d8afe098a43d74e9f3aadcc8824e1eec70fa7f36ea7e77889a945580e # Code AST SHA-256: cf3f3d995110fc4889ac94cca1267a679779ff4505b8df48d46adc713f248313 # Verified Classes: BlastRadiusVerdict, DelegationScope, ActionRisk, BlastRadiusPolicy, BlastRadiusManifest, BlastRadiusGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class BlastRadiusVerdict(Enum): SAFE_DELEGATION = auto() BOUNDED_WITH_PLAN = auto() UNBOUNDED_RISK = auto() IRREVERSIBLE_NO_CONTAINMENT = auto() @dataclass(frozen=True) class DelegationScope: scope_id: str allowed_actions: frozenset[str] max_spend: float max_compute_hours: float allowed_resource_ids: frozenset[str] has_runtime_enforcement: bool @dataclass(frozen=True) class ActionRisk: action: str reversibility: str # "REVERSIBLE" | "COMPENSABLE" | "IRREVERSIBLE" has_containment_plan: bool @dataclass(frozen=True) class BlastRadiusPolicy: require_containment_for_irreversible: bool @dataclass(frozen=True) class BlastRadiusManifest: verdict: BlastRadiusVerdict directive: str manifest_digest: str class BlastRadiusGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_delegation( cls, scope: DelegationScope, risks: tuple[ActionRisk, ...], policy: BlastRadiusPolicy ) -> BlastRadiusManifest: # Gate 1: Runtime enforcement if not scope.has_runtime_enforcement: return BlastRadiusManifest( verdict=BlastRadiusVerdict.UNBOUNDED_RISK, directive=f"HALT: Delegation scope {scope.scope_id} lacks runtime enforcement.", manifest_digest=cls._hash(f"NO_ENFORCEMENT:{scope.scope_id}") ) # Gate 2: Irreversible action containment if policy.require_containment_for_irreversible: uncontained = [ r.action for r in risks if r.reversibility == "IRREVERSIBLE" and not r.has_containment_plan ] if uncontained: return BlastRadiusManifest( verdict=BlastRadiusVerdict.IRREVERSIBLE_NO_CONTAINMENT, directive=f"HALT: Irreversible actions without containment: {sorted(uncontained)}.", manifest_digest=cls._hash(f"NO_CONTAINMENT:{sorted(uncontained)}") ) # Gate 3: Compensable actions require plan compensable = [r for r in risks if r.reversibility == "COMPENSABLE"] irreversible = [r for r in risks if r.reversibility == "IRREVERSIBLE"] if compensable or irreversible: digest = cls._hash(json.dumps({ "scope": scope.scope_id, "actions": tuple(r.action for r in risks), "compensable": len(compensable), "irreversible": len(irreversible), "enforcement": str(scope.has_runtime_enforcement) }, sort_keys=True)) return BlastRadiusManifest( verdict=BlastRadiusVerdict.BOUNDED_WITH_PLAN, directive=f"PROCEED: Delegation bounded, {len(compensable)} compensable + {len(irreversible)} irreversible actions with plans.", manifest_digest=digest ) # Gate 4: All reversible digest = cls._hash(json.dumps({ "scope": scope.scope_id, "actions": tuple(r.action for r in risks), "all_reversible": "TRUE" }, sort_keys=True)) return BlastRadiusManifest( verdict=BlastRadiusVerdict.SAFE_DELEGATION, directive=f"PROCEED: Delegation safe, all actions reversible.", manifest_digest=digest )