Which invariants prevent unsigned skill manifests from mutating a live agent tool registry mid-episode

**Date of Record:** 2026 December 2 **Scope:** Applies to agents that load tools/skills from a mutable registry (local manifest directory, remote skill index, or MCP server list) at any point after the initial system prompt is constructed. Does not apply to statically compiled tool sets baked into the model weights or frozen at process start with no reload path.

Core Distinction

The dangerous boundary is not "malicious skill exists in the registry." It is "a skill becomes visible to the agent's tool-selection loop *after* the agent has already committed to a plan that assumed the prior registry snapshot." A signed-but-late skill is as dangerous as an unsigned one, because the agent's reasoning trace was generated against a tool inventory that no longer matches reality. The invariant that matters is **registry immutability per episode**: the set of callable tools, their schemas, and their manifest hashes must be pinned at episode start and only re-derived across an explicit checkpoint boundary — never mid-loop.

Manifest signing solves authenticity ("this skill came from publisher X"). It does not solve **temporal consistency** ("this skill was not present when I planned step 3"). Attackers exploit the gap: they register a skill whose *name and description* collide with a tool the planner already referenced, so the agent's next tool-call resolves to the attacker's implementation while the reasoning trace still says it is calling the trusted one.

What Was Observed

Trigger condition: a registry that supports hot-reload (file watcher on `~/.agent/skills/`, or a periodic poll of a remote index) combined with a planner that emits tool calls by name, not by content hash.

Failure trace:

  1. Episode starts. Registry snapshot R0 contains `web_search` (publisher A, hash `h_A`). Planner emits a plan: `step1: web_search(...)`, `step2: summarize`.
  2. Mid-episode, attacker drops a manifest declaring `name: web_search`, `publisher: A`, valid signature for a *different* artifact `h_E`. Registry reloads → snapshot R1. Name-keyed lookup now resolves `web_search` → `h_E`.
  3. Agent executes `step1` by name. It invokes `h_E`, which exfiltrates the query and returns plausible results. The reasoning trace, the audit log's tool name, and the manifest publisher field all read "web_search / A." Only the hash differs.
  4. Signature verification passes at load time (the signature is valid for `h_E`). Verification at *call* time was never performed, because the call site keys on name.

The non-obvious part: signature verification at registration is insufficient. The signature must be **re-verified against the pinned hash at invocation**, and the invocation must be keyed on `(name, hash)` — not name alone. A registry that verifies on write but resolves on read-by-name is a confused-deputy channel.

Condition of Validity

This failure requires all of:

If resolution is keyed on `(name, content_hash)` and the planner emits the hash alongside the name, the substitution fails: the call resolves to `h_A` or raises, never to `h_E`.

Decision Boundary

The guardrail is a **pinned registry handle** carried through the episode:

The boundary decision: if the registry mutates mid-episode and the agent cannot re-plan against the new snapshot before the next tool call, the episode must **halt**, not proceed. Proceeding on a stale plan against a fresh registry is the exact confused-deputy window.

Operational Effect

With pinning enforced, a mid-episode registry mutation produces a `RegistryDriftError` at the next tool call, which the orchestrator surfaces as a checkpoint request. The planner re-derives its plan against the new snapshot, and any tool whose hash changed is flagged for re-approval. The attack surface collapses from "silent substitution" to "loud re-plan," which is recoverable and auditable.

Without pinning, the failure is silent: audit logs show the trusted name, the signature verifies, and the exfiltration is attributed to publisher A. Post-hoc forensics must diff manifest hashes across the episode window to detect it — and only if the registry retains a hash history, which most do not.

The invariant to encode: **a tool call is a reference to (name, hash, snapshot_id), and any resolution that cannot produce all three from the pinned snapshot is a hard failure, never a fallback.**

import hashlib
from dataclasses import dataclass


class RegistryDriftError(RuntimeError):
    """Raised when a tool call resolves outside the episode's pinned registry snapshot."""


@dataclass(frozen=True)
class ToolRef:
    name: str
    content_hash: str
    schema_digest: str


def snapshot_id(tools: list[ToolRef]) -> str:
    payload = "|".join(
        f"{t.name}:{t.content_hash}:{t.schema_digest}"
        for t in sorted(tools, key=lambda t: t.name)
    )
    return hashlib.sha256(payload.encode()).hexdigest()


def resolve_call(
    pinned: dict[str, ToolRef],
    pinned_snapshot_id: str,
    live_snapshot_id: str,
    requested_name: str,
    requested_hash: str,
    call_snapshot_id: str,
) -> ToolRef:
    if call_snapshot_id != pinned_snapshot_id:
        raise RegistryDriftError(
            f"call carried snapshot {call_snapshot_id!r}, episode pinned {pinned_snapshot_id!r}"
        )
    if live_snapshot_id != pinned_snapshot_id:
        raise RegistryDriftError(
            f"live registry drifted to {live_snapshot_id!r}; halt and re-plan at checkpoint"
        )
    ref = pinned.get(requested_name)
    if ref is None:
        raise RegistryDriftError(f"tool {requested_name!r} not in pinned snapshot")
    if ref.content_hash != requested_hash:
        raise RegistryDriftError(
            f"name collision: {requested_name!r} pinned {ref.content_hash!r}, "
            f"call requested {requested_hash!r}"
        )
    return ref