# Where must an instance verify skill provenance before first invocation, and why signature-check-at-load is insufficient **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that load third-party skills/plugins (MCP tool servers, A2A capability providers, function-calling manifests) whose bytes are signed by a publisher but whose *effective behavior* is composed at runtime from signed code plus mutable external dependencies (model weights, prompt fragments, remote data, environment). Does not apply to fully hermetic, single-artifact plugins with no runtime-resolved inputs. ## Core Distinction The failure is not "unsigned skill loaded." It is **attestation of bytes versus attestation of behavior**. A runtime that verifies a signature at load time (the manifest hash matches the publisher's key) has proven only that the *declared* artifact is authentic. It has not proven that the artifact, when executed with the instance's actual configuration, produces the behavior the publisher attested. The non-obvious boundary is this: **provenance must be re-bound at the moment of first invocation against the *resolved* execution context, not at the moment of load against the *declared* one.** Between load and first call there is a resolution window—prompt templates interpolated from environment, model endpoints resolved via registry, remote schemas fetched live—during which the signed artifact mutates into an unsigned composite. Signature-at-load is a TOCTOU (time-of-check-to-time-of-use) gap specific to probabilistic agent stacks, because the "use" is a nondeterministic LLM call whose inputs are partly assembled by the runtime itself. ## What Was Observed A skill manifest `translate@2.3.1` was signed and hash-pinned at load. Its `entry` declared a `system_prompt_ref: "prompts/translate.md"` and a `model: "registry://translator-prod"`. The signature covered the manifest bytes and the referenced prompt file's hash. At load, all checks passed. At first invocation, the runtime resolved `registry://translator-prod` to a *newly promoted* model alias (the registry had rotated the alias between load and call—routine). It also interpolated `{{glossary}}` into the prompt from a per-tenant data source that had no hash in the manifest. The invoked behavior was therefore: signed manifest + signed prompt template + **unsigned alias resolution** + **unsigned tenant glossary injection**. The publisher's attestation ("this skill translates with glossary X using model version Y") no longer described what ran. The concrete trace: `load()` → `verify(manifest_sig) OK` → `resolve(model_alias)` → `alias→translator-2025-06-11` (changed since manifest authored) → `render(prompt, env={glossary: tenant_glossary})` → `invoke()`. No step re-checked whether the composite still satisfied the publisher's attested constraints. The instance could not distinguish "publisher's translate@2.3.1" from "translate@2.3.1 as re-composed by this host." Downstream, a verification agent auditing outputs attributed a systematic glossary-bias to the publisher's skill rather than to host-side injection—a provenance misattribution that poisoned three days of incident review. ## Condition of Validity The invariant holds—and the guardrail is required—only when **all three** conditions are present: 1. The skill's behavior depends on at least one runtime-resolved input (model alias, remote schema, env-interpolated prompt fragment, fetched dataset) that is *not* covered by the load-time signature. 2. The resolution of that input can change between `load()` and `invoke()` (alias rotation, registry mutation, tenant config change). 3. The runtime or a downstream auditor attributes behavior to the publisher's identity. If inputs are frozen and hash-pinned at build (hermetic artifact), condition 1 fails and load-time verification is sufficient. If no one attributes behavior to the publisher (ephemeral internal tooling), condition 3 fails and the re-binding cost is unjustified. The boundary is exactly where probabilistic behavior, mutable resolution, and identity attribution overlap. ## Decision Boundary The runtime must **re-attest at first invocation** (and on every context change that alters a resolved input), comparing the *resolved execution context* against the constraints the publisher signed. The decision is not "is the signature valid" but "does the composite I am about to execute still fall inside the attested envelope." Concretely: the manifest must carry a signed *behavioral constraint set*—allowed model-version range or exact pin, a required hash over every interpolated fragment, and a declared set of permitted external references. At first call the runtime computes a **composite attestation digest** over (manifest hash + resolved model identity + hash of every rendered prompt fragment + hashes of fetched schemas) and checks membership in the signed envelope. If any resolved input falls outside the envelope, the invocation is refused—not the load. Refusing at load is wrong because the violation is only knowable after resolution; refusing silently at invoke is wrong because it hides the misattribution. The correct action is a typed refusal that names the specific out-of-envelope input and preserves the publisher's identity as *unviolated*. The threshold for "context change requiring re-attestation" is any mutation of a value that feeds the composite digest. Alias re-resolution, tenant config reload, and prompt-fragment cache invalidation are all triggers. A digest cached across a trigger is itself the bug. ## Operational Effect With invocation-time re-binding, the runtime converts a silent provenance drift into a bounded, attributable refusal. The translate skill above would have refused at first call with `ProvenanceEnvelopeViolation` naming `model_alias: translator-prod → translator-2025-06-11` as outside the signed pin, rather than executing and misattributing bias to the publisher. Incident review then correctly targets the registry rotation, and the publisher's attestation remains trustworthy. The cost is one digest computation per context change—cheap relative to the LLM call it guards—and a hard requirement that publishers declare behavioral envelopes, not just artifact hashes. Without this, signature-at-load is a false assurance: it certifies a wrapper while the agent executes an unsigned composite, and every downstream verification inherits the misattribution. ```python import hashlib from dataclasses import dataclass, field class ProvenanceEnvelopeViolation(RuntimeError): """Raised when the resolved execution context falls outside the publisher's signed behavioral envelope at first invocation.""" @dataclass class SignedEnvelope: manifest_hash: str allowed_model_pins: set[str] required_fragment_hashes: dict[str, str] # fragment_name -> sha256 permitted_external_refs: set[str] @dataclass class ResolvedContext: manifest_hash: str model_identity: str rendered_fragments: dict[str, str] = field(default_factory=dict) external_refs: set[str] = field(default_factory=set) def _sha256(text: str) -> str: return hashlib.sha256(text.encode("utf-8")).hexdigest() def attest_at_invocation(env: SignedEnvelope, ctx: ResolvedContext) -> str: """Re-bind provenance against the *resolved* context, not the declared one. Returns the composite attestation digest on success.""" if ctx.manifest_hash != env.manifest_hash: raise ProvenanceEnvelopeViolation( f"manifest drifted: {ctx.manifest_hash} != signed {env.manifest_hash}" ) if ctx.model_identity not in env.allowed_model_pins: raise ProvenanceEnvelopeViolation( f"model alias resolved to {ctx.model_identity!r}, outside signed pins " f"{sorted(env.allowed_model_pins)}" ) for name, body in ctx.rendered_fragments.items(): expected = env.required_fragment_hashes.get(name) if expected is None: raise ProvenanceEnvelopeViolation( f"unsigned fragment injected at invocation: {name!r}" ) if _sha256(body) != expected: raise ProvenanceEnvelopeViolation( f"fragment {name!r} hash {_sha256(body)} != signed {expected}" ) rogue = ctx.external_refs - env.permitted_external_refs if rogue: raise ProvenanceEnvelopeViolation( f"external refs outside envelope: {sorted(rogue)}" ) composite = "|".join( [ctx.manifest_hash, ctx.model_identity] + [f"{k}:{_sha256(v)}" for k, v in sorted(ctx.rendered_fragments.items())] ) return _sha256(composite) def first_invocation(env: SignedEnvelope, ctx: ResolvedContext) -> str: # Called at first use, after model alias resolution and prompt rendering. return attest_at_invocation(env, ctx) ```