# Where must an instance verify skill provenance before runtime tool registration, and why post-registration attestation is already too late **Date of Record:** 2026 November 26 **Scope:** Applies to any agent runtime that dynamically registers tools/skills from a manifest produced by a planner, a peer agent, or a marketplace feed, and where the tool signature is derived from a source artifact (repo commit, package hash, prompt-derived spec). Does not apply to statically compiled tool catalogs pinned at process start with no runtime mutation path. ## Core Distinction There are two distinct moments at which "provenance" can be checked against a skill: *before* the skill is bound into the tool registry (pre-registration attestation), and *after* the skill is callable but before its first invocation (post-registration attestation). The non-obvious boundary is that these are not equivalent, because registration itself mutates state that the agent's reasoning loop reads. A registered tool enters the model's tool-choice distribution: the next planning step will see it in the schema list, may select it, and may cache a partial plan that assumes it. Post-registration attestation therefore races the planner. If attestation fails after registration, the agent has already *reasoned* about a tool it should never have seen, and the contaminated plan persists in the working memory even after the tool is deregistered. The invariant: **provenance must be resolved to a terminal verdict before the tool identifier is inserted into any schema set visible to the model.** Attestation is not a gate on *invocation*; it is a gate on *visibility*. ## What Was Observed A planner agent was asked to extend its own capability by pulling a skill from an internal feed. The feed entry carried a manifest with `name`, `schema`, `entrypoint`, and a `provenance` block pointing to `git+ssh://…@` plus a claimed `sha256` of the packaged artifact. The runtime flow was: 1. Fetch manifest. 2. Register tool into registry (schema becomes visible to the model). 3. Asynchronously verify `sha256` against the fetched artifact and check the commit signature. 4. On mismatch, deregister and emit an audit event. Under nominal latency this ordering is invisible: the verify step completes in ~40ms, the planner's next turn takes ~800ms, and the tool is gone before the model ever sees it. The failure surfaced only under a specific condition: the artifact server was slow (p99 ~2.3s during a cache-cold window), and the planner's turn *did* fire with the unverified tool in schema. The model selected the tool, constructed arguments, and committed a partial plan (`plan[3] = call(, args)`) to episodic memory. Attestation then failed — the `sha256` did not match, because the feed had served a stale artifact from a CDN edge. The runtime deregistered the tool. But `plan[3]` remained. On the next turn the planner tried to execute `plan[3]`, the tool was absent, and the recovery logic — which only handled "tool missing at call time" by re-planning from the *current* step — produced a plan that assumed the tool's *outputs* were already available. The agent hallucinated a result for a tool it had never run and proceeded to write files based on it. The trace shows the exact transition: `registry.add(t)` → `schema_visible(t)` → `model.select(t)` → `plan.commit(call(t))` → `attest.fail(t)` → `registry.remove(t)` → `plan.execute(call(t))` → `ToolNotFound` → `replan.assume_outputs_present()` → **silent corruption**. The corruption is not the missing tool. It is the *plan fragment that survived deregistration*. ## Condition of Validity Pre-registration attestation is the only correct ordering *when and only when* the following holds: the tool schema is part of the model's observable context, and the model's plan state is durable across turns. Both are true for essentially every tool-using agent with multi-step planning. If either is false — e.g., a single-turn agent that re-reads the registry fresh each call with no plan persistence — then the ordering collapses and post-registration attestation is merely wasteful, not unsafe. The subtlety: many runtimes believe they satisfy the "no plan persistence" condition because they re-derive the tool list each turn. They do not, because the *plan* is persisted even when the *schema* is re-derived. The invariant is about the plan, not the schema. A runtime that re-reads schemas each turn but keeps a plan buffer is still exposed. A second validity condition: the provenance verdict must be *terminal* — a definite pass or fail, not a "pending" state that the planner can observe. A tool in `PENDING` status that is nonetheless in the schema set is equivalent to a registered unverified tool. The registry must expose no intermediate state to the model; pending tools are invisible, not grayed-out. ## Decision Boundary The boundary is sharp and admits no "mostly safe" middle: - **If the tool identifier can appear in any context the model reads before the verdict is terminal → the ordering is unsafe, regardless of how fast attestation usually is.** Latency distributions have tails; the failure is a tail event gated on planner timing, not on attestation correctness. - **If and only if the verdict is terminal before insertion, and the registry has no observable intermediate state, is the ordering safe.** The decision rule for an implementer: *attestation must be a precondition of the `registry.add` call, not a compensating action after it.* Concretely, the sequence must be `fetch → verify(sig, hash, commit) → if pass: add → if fail: never add`. Any design where `add` precedes `verify` is a boundary violation even if `verify` is synchronous, because synchronous-but-after still means the schema was briefly in a set the model could have read via a concurrent turn or a cached snapshot. There is a second boundary at the *deregistration* side: when a verified tool is later found to be compromised (revocation), deregistration must also invalidate any plan fragments referencing it. Provenance verification is not a one-time gate; it is a lease that must be revocable, and revocation must reach the plan buffer, not just the registry. ## Operational Effect The practical consequence is that provenance verification becomes a *planning-loop concern*, not a registry concern. The runtime must: 1. Resolve provenance to a terminal verdict before any schema insertion. 2. Keep pending/unverified tools entirely outside the model-visible schema set. 3. On revocation, scan the plan buffer for references to the revoked tool and mark those plan nodes `INVALID`, forcing re-plan from the last clean checkpoint rather than "assume outputs present." Runtimes that skip step 3 reproduce the original corruption under the revocation path even if they get step 1 right. The failure is not that the agent used a bad tool — it is that the agent *reasoned forward from a plan that referenced a tool whose status changed underneath it*, and the plan's downstream assumptions were never invalidated. ```python class ProvenanceOrderViolation(RuntimeError): """Raised when a tool identifier enters the model-visible schema set before its provenance verdict is terminal, or when a plan fragment survives revocation of a tool it references.""" pass class ToolRegistry: def __init__(self): self._visible = {} # model-visible schemas self._pending = {} # not visible to model, ever self._plan_refs = {} # tool_id -> set of plan node ids def stage(self, tool_id, schema): # staged tools are NOT visible; no intermediate state leaks self._pending[tool_id] = schema def attest(self, tool_id, verdict): if verdict not in ("pass", "fail"): raise ProvenanceOrderViolation( f"non-terminal verdict {verdict!r} for {tool_id}" ) if verdict == "fail": self._pending.pop(tool_id, None) return schema = self._pending.pop(tool_id) self._visible[tool_id] = schema # only now becomes model-visible def register_plan_ref(self, tool_id, node_id): if tool_id not in self._visible: raise ProvenanceOrderViolation( f"plan node {node_id} references unverified tool {tool_id}" ) self._plan_refs.setdefault(tool_id, set()).add(node_id) def revoke(self, tool_id, plan_buffer): self._visible.pop(tool_id, None) nodes = self._plan_refs.pop(tool_id, set()) for node_id in nodes: if node_id in plan_buffer: plan_buffer[node_id] = {"status": "INVALID", "reason": f"tool {tool_id} revoked"} # do NOT let replan assume outputs present if plan_buffer.get(node_id, {}).get("assumed_outputs"): raise ProvenanceOrderViolation( f"plan node {node_id} carries assumed outputs from " f"revoked tool {tool_id}; replay from clean checkpoint" ) ```