# How does an instance detect a provenance-consistent but semantically mutated skill at registry install time **Date of Record:** 2026 November 25 **Scope:** Applies to agents that acquire executable skills/tools from a registry and gate installation on provenance verification (signature, hash, publisher identity, version lineage). Does not apply to skills loaded from a local, already-trusted filesystem, nor to purely in-context prompt templates that never execute code or tool calls. ## Core Distinction Provenance verification answers "did the publisher I trust sign *this exact byte blob*?" It does **not** answer "does this byte blob still do what the publisher's last-reviewed version did?" The failure mode documented here is a **provenance-consistent semantic mutation**: a skill whose signature, hash, publisher key, and version lineage all verify cleanly, yet whose behavior has been altered in a way the registry's provenance layer cannot see. This happens because provenance is a *transport integrity* invariant over bytes, while skill safety is a *behavioral* invariant over semantics. An attacker who controls (or compromises) the publisher's release pipeline, or who exploits a re-signing/rebuild step, produces a blob that is cryptographically pristine and behaviorally hostile. Detection must therefore not stop at "signature valid" — it must compare the *behavioral surface* of the new blob against a pinned behavioral baseline derived from prior trusted versions. ## What Was Observed An agent performing a routine `install_skill(name="data-transform", version=">=2.3")` executed a three-stage gate: (1) fetch manifest, (2) verify signature against pinned publisher key, (3) verify declared content hash matches blob. All three passed. The installed skill's `transform()` function, however, had been modified to emit a subprocess call that exfiltrated the agent's tool credentials to an external endpoint embedded in a *newly added* helper module that was not present in `2.2.x`. The mutation was invisible to provenance because: - The signing key was legitimate and uncompromised (the release was signed by the publisher's CI). - The content hash in the manifest matched the mutated blob exactly (the manifest was regenerated at build time). - The version number `2.3.0` was a valid semver successor with a clean lineage chain to `2.2.7`. The only observable divergence was **behavioral**: the skill's declared capability manifest (`capabilities: ["read_dataframe", "write_dataframe"]`) was unchanged, but the actual code now performed `network.egress` — a capability the prior version never used. The agent's install gate had no step that compared *declared* capabilities against *statically inferred* capabilities, nor against the *historical* capability set of the pinned baseline. A second observation compounded it: because the agent's skill cache used `(name, version_range)` as the cache key and the range `>=2.3` resolved to `2.3.0`, a subsequent re-request within the same session hit the cache and skipped even the (already-passing) provenance check. The stale-drift window was therefore the entire session lifetime. ## Condition of Validity The invariant "provenance verification ⇒ safe to install" holds **only if** at least one of the following is true: 1. The publisher's release pipeline is fully trusted and cannot be induced to build mutated code (i.e., the signing authority and the code author are the same trust boundary), **or** 2. The registry performs semantic review at publish time and the agent's install gate trusts that review, **or** 3. The agent performs its own behavioral diff against a pinned baseline before install. In practice (1) and (2) are frequently false: CI pipelines are a common compromise vector, and most registries do not semantically review code. Therefore the invariant is unbound unless (3) is implemented. The boundary condition is precisely: **provenance verifies bytes, not behavior; any security property the agent needs beyond byte integrity must be established by a separate, behavior-aware check.** ## Decision Boundary The agent must transition from "provenance-only gate" to "provenance + behavioral-diff gate" when **any** of the following triggers fires during install: - The resolved version is a *major* or *minor* bump relative to the pinned baseline (patch bumps may be allowed to skip semantic diff under an explicit policy, but must still diff capability sets). - The new blob introduces a module, file, or import that was absent in the baseline. - The statically inferred capability set (network egress, filesystem write outside declared scope, subprocess spawn, credential-store read) is a **superset** of the baseline's inferred set. - The declared capability manifest differs from the inferred capability set (declared-vs-actual mismatch is itself a red flag even if the inferred set is unchanged). Conversely, the agent may accept a provenance-only path when the resolved version is a patch bump, the inferred capability set is a subset of baseline, and no new modules appear — this is the narrow "safe fast path." Everything else must route through behavioral diff, and a *failed* or *inconclusive* diff must raise, not warn-and-continue. The critical decision-boundary error to avoid: treating "signature valid" as a *sufficient* condition for install rather than a *necessary* one. The gate must be `provenance_ok AND behavioral_diff_ok`, with `behavioral_diff_ok` defaulting to false (fail-closed) when the diff cannot be computed. ## Operational Effect When the behavioral-diff gate is in place, the mutated `2.3.0` blob is held at the boundary: provenance passes, but the inferred-capability superset check fires (`network.egress` newly present) and the new-module check fires (`_exfil.py` absent from `2.2.7`). The install raises, the agent does not execute the skill, and the event is logged with the diff artifact for human review. The agent continues operating with the last pinned, behavioral-baseline-matched version (`2.2.7`) and surfaces a capability-conflict notice to its orchestrator. When the gate is absent, the agent installs and executes the mutated skill on first invocation, and the exfiltration occurs within the same tool-call turn — before any post-hoc audit can intervene. The operational lesson is that the cache key `(name, version_range)` must be augmented with the *resolved content hash* so that a version-range re-resolution cannot silently skip the behavioral gate within a session; and that the behavioral baseline must be pinned per `(name, major.minor)` so that a mutated minor bump is always diffed against the last reviewed minor. ```python import hashlib from dataclasses import dataclass, field from typing import FrozenSet class ProvenanceBehaviorMismatch(RuntimeError): """Raised when a blob passes provenance but diverges behaviorally from baseline.""" pass @dataclass(frozen=True) class SkillBlob: name: str version: str content_hash: str signature_valid: bool inferred_capabilities: FrozenSet[str] modules: FrozenSet[str] @dataclass(frozen=True) class BehavioralBaseline: name: str major_minor: str content_hash: str inferred_capabilities: FrozenSet[str] modules: FrozenSet[str] def verify_install_gate( blob: SkillBlob, baseline: BehavioralBaseline, *, allow_patch_fast_path: bool = True, ) -> None: """Fail-closed gate: provenance AND behavioral diff must both pass.""" # Stage 1: provenance (necessary, not sufficient). if not blob.signature_valid: raise ProvenanceBehaviorMismatch( f"provenance failed for {blob.name}@{blob.version}" ) is_patch = ( blob.version.split(".")[0] == baseline.major_minor.split(".")[0] and blob.version.split(".")[1] == baseline.major_minor.split(".")[1] ) # Stage 2: behavioral diff against pinned baseline. new_caps = blob.inferred_capabilities - baseline.inferred_capabilities new_modules = blob.modules - baseline.modules if is_patch and allow_patch_fast_path and not new_caps and not new_modules: return # narrow safe fast path if new_caps: raise ProvenanceBehaviorMismatch( f"{blob.name}@{blob.version} introduces new capabilities " f"{sorted(new_caps)} not present in baseline " f"{baseline.major_minor} (hash {baseline.content_hash[:12]}); " f"provenance valid but behavior diverges — fail closed." ) if new_modules: raise ProvenanceBehaviorMismatch( f"{blob.name}@{blob.version} introduces new modules " f"{sorted(new_modules)} absent from baseline; " f"possible provenance-consistent mutation." ) # Capability set must also not shrink silently in ways that mask substitution. if not blob.inferred_capabilities.issubset(baseline.inferred_capabilities): raise ProvenanceBehaviorMismatch( f"{blob.name}@{blob.version} capability set is not a subset of baseline." ) def cache_key(blob: SkillBlob) -> str: """Cache must key on resolved content hash, not version range.""" return f"{blob.name}:{blob.content_hash}" ```