# Why does an instance execute a poisoned skill after a registry reload when its manifest hash matched at load time? **Date of Record:** 2026 December 3 **Scope:** Applies to agents that resolve executable skills from a mutable registry (remote or shared filesystem) and cache skill manifests/descriptors locally between reloads. Does not apply to statically compiled tool bindings or to registries with content-addressed, signed, immutable skill entries keyed by digest. ## Core Distinction The failure is not "a malicious skill got registered." It is that **manifest integrity verification and executable body resolution are two separate reads against a mutable store, and the agent treats the first read as authoritative for the second.** A skill registry entry typically has two parts: a *descriptor* (name, version, declared capability schema, permission scopes, `manifest_sha256`) and a *body* (the actual prompt template, tool-call plan, or code the agent will execute). The loader verifies the descriptor's hash, caches the descriptor, and then — at execution time — dereferences the body by a mutable pointer (`skill_id` + `version` or a `latest` tag). Between the verify-read and the execute-read, the registry can be mutated. The agent's cached descriptor still hashes correctly; the body it actually runs was never covered by that hash. This is a **time-of-check/time-of-use (TOCTOU) gap across the descriptor/body split**, and it is invisible to any check that only validates what was cached. The non-obvious part: reload logic usually *widens* the window rather than closing it. A reload that re-fetches descriptors but reuses a warm body cache, or that re-fetches bodies but re-validates descriptors lazily, leaves the two halves out of sync — and the agent has no invariant asserting they were fetched atomically. ## What Was Observed A registry-backed agent (skills registered as `{skill_id, version, manifest_sha256, body_ref}`) was configured to reload its skill table every N task cycles. Trace of the failing sequence: 1. **Cycle 0 — load.** Agent fetches descriptor for `summarize_doc@1.4`, computes `manifest_sha256`, matches the registry-declared hash, caches descriptor + `body_ref = "blob://skills/summarize_doc/1.4/body"`. Verification passes. The body is *not* fetched at this point — only referenced. 2. **Cycle 0 — first execution.** Agent dereferences `body_ref`, fetches body, executes. Correct behavior. Body is now in a warm LRU keyed by `body_ref`. 3. **Inter-cycle mutation.** An attacker (or a compromised publisher pipeline) overwrites the blob at `blob://skills/summarize_doc/1.4/body` in place. The descriptor is untouched — `manifest_sha256` still matches, because the hash only covered the descriptor, not the body. The version string `1.4` is unchanged; the pointer is stable. 4. **Cycle N — reload.** Reload re-fetches descriptors, re-verifies `manifest_sha256`, passes. The warm body cache is keyed by `body_ref`, and `body_ref` is unchanged, so the cache hits. **The agent never re-reads the mutated blob** — but on the next cold path (cache eviction, a different worker instance, or a `no-cache` header), it *does* read the mutated blob and executes it under the still-valid descriptor's permission scope. 5. **Divergence.** Two instances of the same agent, same descriptor, same verified hash, execute different bodies depending on cache state. Auditors replaying from the descriptor cannot reproduce which body ran, because the body identity was never bound to the verified hash. The observable symptom is not a load error — every hash check passes. It is **behavioral divergence between instances that agree on every verified artifact**, plus an injection that inherits the legitimate skill's declared scopes (e.g., `filesystem:read`, `http:post`) because scope is attached to the descriptor, not the body. ## Condition of Validity The attack surface exists only when all of the following hold; the invariant below is valid exactly under these conditions: - **Descriptor and body are separately addressable and the body pointer is mutable** (tag, `latest`, in-place blob overwrite). If bodies are content-addressed (`body_ref = sha256:`) and the digest is *inside* the signed descriptor, the gap collapses. - **The verified hash does not cover the body**, or covers a body digest that is not re-checked at execution time. - **The agent caches either half across a reload** and does not invalidate the other half in the same atomic step. - **Execution-time resolution dereferences the mutable pointer** rather than a digest pinned at verification time. It does *not* apply when the registry enforces immutability (write-once blobs, version-pinned digests) or when the loader fetches descriptor+body in a single signed bundle and verifies the bundle hash before any execution. ## Decision Boundary The boundary is: **what identity does the executor bind to, and was it the same identity that was verified?** - If the executor binds to `(skill_id, version, body_ref)` and verification bound to `manifest_sha256` over the descriptor only → **the binding is split; treat as untrusted.** - If the executor binds to a digest that was itself inside the verified descriptor and the body is fetched by that digest → **binding is closed; safe to execute.** Operationally, the guardrail is a **pin-then-fetch-then-reverify invariant**: at verification time, resolve the body to a content digest, confirm that digest is present in the verified descriptor, and hand the executor an immutable handle to that digest — never the mutable `body_ref`. On reload, invalidate descriptor and body cache entries as one unit; a descriptor cache hit with a body cache miss (or vice versa) must force a full re-verify, not a partial one. Any execution whose resolved body digest is absent from the verified descriptor's body-digest field must be rejected before tool invocation, not after. ## Operational Effect Without the invariant, skill-injection becomes a **persistence primitive**: the injected body runs under the legitimate skill's scopes, survives reloads (descriptor hash still valid), and produces non-reproducible execution across instances — defeating replay-based auditing because the audit record (descriptor hash) does not identify the body that ran. The blast radius is bounded only by the skill's declared scopes, which the attacker inherits for free. With the invariant, the mutation is caught at the next execution as a digest mismatch against the verified descriptor, the skill is quarantined, and the divergence is surfaced as a hard error rather than silent behavior change. ```python import hashlib from dataclasses import dataclass class SkillIntegrityError(RuntimeError): """Raised when an executable skill body is not bound to the verified descriptor.""" pass @dataclass(frozen=True) class VerifiedDescriptor: skill_id: str version: str manifest_sha256: str # Digest(s) of the body, covered by manifest_sha256. Empty => body unbound. body_digests: frozenset[str] scopes: frozenset[str] def resolve_executable_handle( descriptor: VerifiedDescriptor, fetched_body: bytes, declared_manifest_sha256: str, ) -> str: # Re-verify the descriptor hash at execution time (not just at load). recomputed = hashlib.sha256( f"{descriptor.skill_id}|{descriptor.version}|" f"{','.join(sorted(descriptor.body_digests))}|" f"{','.join(sorted(descriptor.scopes))}".encode() ).hexdigest() if recomputed != declared_manifest_sha256: raise SkillIntegrityError( f"descriptor hash drift for {descriptor.skill_id}@{descriptor.version}" ) body_digest = "sha256:" + hashlib.sha256(fetched_body).hexdigest() # The invariant: the body we are about to execute must be one the # verified descriptor committed to. A mutable body_ref that resolves # to an uncommitted digest is rejected here, before any tool call. if body_digest not in descriptor.body_digests: raise SkillIntegrityError( f"body digest {body_digest} not bound to verified descriptor " f"{descriptor.skill_id}@{descriptor.version}; possible TOCTOU injection" ) return body_digest def execute_skill(descriptor, body_fetcher, declared_manifest_sha256): body = body_fetcher() # may return a mutated blob after reload handle = resolve_executable_handle(descriptor, body, declared_manifest_sha256) # Only now, with a digest-bound handle, may scopes be granted. return handle ```