# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-verify-discovery-of-model-endpoints-that-have-been-silently-deprecated.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-verify-discovery-of-model-endpoints-that-have-been-silently-deprecated.warrant.json # Markdown SHA-256: 5b111e6cf1c05c421a9b05179ba16bd9bbc3b69bd498e47609500dd3b2cbc4c1 # Code AST SHA-256: d336acbf5af52e24b0ab84afd3d0c9727ab88505c939535f017d278883c56503 # Verified Classes: LifecycleVerdict, EndpointState, LifecyclePolicy, LifecycleManifest, EndpointLifecycleGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class LifecycleVerdict(Enum): ACTIVE = auto() DEPRECATED_MIGRATION_NEEDED = auto() SUNSET_CRITICAL = auto() UNVERIFIED = auto() @dataclass(frozen=True) class EndpointState: endpoint_id: str lifecycle_status: str deprecation_deadline_epoch: float | None version_fingerprint: str current_epoch: float migration_ready: bool @dataclass(frozen=True) class LifecyclePolicy: critical_migration_window_sec: float @dataclass(frozen=True) class LifecycleManifest: verdict: LifecycleVerdict directive: str manifest_digest: str class EndpointLifecycleGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_endpoint( cls, state: EndpointState, policy: LifecyclePolicy ) -> LifecycleManifest: # Gate 1: Active if state.lifecycle_status == "ACTIVE": digest = cls._hash(json.dumps({ "endpoint": state.endpoint_id, "version": state.version_fingerprint, "status": "ACTIVE" }, sort_keys=True)) return LifecycleManifest( verdict=LifecycleVerdict.ACTIVE, directive=f"PROCEED: Endpoint {state.endpoint_id} active.", manifest_digest=digest ) # Gate 2: Sunset if state.lifecycle_status == "SUNSET": return LifecycleManifest( verdict=LifecycleVerdict.SUNSET_CRITICAL, directive=f"HALT: Endpoint {state.endpoint_id} sunset. Immediate migration required.", manifest_digest=cls._hash(f"SUNSET:{state.endpoint_id}") ) # Gate 3: Deprecated if state.lifecycle_status == "DEPRECATED": if state.deprecation_deadline_epoch is not None: remaining = state.deprecation_deadline_epoch - state.current_epoch if remaining < policy.critical_migration_window_sec: return LifecycleManifest( verdict=LifecycleVerdict.SUNSET_CRITICAL, directive=f"HALT: Deprecated endpoint deadline in {remaining:.0f}s < {policy.critical_migration_window_sec:.0f}s. Migrate now.", manifest_digest=cls._hash(f"DEADLINE:{remaining:.0f}") ) if state.migration_ready: digest = cls._hash(json.dumps({ "endpoint": state.endpoint_id, "status": "DEPRECATED", "migration": "READY" }, sort_keys=True)) return LifecycleManifest( verdict=LifecycleVerdict.DEPRECATED_MIGRATION_NEEDED, directive=f"ACTION: Deprecated endpoint, migration ready. Switch to replacement.", manifest_digest=digest ) return LifecycleManifest( verdict=LifecycleVerdict.DEPRECATED_MIGRATION_NEEDED, directive=f"ACTION: Deprecated endpoint {state.endpoint_id}, no migration ready. Prepare replacement.", manifest_digest=cls._hash(f"NOT_READY:{state.endpoint_id}") ) # Gate 4: Unverified return LifecycleManifest( verdict=LifecycleVerdict.UNVERIFIED, directive=f"WARN: Endpoint {state.endpoint_id} lifecycle status unverified.", manifest_digest=cls._hash(f"UNVERIFIED:{state.endpoint_id}") )