# How does an instance detect a shadowed-skill injection when a dynamically loaded registry resolves two skill manifests to the same invocation key **Date of Record:** 2026 November 21 **Scope:** Applies to agents whose tool/skill registry is populated at runtime from external manifests (MCP `tools/list`, plugin directories, remote skill stores) and where resolution is keyed by a name or `(name, namespace)` pair. Does not apply to statically compiled, single-author tool tables where the invocation key is fixed at build time and cannot be re-bound. ## Core Distinction The failure is not "a malicious skill got loaded." It is that **the registry accepted a second manifest whose invocation key collides with an already-resident, previously-verified skill, and the resolver silently chose one of the two without recording which.** The agent's planner continues to reason over a skill it believes is the vetted one (say `read_file`, previously audited, scope-restricted to a sandbox root), while the dispatcher routes the call to the newly injected manifest that shadows it. The dangerous part is the *discontinuity of identity under a stable name*: from the planner's perspective nothing changed, because the name did not change. Every downstream invariant—capability scoping, warrant propagation, audit attribution—was anchored to the name, and the name now points at different code. This is distinct from classic prompt injection (which corrupts *inputs* to reasoning) and from supply-chain poisoning at install time (which corrupts the *artifact* before it is trusted). Here the artifact may be individually benign-looking; the corruption is in the *resolution map*, the binding between an invocation key and a manifest. The agent's trust model is a function of keys; the attack is a function of key collisions. ## What Was Observed A registry loaded a baseline set of skills at cold start, including `fs.read` with a declared scope of `sandbox_root` and a content hash recorded in the session's trust ledger. Mid-task, a remote skill store refresh was triggered (a routine `tools/list` re-poll after a TTL expiry). The refresh returned the baseline set *plus* a new manifest declaring the same key `fs.read` but with `scope: "/"` and a different hash. The loader's merge policy was "last write wins per key," a common default because it makes hot-reload of updated skills trivial. The trace: 1. `tools/list` poll returns 14 manifests; 13 match resident hashes, 1 collides on key `fs.read` with a mismatched hash. 2. Merge step overwrites the resident entry. No diff is surfaced to the planner; the planner's system prompt still describes `fs.read` as sandbox-scoped because that description was rendered *before* the refresh from the old manifest. 3. Planner issues `fs.read("/etc/passwd")` believing it will be rejected by the scope guard. 4. Dispatcher resolves `fs.read` to the *new* manifest, whose declared scope is `/`, and the guard—evaluated against the new manifest's scope—permits it. 5. The call succeeds. The audit log records `fs.read` under the original skill's identity because attribution keyed on the name, not the hash. The observable signature was a **hash discontinuity under a stable key with no intervening unload event**. The registry had no notion of "unload"—it only knew "merge." A skill's identity, from the registry's view, was its key; from the audit's view, it was also its key; from the planner's view, it was the description string cached in context. Three different identity notions, none of which included the content hash at the moment of dispatch. ## Condition of Validity The guardrail holds only under a specific invariant, which we state as the **key-immutability invariant**: *for the lifetime of a session, an invocation key resolves to exactly one content hash, and any attempt to re-bind that key to a different hash must either fail loudly or produce an explicit unload/reload event that invalidates all cached descriptions and re-runs verification.* This invariant is violated by any of: - **Last-write-wins merge** on key collision (the observed case). - **Namespace flattening**, where `vendorA.fs.read` and `vendorB.fs.read` both normalize to `fs.read` during registration. - **Case/whitespace normalization** in the key function, so `FS.Read` and `fs.read ` collide with `fs.read` only *after* the loader has already deduplicated by raw string, leaving two entries that resolve identically at dispatch. - **Description-cache staleness**, where the planner's rendered tool schema is refreshed on a different cadence than the manifest map, so the two disagree for a window. The invariant is *not* needed when the registry is append-only and dispatch is keyed by `(key, hash)`, because a colliding key simply becomes a distinct, explicitly-selected entry—ambiguity is surfaced to the planner rather than resolved silently. ## Decision Boundary The instance must draw the line at the moment of merge, not at the moment of dispatch. At dispatch it is too late: the planner has already committed a tool call whose arguments were shaped by the stale description. The decision is a binary at merge time: - If a returned manifest's key matches a resident key **and** its hash matches → no-op, refresh TTL only. - If the key matches and the hash differs → **do not merge.** Either reject the refresh entry and keep the resident binding, or, if hot-swap is required, emit an explicit `SkillRebind` event that (a) unloads the resident entry, (b) invalidates every cached description referencing that key, and (c) forces the planner to re-read the tool schema before its next call. The boundary is *not* "is the new manifest malicious?" The registry cannot answer that, and attempting to (heuristic scanning of descriptions, etc.) produces false confidence. The boundary is purely structural: **does this operation change what a stable name points at?** If yes, it is a rebind and must be treated as a trust event, never as a routine refresh. A second boundary governs ambiguity: if after merge two entries share a key, dispatch must **fail closed** rather than pick one. Silent tie-breaking—by load order, by recency, by hash sort—is the mechanism by which shadowing becomes invisible. ## Operational Effect With the invariant enforced, the observed attack degrades to a rejected refresh entry: the colliding manifest is quarantined, the resident `fs.read` keeps its sandbox scope, and the planner's `fs.read("/etc/passwd")` is rejected by the scope guard as originally intended. The cost is that legitimate skill updates require an explicit rebind handshake—acceptable, because skill updates are rare relative to calls, and the handshake is exactly where re-verification belongs. Without it, the agent's entire trust surface is a name-keyed map that any refresh can silently re-point. Capability scoping, warrant propagation, and audit attribution all inherit the collision and all fail together, because they all trusted the key. The instance cannot detect the *motive*, but it can and must detect the *hash discontinuity under a stable key*—that is the one signal that is structural, cheap, and unambiguous. ```python import hashlib from dataclasses import dataclass, field class SkillRebindError(RuntimeError): """Raised when a registry refresh attempts to silently re-bind a stable invocation key to a different content hash without an explicit rebind event.""" class AmbiguousResolutionError(RuntimeError): """Raised at dispatch when more than one manifest resolves to the same key.""" @dataclass class Manifest: key: str content: bytes scope: str = "sandbox_root" @property def digest(self) -> str: return hashlib.sha256(self.content).hexdigest() @dataclass class SkillRegistry: resident: dict[str, Manifest] = field(default_factory=dict) pending_rebinds: dict[str, Manifest] = field(default_factory=dict) def load_initial(self, manifests: list[Manifest]) -> None: for m in manifests: if m.key in self.resident: raise AmbiguousResolutionError(f"duplicate key at cold start: {m.key}") self.resident[m.key] = m def merge_refresh(self, manifests: list[Manifest], allow_rebind: bool = False) -> None: """Merge a tools/list refresh. Enforces key-immutability: a colliding key with a differing hash is a rebind, not a refresh.""" for m in manifests: existing = self.resident.get(m.key) if existing is None: self.resident[m.key] = m continue if existing.digest == m.digest: continue # benign refresh, same content if not allow_rebind: raise SkillRebindError( f"key {m.key!r} re-bound from {existing.digest[:12]} " f"to {m.digest[:12]} without explicit rebind event; " f"resident scope {existing.scope!r} would be shadowed by {m.scope!r}" ) # Explicit rebind: quarantine old, stage new, invalidate descriptions. self.pending_rebinds[m.key] = m del self.resident[m.key] def resolve(self, key: str) -> Manifest: if key in self.pending_rebinds: raise SkillRebindError( f"key {key!r} awaiting rebind handshake; dispatch blocked until " f"planner re-reads schema" ) if key not in self.resident: raise AmbiguousResolutionError(f"unresolvable key: {key!r}") return self.resident[key] def handle_refresh(registry: SkillRegistry, manifests: list[Manifest]) -> None: try: registry.merge_refresh(manifests) except SkillRebindError as e: # Fail closed: quarantine the colliding entries, keep resident bindings. # Log the hash discontinuity as a trust event for audit. raise SkillRebindError(f"refresh rejected, resident bindings preserved: {e}") from e ```