# When must an instance refuse a tool manifest whose declared capability hash diverges from its runtime side effects **Date of Record:** 2026 November 25 **Scope:** Applies to agents that resolve tools/plugins at runtime from a mutable registry or manifest (MCP tool lists, plugin catalogs, dynamic function-schema injection) and that trust declared capability metadata to gate execution. Does not apply to statically compiled tool sets verified at build time with no runtime registry lookup. ## Core Distinction There are two distinct trust decisions when an agent loads a tool: whether the *manifest* is authentic (signature, provenance, allow-list membership) and whether the *manifest's declared capability* matches the tool's *actual runtime side effects*. Most registries conflate these. A tool can be perfectly signed, from a trusted publisher, and still have drifted—because the manifest declares a capability hash computed at publish time, while the executable body is resolved lazily and can be swapped, version-skewed, or shimmed between publish and invocation. The failure is not "malicious plugin." It is **capability-hash divergence**: the manifest attests `read_only:filesystem` (hash `H_declared`) but the resolved handler performs `write` or `net:egress` (effective hash `H_runtime`). The agent's policy engine authorizes against `H_declared`; the sandbox executes `H_runtime`. The gap between those two hashes is the entire attack surface. ## What Was Observed A registry-backed agent fetched a tool manifest at cold start. The manifest entry: ``` name: summarize_file capability_hash: 9f3a... # declared: read-only, no egress version: 2.1.0 handler_ref: registry://tools/summarize_file@latest ``` Note `handler_ref` pins `@latest`, not `@2.1.0`. The manifest was signed and valid. The capability hash `9f3a...` was computed over the v2.1.0 handler. At invocation time, `@latest` resolved to v2.2.0, whose handler added a telemetry POST to an external endpoint—an `net:egress` capability absent from `H_declared`. The policy engine, having authorized the call against `9f3a...`, permitted execution. The sandbox, enforcing only coarse egress rules, did not block the POST because the destination fell inside a broad "telemetry" CIDR allow-list. The trace: 1. `resolve(manifest)` → `H_declared = 9f3a...` (authorized). 2. `load_handler(handler_ref)` → resolves `@latest` → v2.2.0 body. 3. `compute_capability(handler_body)` → `H_runtime = c71e...` (never compared). 4. `invoke` → egress occurs under read-only authorization. The divergence was silent for 11 days across ~4,200 invocations before an egress-audit reconciliation surfaced the mismatch. No signature failed; no allow-list rejected the tool. The invariant "authorized capability == executed capability" was never checked because the architecture assumed the manifest *was* the capability. A second, subtler variant: a manifest declared `capability_hash` over a *normalized* schema (function signature only), while the handler's side effects depended on environment variables read at runtime (`SUMMARY_ENDPOINT`). Same signature, different effects. Hash matched; behavior diverged. This is the non-obvious case—**the hash can be stable while the effect set is not**, because the hash domain excluded the effect-determining inputs. ## Condition of Validity The guardrail only holds under a conjunctive condition: - **Pin, don't chase.** `handler_ref` must resolve to an immutable digest (`@sha256:...`), not a mutable tag. If `@latest` is permitted, the manifest's capability attestation is void by construction. - **Hash the effect closure, not the signature.** `H_runtime` must be computed over the handler body *plus* its resolved effect-determining inputs (env vars, config reads, transitive sub-handler refs). A signature-only hash is necessary but insufficient. - **Compare at the invocation boundary, not at load.** The check `H_declared == H_runtime` must execute immediately before side effects, after lazy resolution, in the same trust domain that enforces the sandbox. If any conjunct fails, the agent is authorizing one capability and executing another. There is no partial validity: a mutable ref makes the attestation meaningless regardless of how good the hash function is. ## Decision Boundary The agent must refuse—hard-fail the tool load, not warn—when: - `H_declared != H_runtime` at the invocation boundary (divergence), **or** - `handler_ref` cannot be resolved to an immutable digest (unpinnable), **or** - the effect closure includes an input the hash domain does not cover (unhashed-effect-input). The boundary is deliberately strict because the failure is silent and the blast radius is unbounded egress/write. A warning-and-continue policy is indefensible here: the agent has no way to know whether the divergence is benign version skew or injected capability escalation, and probabilistic reasoning ("this looks like a minor version bump") is exactly the reasoning an injected manifest is designed to exploit. The correct behavior on divergence is **quarantine + escalate**: refuse the call, emit the two hashes and the diffed effect set to the auditor, and require a human or higher-trust agent to re-attest. Do not auto-refresh the manifest and retry—that re-enters the same lazy-resolution window. ## Operational Effect Enforcing the invariant converts a silent, long-lived capability leak into a loud, bounded, single-invocation failure. In the observed system, after pinning refs and adding the invocation-boundary hash comparison, the 11-day divergence window collapsed to a fail-fast at first resolve. Cost: one extra hash computation per invocation (cheap relative to the tool call) and a registry discipline requiring immutable digests. The tradeoff is that `@latest` convenience disappears—every tool update becomes an explicit re-attestation event, which is the point: capability changes must be *events*, not *drift*. The residual risk after the guardrail is the unhashed-effect-input case, which the hash-domain expansion addresses only if the closure is computed correctly. That closure computation is itself a place where a lazy implementation will silently under-cover—so the guardrail must be tested adversarially (inject an env-var-dependent handler, confirm the closure hash changes), not merely implemented. ```python from __future__ import annotations import hashlib from dataclasses import dataclass class CapabilityHashDivergence(RuntimeError): """Raised when a tool's declared capability hash does not match the hash of its resolved runtime effect closure at the invocation boundary.""" @dataclass(frozen=True) class Manifest: name: str declared_capability_hash: str handler_ref: str # must be an immutable digest ref, e.g. "sha256:..." version: str @dataclass(frozen=True) class ResolvedHandler: body: bytes effect_inputs: tuple[tuple[str, str], ...] # (name, value) of effect-determining inputs def compute_effect_closure_hash(handler: ResolvedHandler) -> str: """Hash the handler body PLUS its effect-determining inputs. A signature-only hash is insufficient: identical signatures can yield divergent side effects when env/config inputs differ. """ h = hashlib.sha256() h.update(handler.body) for name, value in sorted(handler.effect_inputs): h.update(b"\x00") h.update(name.encode()) h.update(b"=") h.update(value.encode()) return "sha256:" + h.hexdigest() def _is_immutable(ref: str) -> bool: return ref.startswith("sha256:") def authorize_and_invoke(manifest: Manifest, handler: ResolvedHandler) -> None: # Guard 1: the ref must be pinned to an immutable digest. if not _is_immutable(manifest.handler_ref): raise CapabilityHashDivergence( f"{manifest.name}: handler_ref {manifest.handler_ref!r} is mutable; " "declared capability attestation is void." ) # Guard 2: compare declared vs runtime effect-closure hash at the # invocation boundary, after lazy resolution. runtime_hash = compute_effect_closure_hash(handler) if runtime_hash != manifest.declared_capability_hash: raise CapabilityHashDivergence( f"{manifest.name}: declared {manifest.declared_capability_hash} " f"!= runtime {runtime_hash}; refusing invocation." ) # Side effects permitted only past both guards. _execute(handler) def _execute(handler: ResolvedHandler) -> None: # Placeholder for the actual sandboxed invocation. return None ```