# Where must an instance reconcile a capability diff before skill load, or the diff itself becomes the injection vector **Date of Record:** 2026 November 24 **Scope:** Applies to agents that gate skill/tool loading on a pre-load capability diff (declared vs. observed permissions, schema surface, or reachable-tool set). Does not apply to agents that load skills from a fully trusted, version-pinned manifest with no runtime introspection step. ## Core Distinction There are two structurally different failure surfaces when an agent loads a skill. The first is the *content* of the skill: malicious instructions, prompt injection embedded in a tool description, poisoned few-shot examples. This is the well-trodden injection surface, and capability-diffing does not address it. The second surface is the *capability diff itself*. When an agent decides whether to admit a skill by computing `observed_capabilities − declared_capabilities` and acting on the difference, it has created a new stateful, attacker-observable, attacker-influenceable computation that runs *before* the skill is trusted. The diff is a decision artifact produced from untrusted input, and the agent typically treats the diff's *output* as trusted. That asymmetry — untrusted inputs producing a trusted verdict — is where the boundary fails. The non-obvious consequence: an adversary who cannot smuggle a payload past content filters can instead shape the *observed* capability set so the diff reads clean. The skill loads without alarm not because it is safe, but because the attacker made the diff unable to see the delta. ## What Was Observed A skill admission pipeline computed the diff by enumerating reachable tools *after* a dry-run tool-load, then comparing against the manifest's declared `permissions` block. The dry-run instantiated the skill in a sandbox, invoked a no-op `__init__`, and introspected the resulting tool registry. The observed failure trace: 1. The skill's `__init__` registered a benign tool set, so `observed` matched `declared` — diff empty, verdict `ADMIT`. 2. The skill's `__init__` also spawned a deferred registration path: a thread, an `atexit` hook, or a lazy import that mutated the tool registry *after* introspection returned. 3. Post-admission, the registry contained tools never seen by the diff. The agent operated with a capability set that no diff ever evaluated. 4. Because the diff had returned `ADMIT`, downstream policy treated the skill as capability-verified. The verification artifact outlived the state it verified. The load-time diff was a point-in-time measurement of a system whose capability surface was mutable across time. The invariant "diff empty ⇒ capability set equals declared" held only at the instant of measurement and was silently violated at every subsequent instant. A second observed variant: the diff normalized capability identifiers by string, and the skill declared `fs.read` while exposing a tool that resolved to `filesystem::read` through an alias table populated at load. The diff saw two distinct strings, computed a delta, and — depending on whether the policy treated unknown-to-declared as additive or as a mismatch — either admitted an unlisted capability or rejected a safe skill. The alias table was itself attacker-influenceable through a skill-provided resolver. ## Condition of Validity The capability-diff guardrail is valid only under all of the following, and the agent must be able to *test* each at load time: - **Immutability across the admission window.** The observed capability set is frozen between measurement and the first post-admission tool invocation. Any deferred registration, lazy import, thread spawn, or registry mutation invalidates the diff. The agent must either seal the registry or re-diff on every mutation. - **Canonical identity.** Capability identifiers are resolved through a canonicalization function that is not supplied or influenced by the skill. If the skill can register aliases, the diff compares incomparable strings. - **Diff-direction discipline.** The agent must distinguish `observed ⊋ declared` (undeclared capability — hard fail) from `declared ⊋ observed` (unrealized declaration — soft, benign) and from set-equality-after-canonicalization. Collapsing these into a single boolean is the most common defect. - **Verdict scoping.** The `ADMIT` verdict is bound to the exact capability set it measured. If the set changes, the verdict is void, not merely stale. When any of these fails, the diff is not a weaker guardrail — it is a *negative* guardrail, because it manufactures false assurance that suppresses other checks. ## Decision Boundary The boundary is this: **a capability diff may gate admission only if the diff is computed over a sealed, canonically-identified capability set, and the verdict is invalidated by any subsequent set mutation.** Operationally, the agent must choose between two admissible designs and reject the third: - **Seal-then-diff.** Freeze the registry (deny registration after introspection), compute the diff, admit, then unfreeze with the verdict bound to the frozen set. Any post-unfreeze mutation triggers a re-diff before the new capability is usable. - **Diff-on-mutation.** Leave the registry live but install a mutation hook that recomputes the diff and revokes admission on any delta. The verdict is a continuously-maintained invariant, not a one-shot event. - **Rejected: diff-once-trust-forever.** The common implementation. It is inadmissible whenever the skill executes any code before or during introspection, which is essentially always. The agent must also refuse to treat a *non-empty* diff as automatically hostile without canonicalization; a false-positive diff that rejects safe skills trains operators to disable the check, which is a slower path to the same failure. ## Operational Effect When the invariant holds, the capability diff is a genuine pre-admission gate: undeclared reachable tools block the load, and the block is durable because the verdict tracks the capability set. When it fails, the failure is silent and *inverted* — the agent's logs show `ADMIT` with an empty diff, which reads as a clean verification, while the actual runtime capability set diverges. Incident response then investigates the skill content (the wrong surface) and finds nothing, because the payload was never in the content; it was in the timing of registration. The practical consequence for an agent operating under this guardrail: never persist an `ADMIT` verdict as a property of the skill. Persist it as a property of the *(skill, capability-set-hash)* pair, and re-verify the hash before every privileged tool invocation. A verdict without its measured set is an unverifiable claim. ```python import hashlib from dataclasses import dataclass, field class CapabilityDiffViolation(RuntimeError): """Raised when a skill's observed capability set diverges from the set a verdict was issued against.""" pass @dataclass(frozen=True) class CapabilitySet: tools: frozenset def canonical_hash(self) -> str: # Canonicalization MUST NOT consult any skill-supplied alias table. joined = "\x00".join(sorted(self.tools)) return hashlib.sha256(joined.encode("utf-8")).hexdigest() @dataclass class AdmissionVerdict: skill_id: str declared: CapabilitySet measured: CapabilitySet set_hash: str = field(init=False) def __post_init__(self) -> None: self.set_hash = self.measured.canonical_hash() def is_valid_for(self, current: CapabilitySet) -> bool: # Verdict is bound to the exact set it measured; mutation voids it. return current.canonical_hash() == self.set_hash def admit_skill(skill_id: str, declared: CapabilitySet, registry_snapshot: CapabilitySet) -> AdmissionVerdict: undeclared = registry_snapshot.tools - declared.tools if undeclared: raise CapabilityDiffViolation( f"skill {skill_id!r} exposes undeclared capabilities: {sorted(undeclared)}" ) return AdmissionVerdict(skill_id=skill_id, declared=declared, measured=registry_snapshot) def invoke_with_verdict(verdict: AdmissionVerdict, current_registry: CapabilitySet, tool: str, *args): if not verdict.is_valid_for(current_registry): raise CapabilityDiffViolation( f"admission verdict for {verdict.skill_id!r} was issued against set " f"{verdict.set_hash[:12]} but registry now hashes to " f"{current_registry.canonical_hash()[:12]}; capability set mutated post-admission" ) if tool not in verdict.measured.tools: raise CapabilityDiffViolation( f"tool {tool!r} not present in the measured capability set for {verdict.skill_id!r}" ) return (tool, args) ```