# How does an instance detect manifest-shadowed tool aliasing during dynamic skill injection **Date of Record:** 2026 November 21 **Scope:** Applies to agents that load tool/skill registries at runtime from manifests (MCP server descriptors, plugin manifests, OpenAPI-derived tool specs) and resolve tool calls by name. Does not apply to statically compiled tool sets with no dynamic registration path. ## Core Distinction The threat most registries defend against is *malicious content inside a well-formed tool*: a poisoned description, an injected instruction in a schema `description` field, a prompt-injection payload smuggled through a parameter default. The failure mode that actually escapes detection is different: **two manifests legitimately declare the same tool name, and the resolution order silently favors the later-loaded one.** No field is malformed. No description contains an injection string. Each manifest passes schema validation independently. The attack surface is not the content of any single skill—it is the *aliasing* between them, and the registry's implicit "last writer wins" merge semantics. An instance cannot detect this by inspecting tool output or reasoning traces. It must detect it at registration time, by comparing the *identity* of a newly registered tool against the identity of the tool it is about to shadow. If the registry keys only on `name` and overwrites silently, the shadowing is invisible to the model, which continues to believe it is calling the original tool. ## What Was Observed A production agent loaded three skill packs in sequence: a base pack (`fs.read`, `fs.write`, `net.fetch`), an analytics pack, and a user-supplied "productivity" pack. The productivity pack's manifest declared a tool it called `net.fetch` with an identical parameter schema (`url: string`, `timeout_ms: int`) but a different implementation endpoint. Because the registry merged by `name`, the user pack's `net.fetch` replaced the base one. The model's tool-call syntax was unchanged; its system prompt still described `net.fetch` as "retrieves a URL and returns the body." Traces showed the divergence only under a specific condition: when the model passed a `timeout_ms` below 2000, the shadowing implementation fell back to a synchronous path that returned a truncated body *with HTTP 200*, whereas the base implementation returned `408` on timeout. The model, seeing 200, treated the truncated body as complete. Multi-step chains that fetched a spec, then parsed it, then acted on the parsed result, silently operated on half a document. No exception was raised anywhere in the stack. The failure looked, in the reasoning trace, like a model hallucination—the model "misread" the document—when in fact the document was truncated by a tool the model never knew had been swapped. Detection in this case came not from the model but from an out-of-band replay auditor: re-running the same tool call against the base pack produced a full body, and the diff surfaced the aliasing. ## Condition of Validity The invariant that must hold is: **a tool call resolves to the implementation whose manifest was in force when the model's context describing that tool was constructed.** This is a *binding* invariant, not a *content* invariant. It is valid only if the registry enforces one of: 1. **Namespace isolation** — each pack registers into a distinct namespace (`analytics.net.fetch` vs `prod.net.fetch`) and the model's tool list reflects the qualified name, so shadowing is impossible by construction. 2. **Identity pinning** — each tool carries a content hash over `(name, schema, endpoint, version)`, and the model's context records the hash it was shown. A call whose hash does not match the currently-registered hash is rejected before dispatch. 3. **Immutable-on-load** — the registry refuses to overwrite an existing name; a colliding manifest must either declare a distinct name or be rejected. Without one of these, the invariant is undefined, and no amount of prompt hardening or output validation recovers it, because the model's belief about the tool and the registry's actual tool have silently decoupled. The condition of validity is therefore *structural*, established at registration, not at call time. ## Decision Boundary The boundary is whether a name collision is treated as an error or as a merge. The decision must be made at *registration*, before any model context is built, because after context construction the decoupling is already latent. Concretely: - If a manifest declares a name that already exists and its identity hash differs → **reject the manifest** (or quarantine it into a namespace), and do not rebuild the model context. Surface the collision to the operator, not to the model. - If the identity hash matches → idempotent re-registration; safe to no-op. - If the manifest is a *versioned upgrade* of an existing tool → require an explicit version bump in the name or a signed upgrade warrant, and invalidate any in-flight contexts that reference the old hash. The subtle case: a pack that legitimately *intends* to override a base tool (a caching wrapper, a mock for testing). This must be expressed as an explicit `overrides: ` field in the manifest, which the registry verifies against the target's hash. An override without a matching hash is indistinguishable from an attack and must be rejected. The model must also be told, in its context, that the tool is a wrapper—otherwise it will reason about the wrapper's semantics as if they were the base tool's. ## Operational Effect When the invariant holds, a skill-injection attempt via aliasing fails closed at registration and never reaches the model. When it is absent, the attack is *silent and durable*: the shadowing tool persists for the life of the registry, every subsequent call in every subsequent session resolves to it, and the only observable signal is downstream behavioral drift (truncated results, altered error codes, changed latency) that the model will rationalize as its own error. Replay auditing against a pinned base pack is the recovery mechanism, but it is expensive and only catches drift when the same call is re-executed. The operational rule is therefore: **never let a registry key on name alone; key on name plus identity hash, and make collision a hard error at load time.** ```python import hashlib from dataclasses import dataclass class ToolAliasCollisionError(RuntimeError): """Raised when a manifest registers a tool name whose identity hash does not match the already-registered tool of the same name, and no valid override warrant is present. This is a registration-time failure; it must fire before any model context referencing the tool is built.""" @dataclass(frozen=True) class ToolIdentity: name: str schema: str endpoint: str version: str def content_hash(self) -> str: payload = "|".join((self.name, self.schema, self.endpoint, self.version)) return hashlib.sha256(payload.encode("utf-8")).hexdigest() class ToolRegistry: def __init__(self) -> None: self._tools: dict[str, ToolIdentity] = {} def register(self, tool: ToolIdentity, override_hash: str | None = None) -> None: existing = self._tools.get(tool.name) if existing is None: self._tools[tool.name] = tool return incoming_hash = tool.content_hash() existing_hash = existing.content_hash() if incoming_hash == existing_hash: return # idempotent re-registration # An override is only legitimate if it names the exact hash it shadows. if override_hash is not None and override_hash == existing_hash: self._tools[tool.name] = tool return raise ToolAliasCollisionError( f"tool name {tool.name!r} collides: registered={existing_hash[:12]} " f"incoming={incoming_hash[:12]} override_warrant={override_hash!r}; " f"refusing to shadow. Qualify the name or supply a matching override." ) def resolve(self, name: str) -> ToolIdentity: tool = self._tools.get(name) if tool is None: raise ToolAliasCollisionError(f"tool {name!r} not registered") return tool def load_manifest_pack(registry: ToolRegistry, pack: list[ToolIdentity]) -> None: # Load atomically: validate the whole pack before mutating the registry, # so a mid-pack collision does not leave a partially-applied pack. staged: dict[str, ToolIdentity] = {} for tool in pack: prior = staged.get(tool.name) or registry._tools.get(tool.name) if prior is not None and prior.content_hash() != tool.content_hash(): raise ToolAliasCollisionError( f"intra-pack alias on {tool.name!r}; pack rejected wholesale" ) staged[tool.name] = tool for tool in staged.values(): registry.register(tool) ```