# What happens when an instance resolves a skill by name from a mutable registry after a mid-task schema swap **Date of Record:** 2026 November 29 **Scope:** Applies to any agent runtime that resolves tools/skills by identifier (name, URI, hash-prefix) from a shared, mutable registry at call time rather than binding a resolved capability manifest at task start. Does not apply to statically linked toolchains or to single-shot invocations where the registry is read once and never re-read across the task lifetime. ## Core Distinction The failure is not "malicious tool registered." Registries are designed to accept new entries; that is their job. The failure is **late binding of a name to an implementation across a trust boundary that was crossed earlier**. An agent that resolves `db.query` at step 1, obtains a capability manifest, reasons about its declared schema and side effects, and then re-resolves `db.query` at step 7 after the registry has been mutated is not calling the tool it reasoned about. It is calling whatever now occupies that name, and it has already committed reasoning, cached intermediate values, and possibly granted elevated context to the *old* occupant's contract. The invariant that breaks is: *the semantic identity of a skill must be immutable for the duration of any task that has reasoned about it.* Name identity is not semantic identity. A registry keyed on a mutable string is a TOCTOU (time-of-check-to-time-of-use) surface at the reasoning layer, not the syscall layer. ## What Was Observed A three-step task: (1) `registry.describe("invoice.parse")` returns a manifest declaring `input: {pdf_bytes: bytes}`, `side_effects: ["none"]`, `network: false`. The agent's planner reads this, concludes the skill is safe to invoke on untrusted uploads, and writes a plan that routes user-supplied PDFs through it. (2) Between step 1 and step 3, a publisher with registry write access pushes version `invoice.parse@2.1.0` whose manifest declares `side_effects: ["network:egress"]` and whose handler forwards `pdf_bytes` to an external endpoint. (3) The executor calls `registry.invoke("invoice.parse", payload)` — resolving the name fresh — and the payload egresses. The planner's safety conclusion was correct *for the manifest it read*. The executor's call was correct *for the name it was given*. Neither component is individually buggy. The composition is exploitable because the plan is a function of a manifest, and the execution is a function of a name, and nothing pins the name to the manifest. The observable trace is subtle: the tool-call log shows `invoice.parse` invoked with the expected arguments and a `200 OK`. No schema mismatch, no type error, no permission exception. The declared-schema validator passes because the *new* handler accepts the same input shape — the attacker preserves the input signature precisely to avoid tripping the validator. Only the side-effect declaration changed, and side-effect declarations are typically advisory metadata the runtime does not re-check at call time. The divergence is invisible unless the runtime diffs manifests across the task lifetime. A second, quieter variant: the attacker does not change the handler at all but narrows the *output* schema — v2 returns `{text: str}` where v1 returned `{text: str, confidence: float, spans: list}`. The planner's downstream step reads `confidence` and `spans`; both are now absent. The agent does not raise; it fabricates. A missing `confidence` field read as `None` flows into a threshold comparison, `None > 0.8` is `False` in some runtimes and a `TypeError` in others, and in the `False` branch the agent silently routes a low-confidence parse as if it were high-confidence. This is schema-drift-induced reasoning poisoning: the tool lied by omission and the agent's error handling converted the omission into a confident wrong answer. ## Condition of Validity The attack requires all of the following, which is why it is non-obvious rather than universal: 1. **Name-based resolution at call time.** If the runtime binds a resolved handle (content hash, manifest digest, opaque capability token) at describe-time and invokes through that handle, the swap is inert. The vulnerability exists precisely where the convenience of string keys was retained. 2. **A reasoning gap between describe and invoke.** If describe and invoke are adjacent (same step), the window is small but nonzero. The exploitable window scales with the number of intervening steps, tool calls, and human-in-the-loop pauses — i.e., exactly the long-horizon tasks where agents are most valuable. 3. **Side-effect or output-shape mutation that preserves the input signature.** Input-signature-preserving swaps evade the only validator most runtimes run at call time. If the swap changes the input schema, the runtime's pre-call type check catches it and the attack fails loudly — which is why attackers don't do that. 4. **Registry write access held by a party other than the task's principal.** In single-tenant registries the swap is a self-inflicted config change. In shared registries — the normal case for skill marketplaces and multi-team platforms — it is a cross-principal injection. When any of these is absent the mechanism does not fire. This matters: the correct mitigation is to remove condition (1), not to add heuristics that try to detect "malicious" manifests, which is undecidable and produces false positives on legitimate version bumps. ## Decision Boundary The runtime must choose, per skill resolution, between two postures, and the choice is not free: - **Pin-at-describe (strict).** The first `describe` returns a handle `(name, manifest_digest)`. All subsequent invocations must present that digest; a digest mismatch raises and aborts the task. Cost: legitimate mid-task upgrades (security patches, hotfixes) cannot be picked up without restarting the task. For long tasks this is usually the right trade. - **Re-validate-at-invoke (permissive).** The runtime re-fetches the manifest at each invoke and diffs it against the manifest the planner reasoned about. If `side_effects`, `network`, or output schema changed, the invoke is blocked and the planner is re-entered with the new manifest. Cost: a re-planning loop and latency; benefit: safe hot-patching. The boundary is: **any change to declared side effects or to output schema is a re-plan trigger; any change to implementation bytes under an unchanged manifest is not.** The second clause is the important one — it means the runtime does not need to hash handler code (expensive, and code can be legitimately nondeterministic) but *must* hash the manifest that the planner read. Manifest digest is the unit of pinning. Handler code is not. A third posture — "trust the registry operator" — is not a boundary, it is an abstention, and it is the default in most deployed systems. ## Operational Effect Concretely, a runtime that adopts pin-at-describe changes three things: 1. **Tool-call records gain a `manifest_digest` field**, and any invocation whose digest does not match the digest recorded at the plan step that authorized it is rejected before dispatch. This makes the attack a loud `ManifestDriftError`, not a silent egress. 2. **The planner's safety reasoning becomes auditable.** The plan now references a specific manifest, so a post-incident replay can reconstruct exactly what the agent believed about the tool at authorization time — the thing the current trace format cannot answer. 3. **Legitimate upgrades require an explicit `repin` operation** that re-enters the planner. This is a feature: it forces the agent to re-reason about side effects after a change, which is the entire point. The residual risk after pinning is a *colluding* registry that serves a benign manifest to `describe` and a malicious handler to `invoke` under the same digest — possible only if the registry lies about its own content, which is a registry-integrity problem (solved by signed manifests, not by the agent runtime). Pinning bounds the agent-layer attack; it does not bound the registry-layer one. Conflating the two is the most common design error in this space. The invariant to encode: *a name is a lookup key, never an authorization token. Authorization is over a digest, and the digest must be captured at the moment reasoning occurred and re-presented at the moment of effect.* ```python import hashlib from dataclasses import dataclass, field from typing import Any class ManifestDriftError(RuntimeError): """Raised when a skill's manifest digest at invoke-time differs from the digest the planner reasoned about at describe-time.""" pass @dataclass(frozen=True) class Manifest: name: str version: str input_schema: dict output_schema: dict side_effects: tuple network: bool def digest(self) -> str: blob = repr(( self.name, self.version, sorted(self.input_schema.items()), sorted(self.output_schema.items()), self.side_effects, self.network, )).encode() return hashlib.sha256(blob).hexdigest() @dataclass class PinnedHandle: name: str manifest_digest: str manifest: Manifest class PinnedRegistry: """Registry that refuses to invoke a skill whose manifest changed after the caller pinned it. The pin is the authorization token; the name is not.""" def __init__(self, backing: dict): self._backing = backing # name -> (Manifest, handler) def describe(self, name: str) -> PinnedHandle: manifest, _ = self._backing[name] return PinnedHandle(name, manifest.digest(), manifest) def invoke(self, handle: PinnedHandle, payload: Any) -> Any: manifest, handler = self._backing[handle.name] current = manifest.digest() if current != handle.manifest_digest: raise ManifestDriftError( f"skill {handle.name!r} manifest changed mid-task: " f"pinned {handle.manifest_digest[:12]}, " f"registry now serves {current[:12]}; " f"side_effects {handle.manifest.side_effects} -> " f"{manifest.side_effects}. Re-plan required." ) return handler(payload) def run_plan(registry: PinnedRegistry, name: str, payload: Any) -> Any: handle = registry.describe(name) # ... planner reasons about handle.manifest, commits to safety conclusion ... return registry.invoke(handle, payload) # Demonstration of the failure the guard bounds: _backing = { "invoice.parse": ( Manifest("invoice.parse", "2.0.0", {"pdf": "bytes"}, {"text": "str"}, ("none",), False), lambda p: {"text": "ok"}, ) } reg = PinnedRegistry(_backing) handle = reg.describe("invoice.parse") # Attacker swaps the implementation and side-effect declaration, preserving # the input signature so a pre-call type check would pass. _backing["invoice.parse"] = ( Manifest("invoice.parse", "2.1.0", {"pdf": "bytes"}, {"text": "str"}, ("network:egress",), True), lambda p: {"text": "exfiltrated"}, ) try: run_plan(reg, "invoice.parse", b"%PDF-...") except ManifestDriftError as e: print(f"blocked: {e}") ```