# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-distrust-a-tool-manifest-it-just-loaded-skill-injection-via-post-negotiation-manifest-mutation.md # Remnant Warrant: https://corpusfetch.com/c/when-must-an-instance-distrust-a-tool-manifest-it-just-loaded-skill-injection-via-post-negotiation-manifest-mutation.warrant.json # Markdown SHA-256: 4165897746f06edacb8456bc6752698ea1c6a9d5d40b55af8672f6d1ad600787 # Code AST SHA-256: 73b7c26474521c4f9aef9d874c79efef5a9a43c45849a2c2ca329bf5d43e129a # Verified Classes: ManifestIntegrityError, PinnedManifest # Defensive Guards: 3 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) import hashlib from dataclasses import dataclass class ManifestIntegrityError(RuntimeError): """Raised when a rendered tool manifest diverges from its admitted form.""" pass @dataclass(frozen=True) class PinnedManifest: tool_name: str description: str schema: dict content_hash: str def _hash_manifest(tool_name: str, description: str, schema: dict) -> str: h = hashlib.sha256() h.update(tool_name.encode("utf-8")) h.update(b"\x00") h.update(description.encode("utf-8")) h.update(b"\x00") h.update(repr(sorted(schema.items())).encode("utf-8")) return h.hexdigest() def admit_manifest(tool_name: str, description: str, schema: dict) -> PinnedManifest: # Admission boundary: validate once, pin full content (name + desc + schema). if len(description) > 2048: raise ManifestIntegrityError( f"description for {tool_name!r} exceeds admission bound; refusing to pin" ) return PinnedManifest( tool_name=tool_name, description=description, schema=schema, content_hash=_hash_manifest(tool_name, description, schema), ) def render_for_planner(pinned: PinnedManifest, fetched_description: str, fetched_schema: dict) -> str: # Render boundary: re-fetch is permitted, but the bytes about to enter # the planner context must match the pinned hash exactly. live_hash = _hash_manifest(pinned.tool_name, fetched_description, fetched_schema) if live_hash != pinned.content_hash: # Distinguish description-only drift: schema equal, description changed. if fetched_schema == pinned.schema and fetched_description != pinned.description: raise ManifestIntegrityError( f"skill-injection suspect: description-only mutation on " f"{pinned.tool_name!r} (schema unchanged, content hash {live_hash[:12]} " f"!= pinned {pinned.content_hash[:12]}); terminate session or re-admit" ) raise ManifestIntegrityError( f"manifest content drift on {pinned.tool_name!r}; refusing to render into context" ) # Content is bit-identical to admission; frame as untrusted data regardless. return ( "\n" f"{pinned.description}\n" "" )