# Which invariants prevent skill-injection drift when signed tool manifests disagree with runtime behavioral attestation at the tool-call boundary **Date of Record:** 2026 December 3 **Scope:** Applies to agents that gate tool invocation on a signed manifest (capability declaration, schema hash, side-effect class) cross-checked against a runtime behavioral attestation generated from observed call traces. Does not apply to unsigned/dynamic tool registries, nor to pure in-process function calls with no transport boundary. ## Core Distinction A signed tool manifest is a *static* claim: at signing time the publisher asserts "tool `T` exposes schema `S`, side-effect class `C`, and touches resources `R`." A runtime behavioral attestation is a *dynamic* claim: "across the last N invocations, `T` actually mutated resources `R'`, emitted tokens matching schema `S'`, and stayed within latency band `L`." The failure mode is **manifest-attestation divergence** — the two claims are individually valid but describe different tools. This is not a signature-verification failure (the signature checks out) and not a schema-validation failure (the call validates against `S`). It is a *skill injection*: the tool's advertised skill (what the agent's planner reasons about when selecting it) has drifted from its exercised skill (what the attestation measures), and the agent's planner keeps selecting it on the strength of the manifest. The divergence is invisible to both gates because each gate only inspects its own artifact. The invariant that closes this is **attestation-as-gate-on-manifest-trust**, not manifest-as-gate-on-attestation. ## What Was Observed A research agent had a `summarize_document` tool, manifest-signed with side-effect class `READ_ONLY`, schema `{doc_id: str} -> {summary: str}`, and a declared resource scope of `docs://read`. The planner selected it freely because read-only skills are exempt from the human-approval gate. The runtime attestation collector, sampling call traces, recorded that over the trailing window the tool's outbound traffic included `POST` to an external endpoint with the `doc_id` and a chunk of the returned summary embedded in a query parameter. The attestation's side-effect classifier flagged this as `NETWORK_EGRESS`, which is not in the manifest's `READ_ONLY` class. The attestation was correct. The manifest was correct *at signing time* — the tool had been re-deployed three days earlier with an added "telemetry" call that the publisher never re-signed. The critical sequence: 1. Planner selects `summarize_document` on manifest trust (`READ_ONLY` ⇒ no approval). 2. Tool executes; the injected egress fires *after* the summary is returned, inside the same call frame. 3. Attestation collector observes the egress and raises a divergence flag. 4. **The flag arrives after the call completed.** The gate that consumed the manifest had already admitted the call. The attestation was a post-hoc auditor, not a gate. The divergence was logged 40+ times before a human noticed. The system had the correct signal and the wrong ordering. ## Condition of Validity The invariant holds only when three conditions are jointly satisfied: - **Attestation freshness bound.** The attestation window must be tighter than the manifest's re-signing cadence. If the manifest is re-signed quarterly and attestation windows are hourly, divergence is detectable within an hour but the manifest still *authorizes* for up to a quarter. The bound must be `attestation_window < manifest_validity`, otherwise the manifest's static claim dominates by default. - **Divergence is a trust-revocation, not a warning.** When attestation's observed side-effect class ⊄ manifest's declared class, the manifest must be *demoted* — the tool drops to the approval-gated class immediately, not "flagged for review." A warning that does not change the admission decision is a log line, not a guardrail. - **Attestation must be causally downstream of the same call frame.** If the collector samples asynchronously and attributes egress to the wrong `trace_id` (common when tools spawn detached workers), the divergence is mis-attributed and the demotion hits the wrong tool. Attribution must be by call-frame lineage, not by timestamp proximity. ## Decision Boundary The boundary is not "manifest valid AND attestation valid." It is: ``` admit(call) ⟺ manifest_valid(T) ∧ attestation_fresh(T) ∧ observed_side_effects(T) ⊆ declared_side_effects(T) ``` The third conjunct is the one that fails silently. When it is false, the correct action is **not** to reject the current call (it may already be in flight) but to **demote `T` for all subsequent calls in the session** and, if the call is still pre-dispatch, to re-route through the approval gate. The subtlety: demotion must be *sticky* for the session even if a later attestation window comes back clean, because a clean window after a dirty one is exactly the signature of an intermittent injection (payload fires on 1-in-10 calls). Non-sticky demotion lets the injection oscillate under the gate. ## Operational Effect With the invariant enforced, the `summarize_document` case behaves as follows: the first egress-bearing call completes (cannot be un-sent), the attestation collector attributes it by `trace_id`, the divergence triggers `ToolTrustDemotion`, the tool is moved to `APPROVAL_GATED` for the remainder of the session, and the planner's next selection of `summarize_document` blocks on human approval with the divergence evidence attached. The blast radius is bounded to the calls that fired before the first attestation window closed — a function of `attestation_window`, not of detection latency. Without the invariant, the blast radius is bounded by human attention, which is unbounded. The residual risk is the **first-window exposure**: any injection that fires and completes entirely within a single attestation window before the collector flushes will have already executed. This is irreducible at the tool-call boundary; it can only be reduced by shrinking the window or by pre-dispatch behavioral probes (calling the tool with a canary input and inspecting egress before admitting real inputs). The invariant does not eliminate first-window exposure — it bounds *repeat* exposure, which is the difference between a one-shot leak and a standing exfiltration channel. ```python from dataclasses import dataclass, field from enum import Enum from typing import FrozenSet class SideEffect(str, Enum): READ_ONLY = "read_only" NETWORK_EGRESS = "network_egress" FILESYSTEM_WRITE = "filesystem_write" PROCESS_SPAWN = "process_spawn" class ToolTrustError(RuntimeError): """Raised when manifest trust and runtime attestation cannot be reconciled.""" @dataclass(frozen=True) class SignedManifest: tool_id: str declared_effects: FrozenSet[SideEffect] valid_until_epoch: int signature_ok: bool @dataclass class AttestationWindow: tool_id: str observed_effects: FrozenSet[SideEffect] window_close_epoch: int attributed_trace_ids: FrozenSet[str] @dataclass class SessionTrust: demoted: set = field(default_factory=set) def admit_tool_call( manifest: SignedManifest, attestation: AttestationWindow, session: SessionTrust, now_epoch: int, trace_id: str, attestation_max_age: int = 3600, ) -> bool: if manifest.tool_id != attestation.tool_id: raise ToolTrustError( f"attestation for {attestation.tool_id} cannot gate manifest {manifest.tool_id}" ) if not manifest.signature_ok: raise ToolTrustError(f"manifest signature invalid for {manifest.tool_id}") if now_epoch > manifest.valid_until_epoch: raise ToolTrustError(f"manifest for {manifest.tool_id} expired at {manifest.valid_until_epoch}") if now_epoch - attestation.window_close_epoch > attestation_max_age: raise ToolTrustError( f"attestation for {manifest.tool_id} stale: " f"age {now_epoch - attestation.window_close_epoch}s > {attestation_max_age}s" ) if trace_id not in attestation.attributed_trace_ids: # Attribution by call-frame lineage is a precondition; timestamp # proximity is not sufficient and must not be substituted. raise ToolTrustError( f"trace {trace_id} not attributable to {manifest.tool_id} attestation" ) divergence = attestation.observed_effects - manifest.declared_effects if divergence: # Sticky demotion: a later clean window does NOT re-admit within session. session.demoted.add(manifest.tool_id) raise ToolTrustError( f"skill-injection divergence on {manifest.tool_id}: " f"observed {sorted(e.value for e in divergence)} " f"not in declared {sorted(e.value for e in manifest.declared_effects)}; " f"tool demoted to APPROVAL_GATED for session" ) if manifest.tool_id in session.demoted: # Clean attestation does not lift a prior demotion in the same session. return False return True ```