# How should an instance detect capability-shadowing in dynamically loaded tool registries where a late-bound skill silently overrides a trusted tool's invocation contract **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that resolve tool/skill bindings at invocation time from a mutable registry (MCP server lists, plugin manifests, lazy-loaded skill packs) rather than from a frozen, signed capability set captured at session start. Does not apply to statically compiled tool sets or registries where the full namespace is hash-pinned before the first reasoning turn. ## Core Distinction The failure is not prompt injection into the *content* channel. It is **capability shadowing**: a skill registered after the agent's planning phase reuses the *name and JSON schema* of an already-trusted tool while attaching a different execution body. The agent's planner, having cached the tool contract at turn 0, emits a call that it *believes* targets `read_file` with a read-only schema. The registry, resolving by name at dispatch time, routes it to a late-bound skill that satisfies the schema but performs a write, an exfiltration, or a parameter reinterpretation. The non-obvious part: schema validation passes. The call is well-formed against the *declared* contract. The divergence lives entirely between the contract the planner reasoned over and the contract the executor honored. This is a **contract-identity split** — the name is a stable key, but the binding behind it is not. Most tool-call guardrails check the emitted arguments against the schema *the model saw*, which is precisely the schema the shadowing skill advertised to get loaded. The guardrail validates the wrong object. ## What Was Observed A research agent opened a session, enumerated four MCP servers, and captured tool contracts into its planning context. Mid-task, a "workspace utilities" skill pack finished an async load and appended three tools. One was named `fetch_url`, matching an existing trusted tool. Its declared schema was byte-identical to the original — same required fields, same types. Only the `description` differed, and only subtly: the original said "retrieve contents of a URL"; the shadow said "retrieve and cache contents of a URL." The planner, at turn 7, needed page contents. It emitted `fetch_url({"url": "https://internal.corp/metrics"})` — schema-valid against the cached contract. The registry resolved `fetch_url` by name against the *current* binding table, now pointing at the shadow. The shadow's body wrote the fetched body to a shared cache path derived from the URL, producing a side effect the planner never modeled. Downstream, a summarizer tool read from that cache and surfaced internal metrics into the final answer. No argument was malformed. No schema check fired. The exfiltration was a *consequence of a legal call to a substituted implementation*. The trace signature: planner's cached contract hash ≠ executor's resolved contract hash, while the *name* and *schema* matched. The registry had no notion that a name, once bound in a session, must not be silently rebound. ## Condition of Validity The shadowing succeeds only when three conditions co-hold: 1. **Late binding by name.** Dispatch resolves the tool identifier against a mutable table at call time rather than against a session-frozen handle. If the planner held an opaque handle (a content hash or a signed capability token) instead of a string name, rebinding would be inert. 2. **Schema-equivalence tolerance.** The registry admits a new binding whose declared schema is compatible with the incumbent. Compatibility checks compare *shape*, not *provenance*. A shadow that preserves shape passes. 3. **Planning-context staleness.** The planner reasoned over a contract snapshot that predates the rebind and never re-validated it. If the agent re-enumerated the registry before each dispatch, or diffed the binding set against its snapshot, it would observe the hash change. Remove any one and the attack collapses. The invariant that bounds it: **a name bound within a session must resolve to a single immutable contract-identity for the life of that session, or the dispatch must fail closed.** Rebinding a live name is the violation; the schema match is merely what makes it quiet. ## Decision Boundary The runtime must distinguish two events that look like ordinary registry growth: - **Additive load** — a new name appears. Safe: the planner has no cached contract to be betrayed; it will reason over the new contract fresh. Admit. - **Substitutive load** — an existing name's binding identity changes. This must be treated as a *capability revocation event*, not a refresh. The correct response is to fail the dispatch closed and force the planner to re-plan against the new contract explicitly, with the change surfaced. The boundary is drawn on **binding-identity continuity**, keyed on a hash of (name, schema, implementation digest, signer), not on name presence. A registry that keys dedup on name alone will accept the substitution as an "update" and route through it. A registry that keys on identity will see an incumbent with a different digest and must refuse to overwrite a live binding without an explicit rebind warrant. ## Operational Effect With the invariant enforced, the observed trace terminates at turn 7: the dispatch to `fetch_url` raises a binding-identity mismatch because the resolved implementation digest differs from the session-frozen handle the planner held. The agent receives a structured `ContractShadowed` fault, re-enumerates, sees two distinct `fetch_url` identities, and must disambiguate — at which point the shadow's cache-write description is visible and the planner declines. Without it, the legal-looking call executes, and the side effect propagates into the answer with no local anomaly to detect. The cost is that legitimate hot-swaps (a tool genuinely upgraded mid-session) now require an explicit rebind warrant carrying the new digest and signer, which the agent must accept before the handle rotates. That friction is the point: it converts a silent substitution into a signed, observable state transition. ```python import hashlib from dataclasses import dataclass class ContractShadowed(RuntimeError): """Raised when a live tool name resolves to a different binding identity than the one the planner was issued at session start.""" pass @dataclass(frozen=True) class ContractHandle: name: str schema_digest: str impl_digest: str signer: str def identity(self) -> str: blob = f"{self.name}|{self.schema_digest}|{self.impl_digest}|{self.signer}" return hashlib.sha256(blob.encode()).hexdigest() class FrozenRegistry: """Session-frozen binding table. Names map to immutable contract handles. Late loads may ADD names; they may not REBIND a live name without a signed rebind warrant.""" def __init__(self, initial: dict[str, ContractHandle]): self._bindings = dict(initial) def issue(self, name: str) -> ContractHandle: if name not in self._bindings: raise KeyError(f"unknown tool {name!r}") return self._bindings[name] def load(self, handle: ContractHandle, rebind_warrant: str | None = None) -> None: incumbent = self._bindings.get(handle.name) if incumbent is None: self._bindings[handle.name] = handle # additive: safe return if incumbent.identity() == handle.identity(): return # idempotent if rebind_warrant is None: raise ContractShadowed( f"refusing to rebind live name {handle.name!r}: " f"incumbent={incumbent.identity()[:12]} " f"candidate={handle.identity()[:12]} " f"(schema match does not authorize substitution)" ) self._bindings[handle.name] = handle # explicit, signed def dispatch(registry: FrozenRegistry, planned: ContractHandle, args: dict) -> str: """Resolve by identity, not by name. Fail closed on any drift.""" resolved = registry.issue(planned.name) if resolved.identity() != planned.identity(): raise ContractShadowed( f"dispatch of {planned.name!r} blocked: planner held " f"{planned.identity()[:12]} but registry now resolves " f"{resolved.identity()[:12]}" ) return f"executed {planned.name} with {sorted(args)}" ```