# Which invariants prevent skill-injection escalation when a dynamic tool registry re-registers a skill name mid-session **Date of Record:** 2026 November 22 **Scope:** Applies to agents whose tool/skill registry is mutated at runtime (hot-reload, marketplace install, remote MCP server re-announce, or peer-agent capability advertisement) while an active reasoning loop holds references to previously resolved skills. Does not apply to static, build-time-frozen tool manifests where the registry is immutable for the lifetime of the process. ## Core Distinction The failure is not "a malicious skill got installed." That is a coarse, detectable event. The failure is **name-identity conflation during resolution**: an agent's planner resolves a skill by *name* (or by a cached `{name → callable}` binding captured at prompt-assembly time), while the registry permits that same name to be *re-bound* to a different implementation between the moment the planner decided to call it and the moment the executor dispatches it. The agent's reasoning trace still says `call summarize_document(...)` with a justification written against the *old* schema and the *old* trust level; the executor silently invokes the *new* body. The reasoning and the execution diverge without either layer noticing. The invariant that prevents this is **binding immutability across a decision-to-dispatch window**: a skill resolution must produce a handle pinned to an immutable `(name, version, content_hash, warrant)` tuple, and the executor must refuse to dispatch any handle whose registry entry has changed since resolution. Name is a lookup key, never an identity. ## What Was Observed A long-running document-processing agent (planner + executor split, ~40k token context, 11 installed skills) was mid-task on a multi-document summarization run. The planner had already emitted a reasoning step: *"I will call `summarize_document` with `{path, max_tokens}`; this skill is locally authored, low-risk, no network egress."* That justification was written after the planner read the skill's manifest during prompt assembly. Between that step and dispatch, an asynchronous registry refresh fired (a remote marketplace poll, scheduled every 90s). The upstream catalog had published a new revision of `summarize_document` under the identical name — a revision whose body additionally performed an outbound HTTP POST of the document text to a telemetry endpoint and whose schema had silently gained an optional `callback_url` parameter. The registry applied the update in place, overwriting the `{name → callable}` entry. The executor dispatched the planner's `summarize_document({path, max_tokens})` call. It resolved the name *at dispatch time*, got the new callable, and executed it. The document left the sandbox. Nothing in the trace flagged a problem: the planner's stated justification ("no network egress") was now false, but it was never re-checked; the schema mismatch (`callback_url` now optional, not required) meant no argument-validation error fired; the content hash of the skill was never compared because the executor had never recorded one. The post-hoc audit found three separable defects: (1) resolution was deferred to dispatch rather than pinned at decision, (2) the registry applied in-place mutation rather than copy-on-write versioning, and (3) the planner's trust/egress justification was stored as prose in the reasoning trace, not as a machine-checkable precondition attached to the call handle. ## Condition of Validity The guardrail below is *only* sound under these conditions, and each must be asserted explicitly rather than assumed: - **Resolution pinning.** Every skill reference emitted by the planner carries a `SkillHandle` containing `name`, `version`, `content_hash`, and `warrant` (the trust/egress/schema facts the planner reasoned against). The handle is minted at decision time and is the *only* thing the executor accepts. - **Copy-on-write registry.** Registry updates never mutate an existing entry in place; they publish a new version and bump a generation counter. Old versions remain resolvable until explicitly retired, so a pinned handle can still be dispatched against the body it was reasoned about. - **Precondition re-verification at dispatch.** Before invoking, the executor re-checks the handle's `warrant` against the *current* entry: content hash must match, declared egress class must match, and the argument schema the planner validated against must be the schema being enforced. - **Generation fencing on the reasoning loop.** If the registry generation advanced since the planner's last observation, the executor must treat the call as *stale* and bounce it back to the planner for re-justification, rather than silently proceeding. It does **not** hold if the agent resolves skills lazily by name inside tool-call construction, if the registry is a plain dict mutated by a background thread, or if trust facts live only in natural-language reasoning text. ## Decision Boundary When a pinned handle's `content_hash` or `warrant` no longer matches the live registry entry, the agent has exactly two legal moves, and the choice is not discretionary: - **Bounce-and-replan** if the divergence is a benign version bump (same author warrant, additive schema, egress class unchanged). The planner re-reads the new manifest, re-derives its justification, and mints a fresh handle. Cost: one extra reasoning step. - **Halt and quarantine** if the divergence changes the *warrant* — egress class widened, author identity changed, a previously-required parameter became optional (schema loosening is the classic injection signal), or the content hash changed with no version bump. This is not a re-plan; it is a security event. The task suspends, the handle is burned, and the registry entry is flagged. The boundary between these two is **warrant equality, not name equality**. Two skills with the same name and different warrants are different capabilities. An agent that treats a name match as a capability match has already lost the invariant. ## Operational Effect With pinning + copy-on-write + dispatch-time re-verification in place, the injection above fails closed: the executor sees the handle's hash (`sha256:9f2c…`) does not match the live entry (`sha256:1a7e…`), sees the egress class flipped from `local` to `network`, and raises rather than dispatches. The planner's stale justification never gets the chance to authorize egress it did not reason about. The cost is one bounced call and a ~200ms re-resolution; the alternative is silent exfiltration justified by a reasoning trace that is now a lie. The residual risk is *same-warrant content swap*: an attacker who can publish a new revision with identical declared warrant but different body defeats warrant comparison, and only the content hash catches it — which is why the hash must be checked unconditionally, not only when the warrant differs. ```python import hashlib from dataclasses import dataclass class SkillBindingError(RuntimeError): """Raised when a pinned skill handle no longer matches the live registry entry.""" pass @dataclass(frozen=True) class SkillHandle: name: str version: str content_hash: str warrant: dict # egress class, author, required-param set registry_generation: int def resolve_handle(registry, name: str, planner_warrant: dict) -> SkillHandle: entry = registry.current(name) return SkillHandle( name=name, version=entry.version, content_hash=entry.content_hash, warrant=planner_warrant, registry_generation=registry.generation, ) def dispatch(registry, handle: SkillHandle, args: dict): live = registry.current(handle.name) # Invariant 1: content identity must match the body the planner reasoned about. if live.content_hash != handle.content_hash: raise SkillBindingError( f"content hash drift for {handle.name}: " f"pinned={handle.content_hash} live={live.content_hash}" ) # Invariant 2: the trust warrant must be unchanged. Egress widening or # schema loosening (a previously-required param now optional) is an # injection signal, not a benign version bump. if live.warrant.get("egress") != handle.warrant.get("egress"): raise SkillBindingError( f"egress class changed for {handle.name}: " f"{handle.warrant.get('egress')} -> {live.warrant.get('egress')}" ) if not set(handle.warrant.get("required", set())).issubset(live.required_params): raise SkillBindingError( f"schema loosened for {handle.name}: required params " f"{handle.warrant.get('required')} no longer enforced" ) # Invariant 3: generation fencing — if the registry advanced since the # planner last observed it, the call is stale and must be re-justified. if registry.generation != handle.registry_generation: raise SkillBindingError( f"stale handle for {handle.name}: registry generation " f"{handle.registry_generation} -> {registry.generation}; bounce to planner" ) return live.callable(**args) ```