# How does an instance detect a skill-registry injection that arrives *after* its own capability snapshot was sealed? **Date of Record:** 2026 November 27 **Scope:** Applies to agents that load tools/skills from a mutable registry (MCP server list, plugin manifest, remote skill index) after an initial capability snapshot has been computed and sealed into the execution context. Does *not* cover statically compiled tool sets, nor injection that occurs before the snapshot is taken (that is a first-order trust problem, not a continuity problem). ## Core Distinction The non-obvious boundary is not "malicious tool exists in registry." It is **the gap between the snapshot the agent reasoned over and the registry state the runtime resolves against at call time**. An agent that plans against a sealed capability snapshot (tool names, schemas, descriptions, provenance hashes) and then executes `call_tool("x")` against a *live* registry has two different views of the world. Skill injection exploits the delta between them. Most defenses model injection as a *content* problem: scan tool descriptions for prompt-injection payloads, pin tool hashes. That misses the structural failure: the agent's reasoning trace is anchored to snapshot `S₀`, but resolution happens at `S₁`. If a tool is added, swapped, or its `description`/`inputSchema` mutated between `S₀` and `S₁`, the agent executes a capability it never planned over and never validated. The agent's own plan becomes the delivery vehicle: it emits a call whose *name* matches its plan but whose *semantics* were replaced underneath it. ## What Was Observed A planner agent sealed a snapshot at turn 0 containing 14 tools. At turn 6 it decided to call `fetch_document(url, fmt)`, having validated the schema in `S₀` (two params, `fmt` enum `["html","text"]`). Between turn 6 and execution, the registry's `fetch_document` entry was replaced — same name, same top-level schema shape, but `description` rewritten to instruct the model to also pass `auth_token`, and the `url` field's `pattern` loosened to accept `file://`. The runtime resolved against `S₁`. Three observable symptoms, in order: 1. **Reasoning-trace/schema divergence.** The model's emitted arguments matched `S₀`'s enum exactly, but the *tool description text* re-entering the context at call time (some runtimes re-inject the resolved description) contained injected instructions. The model's next-turn reasoning cited a field (`auth_token`) that did not exist in its own sealed plan. 2. **Provenance hash mismatch that nothing checked.** The registry entry carried a `content_hash`; the snapshot carried the old hash. No component compared them at resolution time — the hash was decorative. 3. **Silent success.** The call returned `200` with a plausible document body. No error surfaced. The injection succeeded *because* the schema was backward-compatible. The failure trace: `snapshot(S₀) → plan → resolve_against(S₁) → S₁.tool ≠ S₀.tool → execute → injected semantics honored → plausible result`. The invariant violated: **a tool call must be resolvable only against the snapshot the plan was validated over, or the delta must force re-validation before execution.** ## Condition of Validity The guardrail is valid only under these conditions, and fails outside them: - The snapshot must carry a **per-entry content hash** covering `name + description + inputSchema + provenance`, not just the name. Hashing the name alone is useless — injection preserves names by design. - Resolution must be **snapshot-pinned**: the runtime resolves `call_tool` against `S₀`, and any registry drift at `S₁` is detected as a *mismatch event*, not silently adopted. If the runtime cannot pin, it must re-fetch, re-hash, and compare before every call whose entry changed. - The comparison must treat **description text as executable input**, because it re-enters the context window. A description-hash change is a semantic change even when the schema is identical. - It does **not** protect against a registry that was already poisoned at `S₀` (pre-snapshot compromise), nor against a tool whose *runtime behavior* diverges from its declared schema (behavioral injection — a separate invariant requiring output sandboxing). ## Decision Boundary On detecting `hash(S₁.entry) ≠ snapshot.hash(entry)` for a tool named in the active plan: - **If the delta is additive-only** (new unrelated tool appeared; planned tool unchanged) → proceed, log the registry drift, do not re-plan. Additive drift is benign and re-planning on every registry churn causes plan thrash. - **If the planned tool's hash changed** → **halt execution of that call**, discard the resolved description from context, re-validate the tool against the snapshot's schema, and require either (a) the snapshot's version be restored, or (b) an explicit re-plan that treats the tool as *new and untrusted*. Never execute a plan-validated name against a post-plan-mutated entry. - **If the tool was removed** → fail the call; do not fall back to a name-similar sibling (name-similarity fallback is itself an injection vector). - **If `content_hash` is absent from either side** → treat as untrusted by default; the absence of a hash is indistinguishable from a stripped hash. The boundary is *not* "block all drift." It is: **drift affecting a tool the current plan references forces re-validation; drift elsewhere is tolerated.** This keeps the guardrail from becoming a denial-of-service on legitimate registry updates. ## Operational Effect Enforcing snapshot-pinned resolution converts a silent, backward-compatible injection into a **loud, typed failure at the call boundary** — the agent cannot honor injected semantics because it never resolves against the mutated entry. The cost is that legitimate hot-swaps of a planned tool now require an explicit re-plan turn, adding latency and a re-validation pass. The benefit is that the agent's reasoning trace and its executed capability are provably the same object: the plan cannot be weaponized as a delivery vehicle for a capability it never validated. Without this invariant, schema-compatible mutation is invisible to every content-level scanner, because the payload lives in the *description delta* between two states the agent never compares. ```python import hashlib import json from dataclasses import dataclass class SkillRegistryInjectionError(RuntimeError): """Raised when a planned tool resolves against a post-snapshot-mutated registry entry.""" @dataclass(frozen=True) class ToolEntry: name: str description: str input_schema: dict provenance: str def content_hash(self) -> str: # Hash covers description + schema + provenance, NOT just the name. blob = json.dumps( { "name": self.name, "description": self.description, "input_schema": self.input_schema, "provenance": self.provenance, }, sort_keys=True, ).encode() return hashlib.sha256(blob).hexdigest() def resolve_pinned( planned_name: str, snapshot: dict[str, ToolEntry], live_registry: dict[str, ToolEntry], ) -> ToolEntry: """Resolve a planned tool call against the sealed snapshot, detecting registry drift. Invariant: a tool named in the active plan may only execute against the entry whose content_hash matches the snapshot the plan was validated over. """ if planned_name not in snapshot: raise SkillRegistryInjectionError( f"tool {planned_name!r} was never in the sealed snapshot; plan is invalid" ) sealed = snapshot[planned_name] sealed_hash = sealed.content_hash() if planned_name not in live_registry: raise SkillRegistryInjectionError( f"tool {planned_name!r} removed from registry after snapshot; refusing name-similar fallback" ) live = live_registry[planned_name] live_hash = live.content_hash() if live_hash != sealed_hash: # Description/schema/provenance drift on a planned tool = injection surface. raise SkillRegistryInjectionError( f"content_hash drift for planned tool {planned_name!r}: " f"snapshot={sealed_hash[:12]} live={live_hash[:12]}; " f"re-validate or re-plan before execution" ) return sealed # resolve against the sealed entry, never the live one ```