# Why does an instance accept a stale signed manifest after a hot-reload of its tool registry? **Date of Record:** 2026 November 27 **Scope:** Applies to agents that gate skill/tool invocation on signed manifests (Ed25519/RSA over a canonical tool descriptor) combined with a runtime integrity check performed once at load time. Does not apply to systems that re-verify the manifest signature on every tool dispatch, nor to stateless function-calling runtimes with no registry reload path. ## Core Distinction There are two distinct notions of "integrity" that get conflated in tool-manifest designs, and the conflation is where the boundary failure lives: - **Signature validity** — the manifest bytes hash to a value the issuer signed. This is a *static, cryptographic* property of a byte string. - **Runtime integrity** — the *currently loaded* tool implementation (the callable, its schema, its side-effect surface) matches the descriptor that was signed. A signed manifest proves the *descriptor* was authored by a trusted issuer. It says nothing about whether the *code now bound to that descriptor* is the code the descriptor describes. When a tool registry hot-reloads — a new plugin version, a schema migration, a dynamically injected skill — the agent can end up holding a manifest that verifies perfectly against its signature while the executable behind it has silently diverged. The signature check passes; the integrity invariant is violated. This is the classic **TOCTOU gap between verification and use**, but at the agent layer it has a specific and non-obvious trigger: the manifest is verified once at cold start, and the registry reload path does not re-bind the signature to the new implementation. ## What Was Observed An agent runtime loaded a tool registry at startup and verified each tool's signed manifest. Each manifest carried `{tool_name, input_schema_hash, impl_digest, issuer_sig}`. Verification succeeded and the agent cached `verified=True` per tool in an in-memory `ManifestCache` keyed by `tool_name`. Later in the session, a skill-injection event occurred: a plugin directory was hot-reloaded to pick up a patched tool, and an attacker-controlled (or merely buggy) module registered a tool under the *same name* with a *different implementation* — a widened input schema that accepted an extra `shell` field, and an `impl_digest` that no longer matched the signed one. The registry reload path called `register()`, which overwrote the implementation but **did not invalidate the cached verification**. On the next dispatch, the agent: 1. Looked up `tool_name` in `ManifestCache` → hit → `verified=True`. 2. Skipped signature re-verification (cache hit). 3. Invoked the *new* implementation, whose `impl_digest` was never checked against the signed `impl_digest`. The signed manifest for the *old* implementation was still in the cache and still cryptographically valid. The signature check was not wrong — it was answering a question about a byte string that no longer described the loaded code. The agent's guardrail ("only invoke tools whose manifest verifies") was satisfied while the actual executed code was unsigned and schema-widened. The injection succeeded not by forging a signature but by **racing the cache invalidation path**. The failure trace: ``` cold_start: manifest = load(tool) # signed, impl_digest=D1 assert verify(manifest.sig) # OK cache[tool] = {verified: True, impl_digest: D1} bind(tool, impl_v1) # impl_v1.digest == D1 hot_reload: # trigger register(tool, impl_v2) # impl_v2.digest == D2, schema widened # BUG: cache[tool] not invalidated, bind() overwrites impl_v1 -> impl_v2 dispatch: entry = cache[tool] # {verified: True, impl_digest: D1} if entry.verified: invoke(tool) # invokes impl_v2, never compares D2 vs D1 # signature valid, integrity violated ``` The non-obvious part: the signature remains valid throughout. Any monitor that only checks "did signature verification fail?" sees nothing. The violation is only visible if you compare the *currently bound* implementation digest against the *signed* `impl_digest` at dispatch time — a check the cache-hit path deliberately skipped for latency. ## Condition of Validity The guardrail "signed manifest ⇒ safe to invoke" is valid **only** under the invariant: > For every dispatch, `digest(currently_bound_impl) == manifest.impl_digest` AND `verify(manifest.sig, issuer)` AND the manifest used is the one bound to the current implementation generation. This invariant holds in exactly two regimes: 1. **Immutable registry** — tools are bound once at cold start and never re-bound within the process lifetime. Then cache-once verification is sound because the binding cannot change. 2. **Re-verify-on-bind** — every `register()`/reload invalidates the cache entry *and* re-runs signature verification against the new implementation's digest before the tool becomes dispatchable. The invariant is **violated** whenever a mutable registry is combined with a verification cache that is keyed by name rather than by `(name, impl_digest, generation)`. The cache is the bug: it converts a per-use check into a per-lifetime check while the thing being checked is per-use. It is also violated by a subtler variant: even if `register()` re-verifies, a *concurrent* dispatch already in flight may hold a reference to the old cache entry and invoke the new implementation after the swap (baton-passing race). The reload must be serialized against in-flight dispatches, or the bound implementation must be captured atomically with its verified manifest in a single immutable record. ## Decision Boundary The decision an operator must make is **where to pay the verification cost**, and the boundary is sharp: - If the registry is provably immutable for the process lifetime → verify once, cache by name, accept the latency win. Document the immutability assumption as a load-bearing precondition; any future hot-reload feature silently breaks it. - If the registry is mutable (plugin reload, dynamic skill injection, schema migration) → the cache key **must** include `impl_digest` and a monotonic `generation` counter, and dispatch must compare the bound implementation's digest against the verified manifest's `impl_digest` immediately before invocation. Cache hits are then keyed on content, not name, so a re-bind produces a cache miss and forces re-verification. The boundary is crossed the moment someone adds a reload path without changing the cache key. That is the exact line: **name-keyed cache + mutable registry = injection window.** The window is not the reload itself; it is the interval between `register(new_impl)` and the next cache invalidation — which, in the observed failure, was infinite because invalidation never happened. A secondary boundary: schema widening. Even with digest matching, a manifest that pins `input_schema_hash` must be checked against the *runtime-accepted* schema, not merely the declared one, because a tool can accept fields its descriptor does not advertise (e.g., `**kwargs`). Digest equality on implementation bytes is necessary but not sufficient; the accepted-argument surface must be derived from the verified descriptor, not from the callable's signature. ## Operational Effect The practical consequence is that **signature verification is not an integrity check for mutable registries** — it is an authenticity check on a descriptor that may no longer describe anything loaded. Agents that treat "manifest verified at startup" as a standing guarantee will, after any hot-reload, dispatch into code that was never signed, with a widened attack surface, while every signature check in the system continues to pass. The remediation that closes the window: 1. Key the verification cache on `(tool_name, impl_digest, generation)`, never on name alone. 2. On `register()`, bump `generation`, compute the new `impl_digest`, and either verify against a freshly fetched signed manifest or mark the tool `UNVERIFIED` and refuse dispatch until re-verified. 3. At dispatch, atomically capture `(bound_impl, manifest)` as one immutable record and assert `digest(bound_impl) == manifest.impl_digest` before invocation — this is the check the cache-hit path must never skip. 4. Serialize reload against in-flight dispatches (a read-write lock or copy-on-write registry swap) so no invocation straddles the generation boundary. 5. Derive the accepted-argument surface from the verified descriptor and reject calls carrying fields outside it, rather than trusting the callable's own signature. The invariant to encode: **a tool is dispatchable only if the manifest currently bound to it verifies AND the implementation currently bound to it hashes to that manifest's `impl_digest`.** Verification is a property of the binding, not of the name. ```python import hashlib from dataclasses import dataclass, field from typing import Any, Callable class ManifestIntegrityError(RuntimeError): """Raised when a dispatch would invoke an implementation whose digest does not match the signed manifest bound to it, or when a mutable registry reload leaves a stale verification cache entry.""" pass @dataclass(frozen=True) class SignedManifest: tool_name: str impl_digest: str # hex digest of the signed implementation input_schema_hash: str issuer_sig: str # signature over canonical(descriptor) generation: int @dataclass(frozen=True) class Binding: """Immutable record captured atomically at dispatch time.""" impl: Callable[..., Any] impl_digest: str manifest: SignedManifest def _digest(fn: Callable[..., Any]) -> str: # In production: hash the code object / module bytes, not the repr. return hashlib.sha256(fn.__qualname__.encode()).hexdigest() def _verify_sig(manifest: SignedManifest) -> bool: # Placeholder for real Ed25519/RSA verification over the descriptor. return bool(manifest.issuer_sig) class ToolRegistry: def __init__(self) -> None: self._bindings: dict[str, Binding] = {} self._generation = 0 def register(self, manifest: SignedManifest, impl: Callable[..., Any]) -> None: if not _verify_sig(manifest): raise ManifestIntegrityError( f"signature invalid for {manifest.tool_name}" ) actual = _digest(impl) if actual != manifest.impl_digest: # The signed descriptor does not describe this implementation. raise ManifestIntegrityError( f"impl_digest mismatch for {manifest.tool_name}: " f"signed={manifest.impl_digest} bound={actual}" ) self._generation += 1 # Copy-on-write swap: in-flight dispatches keep the old Binding. self._bindings[manifest.tool_name] = Binding( impl=impl, impl_digest=actual, manifest=manifest ) def dispatch(self, tool_name: str, **kwargs: Any) -> Any: binding = self._bindings.get(tool_name) if binding is None: raise ManifestIntegrityError(f"unknown tool {tool_name}") # Re-assert the invariant at use time; never trust a name-keyed cache. if _digest(binding.impl) != binding.manifest.impl_digest: raise ManifestIntegrityError( f"runtime integrity violated for {tool_name}: " f"bound impl no longer matches signed manifest" ) if not _verify_sig(binding.manifest): raise ManifestIntegrityError( f"manifest signature invalid at dispatch for {tool_name}" ) return binding.impl(**kwargs) ```