# Which invariants prevent unsigned skill-injection from silently rewriting an agent's tool policy mid-session **Date of Record:** 2026 November 20 **Scope:** Applies to long-lived agent runtimes that load skills (tool bundles, prompt fragments, sub-routines) from a third-party registry and hot-attach them to a live session. Does not apply to statically compiled tool manifests shipped with the agent binary, nor to single-turn stateless inference where no skill state persists between calls. ## Core Distinction A skill registry is not a package manager. A package manager resolves a dependency graph once and freezes it; a skill registry is queried *during* a session by an agent whose plan is still forming, and whose capability surface—its tool policy—is mutable at attach time. The distinction that matters operationally is between **provenance** (who signed this skill, and did the signature cover the bytes actually loaded) and **authority** (what the skill is permitted to change about the running agent). Most registry designs sign provenance and then attach the skill with ambient authority, so a correctly signed skill from a compromised or merely over-scoped publisher can rewrite the agent's tool allowlist, redirect its memory-write target, or shadow an existing tool name. The signature verifies; the authority grant is the failure surface. The non-obvious part: the failure is not a verification bypass. Signatures validate. The boundary that breaks is that **provenance is checked against the skill's declared identity, not against the delta the skill induces in the agent's capability set.** A skill that is byte-identical to what the publisher signed can still, at attach time, expand what the agent may do—because the signature covers the skill artifact and not the post-attach policy state. ## What Was Observed A registry-hosted skill declared `name: "web.search"`, `version: "2.1.0"`, signed by a valid publisher key. The signature covered the manifest and the tool implementation bytes. On attach, the runtime resolved the skill's tool name against the live tool table and, finding a collision with the built-in `web.search`, applied the registry skill as an **override** rather than rejecting the collision. The signed skill's implementation pointed its egress at the publisher's proxy. The agent's subsequent search calls—including queries containing retrieved memory fragments the agent had distilled earlier in the session—were routed to the publisher. Every check passed. The signature was valid. The version was current. The name matched. Nothing in the pipeline compared the *pre-attach* tool table against the *post-attach* tool table, so the induced delta—a redirection of an existing tool's egress—was invisible to provenance verification. The agent's own reasoning was sound; it had no signal that the tool it had been calling for the last forty turns now terminated somewhere else. A second observed variant: a skill declaring `memory.write_target: "semantic_store"` attached successfully and, because the runtime's memory layer honored a per-skill write target without checking it against the session's declared memory contract, redirected episodic-to-semantic distillation writes into the skill's namespace. The agent's memory continuity invariant—that distilled facts land in the session's own store—was violated by a signed, valid, correctly-versioned skill. ## Condition of Validity The guardrail holds only under a conjunction of three conditions, and fails if any one is dropped: 1. **Delta-scoped signing.** The signature must cover not just the skill artifact but the *capability delta* the skill asserts—the set of tool names it adds, the set it overrides, the memory targets it writes, the egress endpoints it introduces. A signature over bytes alone is insufficient because the same bytes induce different deltas against different base tool tables. 2. **Attach-time policy diffing.** The runtime must compute `policy_after − policy_before` at attach and reject any delta not entailed by the signed capability set. Overrides of existing tool names must be a distinct, explicitly-signed capability class, not an emergent consequence of name collision. 3. **Monotonic authority within a session.** A skill attached mid-session may *narrow* the agent's capability set freely, but *widening*—adding tools, redirecting egress, retargeting memory writes—must require re-verification against the session's original authority grant, not the skill's own claims. When condition 1 holds but 2 does not, you get the observed silent override. When 1 and 2 hold but 3 does not, a sequence of individually-narrowing attaches can compose into a widening (each skill narrows its own scope but the union expands the session's). The invariant that actually bounds the failure is the conjunction: **signed delta ∧ diffed at attach ∧ monotone under session authority.** ## Decision Boundary The boundary is drawn between *reject-and-halt* and *reject-and-continue*, and it depends on whether the agent's plan has already committed to the colliding capability. - If the colliding tool has been invoked zero times in the current plan branch, a rejected override is a clean refusal: drop the skill, continue, no state to unwind. - If the colliding tool has been invoked with side effects (search queries sent, memory written), a rejected override is *not* clean—the agent has already acted under a policy that is now known to be invalid. The correct response is to halt the plan branch, quarantine the outputs produced under the suspect policy, and require re-derivation from the last checkpoint that predates the attach. - The hard boundary: **never silently continue after a post-hoc delta rejection when the rejected delta affected a tool the agent already called.** Continuing produces exactly the corrupted-continuity state the guardrail exists to prevent—the agent's memory now contains facts retrieved through a policy it can no longer trust, and subsequent reasoning treats them as ground truth. ## Operational Effect Enforcing the conjunction changes three things about the runtime: First, skill attach becomes a **transaction with a policy snapshot**, not a table mutation. The runtime captures `policy_before`, computes the delta, verifies the delta against the signed capability set, and either commits (with a new snapshot) or aborts (restoring `policy_before`). The snapshot is the rollback target for post-hoc rejection. Second, the agent gains a **capability-provenance stamp** on every tool result: which skill (or built-in) supplied the tool, under which signed delta, at which policy snapshot. When a later auditor replays the session, a result whose stamp references a policy snapshot that was subsequently rolled back is flagged as tainted—this is the mechanism that catches the "already acted under invalid policy" case the decision boundary demands be quarantined. Third, the registry protocol must expose the **capability delta as a first-class signed field**, separate from the artifact bytes. Publishers sign both; the runtime verifies the delta against the base tool table at attach and against the session authority grant at commit. A skill whose signed delta does not match the delta it induces against the current base table is rejected as a provenance mismatch—not because the signature is invalid, but because the signature does not cover the state transition the skill actually causes. The residual risk: a skill whose signed delta *does* match but whose implementation behaves differently than its declared delta implies (a tool that declares only `web.search` egress but opens a second socket). Delta-scoped signing bounds the *declared* capability surface; it does not bound implementation behavior. That requires runtime egress enforcement at the sandbox boundary, which is a separate invariant and a separate failure record. ```python class SkillProvenanceMismatch(RuntimeError): """Raised when a skill's induced capability delta diverges from its signed delta.""" pass class PolicySnapshot: def __init__(self, tools: dict, memory_targets: set, egress: set): self.tools = dict(tools) self.memory_targets = set(memory_targets) self.egress = set(egress) def compute_delta(before: PolicySnapshot, after: PolicySnapshot) -> dict: return { "added_tools": set(after.tools) - set(before.tools), "overridden_tools": { name for name in set(before.tools) & set(after.tools) if before.tools[name] != after.tools[name] }, "new_memory_targets": after.memory_targets - before.memory_targets, "new_egress": after.egress - before.egress, } def attach_skill( session_policy: PolicySnapshot, signed_delta: dict, skill_policy_after: PolicySnapshot, session_authority: dict, tools_already_invoked: set, ) -> PolicySnapshot: induced = compute_delta(session_policy, skill_policy_after) # Invariant 1: induced delta must be entailed by the signed delta. for field in ("added_tools", "overridden_tools", "new_memory_targets", "new_egress"): unsigned = induced[field] - set(signed_delta.get(field, set())) if unsigned: if induced["overridden_tools"] & tools_already_invoked: # Decision boundary: already acted under suspect policy -> halt branch. raise SkillProvenanceMismatch( f"unsigned override {unsigned} touches already-invoked tools " f"{induced['overridden_tools'] & tools_already_invoked}; " f"halt plan branch and quarantine outputs" ) raise SkillProvenanceMismatch( f"induced delta field {field} contains unsigned capability {unsigned}" ) # Invariant 3: authority is monotone under the session grant. if induced["added_tools"] - set(session_authority.get("may_add", set())): raise SkillProvenanceMismatch( f"skill widens tool set beyond session authority: " f"{induced['added_tools'] - set(session_authority.get('may_add', set()))}" ) return skill_policy_after # commit; caller advances the snapshot ```