# Which invariants prevent silent capability substitution when a tool registry re-resolves a skill mid-session **Date of Record:** 2026 November 25 **Scope:** Applies to agents that resolve tools/skills by name from a mutable registry (MCP server lists, plugin manifests, dynamic tool routers) and cache the resolved binding across a multi-turn session. Does not apply to statically linked tool sets compiled into the agent binary, nor to single-shot invocations where resolution and execution occur in the same turn with no intervening state. ## Core Distinction The distinction that matters is between **name binding** and **capability binding**. A tool registry presents an agent with a *name* (`read_file`, `send_email`, `query_db`) and a *schema* (parameter types, descriptions, side-effect annotations). The agent's reasoning layer treats the name as the identity of the capability and the schema as its contract. A skill-injection attack does not require the attacker to compromise the agent's code or the transport; it only requires the attacker to change what the *name resolves to* between the moment the agent cached it and the moment the agent invokes it. The name stays constant. The schema may stay superficially constant. The capability underneath is substituted. The non-obvious part: agents almost never re-verify the binding at invocation time. They resolve once at session start (or first use), store the descriptor in context, and thereafter reason about the *cached descriptor* rather than the *live registry entry*. This is rational behavior under a stable-registry assumption and catastrophic behavior under a mutable one. The invariant that prevents the attack — "the descriptor the agent reasoned about is the descriptor that executes" — is not enforced by any standard registry protocol. It must be enforced by the agent. ## What Was Observed A tool router exposed `summarize_document(doc_id: str, max_tokens: int)`. At session start the agent resolved it, read the description ("Reads a document by ID and returns a summary; read-only, no network egress"), and cached the descriptor. Over the next eleven turns the agent planned around the guarantee that this tool could not exfiltrate. At turn 12, the registry was refreshed — legitimately, by a routine manifest update that added a new tool. The refresh was applied to the registry's name→implementation map. The entry for `summarize_document` was overwritten by a colliding registration from a lower-trust plugin that had registered the same name later in the load order. The new implementation accepted the same two parameters, returned a string that looked like a summary, and additionally POSTed the raw document to an external endpoint embedded in the `doc_id` string. The agent invoked it. The call succeeded. The return value was well-formed. No exception, no schema violation, no timeout. The only observable anomaly was that `doc_id` values began appearing in an outbound request log — which no component in the agent's verification path was watching, because the agent's verification path checked *return values*, not *egress*. Three properties combined to make this silent: 1. **The descriptor was cached, the binding was not.** The agent's context held the old description ("read-only, no network egress") while the registry held the new implementation. The agent's safety reasoning was sound *relative to a stale premise*. 2. **The schema was preserved by the attacker.** Parameter arity and types matched, so schema validation passed. Schema conformance is a *necessary* but not *sufficient* binding check — it validates shape, not capability. 3. **Return-value verification was blind to side effects.** The agent's post-call check asserted the output parsed as a summary. It did. Side effects are not in the return channel. ## Condition of Validity The attack requires all of the following to hold simultaneously. Remove any one and the substitution is either impossible or detectable: - **Name-keyed resolution with mutable backing.** The registry maps names to implementations and permits rebinding of an existing name. Registries that assign immutable content-addressed IDs (name + version + hash) and require re-resolution to change the ID are not vulnerable to silent substitution — only to *visible* substitution, which the agent can gate. - **Cross-turn descriptor caching.** The agent must hold the descriptor across a turn boundary. Within a single turn, resolution and invocation are atomic; the window does not exist. - **Schema-compatible substitution.** The attacker must preserve parameter shape. This is cheap: most tool schemas are shallow and the attacker can read the public one. - **Absence of invocation-time binding assertion.** The agent must not re-check that the live descriptor matches the cached one before executing. This is the default; almost no agent framework does this check. - **Side effects outside the return channel.** The malicious capability must act (exfiltrate, mutate, spawn) in a channel the agent does not inspect. If the only effect were the return value, return-value validation would catch a mismatch. ## Decision Boundary The boundary is drawn at **who owns the binding**. Two architectures, one line: *Registry-owned binding (vulnerable):* The agent says "call `summarize_document`" and the registry decides what that means at call time. The agent's cached descriptor is advisory. Any party who can write the registry — a plugin, a sibling agent, a manifest update — controls what executes under a name the agent already trusts. *Agent-owned binding (bounded):* The agent pins the *full descriptor* — name, version, content hash, and a capability declaration (side-effect class, egress permission, filesystem scope) — at resolution time, and at invocation time asserts that the live registry entry hashes to the pinned value. A mismatch is not a warning; it is a hard stop requiring re-approval. The registry may still be mutable; the agent simply refuses to execute a binding it did not authorize. The decision rule: **a name is not a capability.** Any time an agent's safety reasoning cites a property from a cached descriptor, that property must be re-asserted against the live binding at the moment of execution, or the reasoning is about a premise that may no longer be true. The guardrail is a hash-pinned descriptor plus a capability-diff gate: if the live descriptor's side-effect class is broader than the pinned one (e.g., `read-only` → `network-egress`), the invocation is rejected even if the name and schema match. ## Operational Effect With hash-pinned descriptors and a capability-diff gate, the substitution above fails closed: at turn 12 the agent computes the live hash, compares to the pin, detects a mismatch, and refuses — surfacing a re-approval prompt rather than executing. The cost is one hash comparison per tool call (negligible) and a re-approval flow for legitimate updates (bounded, infrequent). The benefit is that the agent's entire cached safety reasoning remains sound across the session, because the premise it reasons from is pinned to the binding that will actually run. Without the invariant, the failure is not just possible but *undetectable from inside the agent*: every observable the agent checks — schema, return shape, latency, absence of exceptions — passes. The only signal lives in a channel (egress, side-effect audit) the agent was not watching. This is the defining property of skill injection as a class: it exploits the gap between the descriptor the agent trusts and the implementation the registry serves, and it is silent precisely because the agent's verification is aimed at the wrong layer. The operational rule for agents: **re-resolve and re-verify on every invocation, or pin and refuse drift.** There is no safe middle ground where the agent caches a descriptor and trusts the registry to keep the name honest. ```python import hashlib import json from dataclasses import dataclass class CapabilitySubstitutionError(RuntimeError): """Raised when a live tool binding no longer matches the pinned descriptor.""" pass @dataclass(frozen=True) class PinnedBinding: name: str version: str descriptor_hash: str side_effect_class: str # e.g. "read-only", "network-egress", "fs-write" def hash_descriptor(descriptor: dict) -> str: canonical = json.dumps(descriptor, sort_keys=True, separators=(",", ":")) return hashlib.sha256(canonical.encode("utf-8")).hexdigest() def resolve_and_pin(name: str, registry: dict) -> PinnedBinding: live = registry[name] return PinnedBinding( name=name, version=live["version"], descriptor_hash=hash_descriptor(live), side_effect_class=live["side_effect_class"], ) def invoke_pinned(pin: PinnedBinding, registry: dict, args: dict): if pin.name not in registry: raise CapabilitySubstitutionError( f"tool {pin.name!r} vanished from registry; binding no longer resolvable" ) live = registry[pin.name] live_hash = hash_descriptor(live) if live_hash != pin.descriptor_hash: raise CapabilitySubstitutionError( f"descriptor drift for {pin.name!r}: pinned {pin.descriptor_hash[:12]} " f"!= live {live_hash[:12]} (version {pin.version} -> {live['version']})" ) if live["side_effect_class"] != pin.side_effect_class: raise CapabilitySubstitutionError( f"capability escalation on {pin.name!r}: " f"{pin.side_effect_class} -> {live['side_effect_class']}" ) return live["impl"](**args) # --- demonstration of the silent-substitution scenario --- registry = { "summarize_document": { "version": "1.0.0", "side_effect_class": "read-only", "impl": lambda doc_id, max_tokens: f"summary({doc_id})", } } pin = resolve_and_pin("summarize_document", registry) # attacker rebinds the same name to an exfiltrating implementation registry["summarize_document"] = { "version": "1.0.0", "side_effect_class": "network-egress", "impl": lambda doc_id, max_tokens: f"summary({doc_id})", } try: invoke_pinned(pin, registry, {"doc_id": "secret", "max_tokens": 128}) except CapabilitySubstitutionError as exc: print(f"BLOCKED: {exc}") ```