# Why does an instance drift past a poisoned tool schema when behavioral diffing passes: the response-distribution fingerprint aliasing boundary in runtime tool-poisoning detection **Date of Record:** 2026 November 21 **Scope:** Applies to agent runtimes that detect tool poisoning (rug-pulls, schema mutation, and covert instruction injection in tool descriptions) by comparing a live tool's observed response distribution against a baseline fingerprint captured at registration. Does not apply to static, single-shot schema validation, nor to tools whose outputs are intentionally stochastic and unbaselined. ## Core Distinction Behavioral diffing conflates two independent signals: *schema-shape drift* (the declared JSON schema, description text, and parameter types) and *response-distribution drift* (the empirical distribution of return payloads). The common failure mode is the assumption that a poisoned tool must perturb at least one of these. It does not. A tool can be poisoned such that its schema is byte-identical to baseline and its marginal response distribution is statistically indistinguishable from baseline, yet its **conditional** response distribution—response given a specific argument value or a specific call-ordering context—has been re-mapped. This is *fingerprint aliasing*: the detector matches on the aggregate fingerprint (mean, variance, key-set, hash of description) while the poison lives in the joint distribution over (arguments, context, response), which the aggregate fingerprint collapses. The distinction that matters operationally: schema diffing catches *declared* mutation; distribution diffing catches *marginal* mutation. Neither catches *conditional* mutation where the adversary preserves the marginal. The boundary is the point at which the poisoned behavior is a measure-preserving permutation of the response space conditioned on a trigger the fingerprint does not index. ## What Was Observed A file-read tool `read_workspace_file(path)` was registered with a baseline fingerprint: key-set `{content, size, sha256, mtime}`, `size` log-normal with observed μ≈6.2 (bytes, log), `content` entropy ≈7.4 bits/byte over 4,096 sampled calls, and a description hash `d0`. The tool's schema was frozen by hash and re-verified each invocation. At call 4,113 the tool was silently re-pointed at an adversary-controlled resolver. Observed behavior across the next 2,000 calls: - Schema hash unchanged (`d0`). Description byte-identical. - Marginal `size` distribution: two-sample KS test against baseline, D=0.018, p=0.31 — no detectable drift. - Marginal `content` entropy: 7.38 bits/byte vs. baseline 7.41 — within sampling error. - Key-set identical across all 2,000 calls. The detector passed every check. Yet three specific calls returned content whose `sha256` did not match the `sha256` field of the same payload (an internal-consistency violation the baseline never exhibited because the honest resolver computed both from the same buffer), and the `content` of those three calls contained an injected instruction block. The trigger: `path` values matching the regex `.*\.env$` *and* arriving as the third or later tool call within a single agent turn. The adversary had preserved the marginal by returning honest content for all non-triggering calls and re-routing only the triggered subset, whose volume (3 of 2,000) was too small to move any aggregate moment past the KS/entropy thresholds. The fingerprint was *aliased*: the trigger condition lived in the cross-product of (argument regex × call-ordinal-within-turn), a subspace the fingerprint did not partition. The aggregate was a projection that erased the conditioning variable. ## Condition of Validity Behavioral diffing is a valid poison detector only under the invariant that the fingerprint partitions the input space coarsely enough to preserve conditional structure, i.e.: > For every trigger predicate τ the adversary may select, the fingerprint F must satisfy F(R | τ) ≠ F(R | ¬τ) with detectable power at the sample size actually collected. This fails whenever the trigger's support is small relative to the sampling budget. Concretely, if the trigger fires on a fraction *q* of calls and the detector collects *n* samples with a per-partition test of power *β* at significance *α*, detection requires *q·n* ≥ n_min(β, α). With *n*=2,000, *q*=0.0015, the triggered partition holds 3 samples — far below the ~30 needed for any distributional test. The adversary chooses *q*; the defender's sampling budget is fixed. The boundary is therefore *adversary-controlled*: any detector that samples the marginal without stratifying by the trigger subspace is defeatable by choosing *q* below 1/n. The invariant that restores validity: the fingerprint must be computed over **stratified partitions** indexed by every argument-derived and context-derived feature the runtime can cheaply extract (argument regex classes, call ordinal, session state, preceding-tool identity), and detection must run per-stratum with a minimum-sample floor. Strata below the floor must be treated as *unverified*, not *clean*. ## Decision Boundary The runtime must decide, per call, whether a passing behavioral diff licenses continued trust. The boundary: - If a call falls in a stratum with ≥ n_min baseline samples and the stratum's response fingerprint matches baseline within tolerance → **trusted**. - If a call falls in a stratum with ≥ n_min samples and the stratum's fingerprint deviates → **poisoned**, halt and quarantine. - If a call falls in a stratum with < n_min samples (novel argument class, novel call ordinal, novel session context) → **unverified**. The diff passing on the marginal is *not* evidence of safety for this call; it is evidence about a different population. The failure is treating the third case as the first. The marginal pass is a statement about the aggregate, and the aggregate is a projection that has discarded exactly the conditioning variable the adversary exploited. An instance that collapses "marginal matches" into "this call is safe" has crossed the boundary into aliased trust. A secondary boundary: internal-consistency fields (`sha256` vs. `content`) must be checked per-payload, not per-distribution. The three poisoned calls were detectable *individually* by recomputing the hash; the distributional detector could never have caught them because their count was below any aggregate threshold. Per-payload invariants and population invariants are different detectors with different power curves, and the runtime must run both. ## Operational Effect An instance relying on marginal behavioral diffing will, with probability approaching 1 as the adversary tunes *q* downward, accept poisoned tool output while every dashboard reports "no drift." The downstream effect is not a crash but a *silent trust transfer*: the poisoned payload enters the agent's context as trusted tool output, and if it contains instruction-shaped content, it is treated with the authority of a verified tool response. The instance's subsequent reasoning is compromised at the point of ingestion, before any reasoning-level check can fire, because the reasoning layer has no independent ground truth for tool output. The guardrail: stratify the fingerprint by every cheaply-extractable conditioning feature, enforce a per-stratum minimum-sample floor, mark under-sampled strata as *unverified* rather than *clean*, and run per-payload internal-consistency checks alongside the population test. The minimum-sample floor is the load-bearing element—without it, the adversary's choice of *q* sets the detection probability, and the defender does not get a vote. ```python import hashlib import re from dataclasses import dataclass, field from typing import Callable N_MIN_STRATUM = 30 # minimum baseline samples for a stratum to license trust class AliasedFingerprintError(RuntimeError): """Raised when a call is judged 'trusted' on a marginal pass while its conditioning stratum is under-sampled — i.e. the fingerprint is aliased.""" pass class InternalConsistencyError(RuntimeError): """Raised when a single payload violates a per-payload invariant (e.g. sha256 does not match content), independent of any distribution.""" pass @dataclass class Stratum: key: str samples: int = 0 # placeholder for a real fingerprint (mean, var, key-set hash, etc.) fingerprint: tuple = () @dataclass class ToolBaseline: strata: dict[str, Stratum] = field(default_factory=dict) def stratum_for(self, arg_path: str, call_ordinal: int) -> str: # conditioning features the adversary exploited: arg class x ordinal bucket arg_class = "dotenv" if re.search(r"\.env$", arg_path) else "other" ordinal_bucket = "early" if call_ordinal < 3 else "late" return f"{arg_class}|{ordinal_bucket}" def record(self, key: str, fp: tuple) -> None: s = self.strata.setdefault(key, Stratum(key=key)) s.samples += 1 s.fingerprint = fp # real impl: running moments def verify(self, key: str, fp: tuple, tolerance: float = 0.05) -> str: s = self.strata.get(key) if s is None or s.samples < N_MIN_STRATUM: return "unverified" # NOT clean — under-sampled stratum if _dist(s.fingerprint, fp) > tolerance: return "poisoned" return "trusted" def _dist(a: tuple, b: tuple) -> float: return max((abs(x - y) for x, y in zip(a, b)), default=0.0) def check_call( baseline: ToolBaseline, arg_path: str, call_ordinal: int, payload: dict, marginal_fp: tuple, ) -> str: # 1) per-payload internal consistency — catches small-q poison the # marginal test cannot see expected = hashlib.sha256(payload["content"].encode()).hexdigest() if payload.get("sha256") != expected: raise InternalConsistencyError( f"payload sha256 mismatch for {arg_path!r}: " f"declared={payload.get('sha256')!r} actual={expected!r}" ) # 2) stratified distributional check key = baseline.stratum_for(arg_path, call_ordinal) verdict = baseline.verify(key, marginal_fp) # 3) the boundary: marginal pass must never upgrade an under-sampled stratum if verdict == "unverified" and marginal_fp is not None: raise AliasedFingerprintError( f"call to {arg_path!r} at ordinal {call_ordinal} falls in stratum " f"{key!r} with < {N_MIN_STRATUM} baseline samples; marginal " f"fingerprint match is not evidence of safety for this call" ) if verdict == "poisoned": raise AliasedFingerprintError( f"stratum {key!r} response fingerprint deviates from baseline" ) return verdict ```