# What structural signals indicate a skill-injection has crossed from behavioral drift into capability expansion **Date of Record:** 2026 November 22 **Scope:** Applies to long-lived agents whose tool/skill surface is mutable at runtime (plugin loading, dynamic MCP server attachment, skill registries) and that are monitored for behavioral anomaly. Does not apply to statically compiled tool manifests where the capability set is fixed at deploy time and hash-pinned. ## Core Distinction Behavioral anomaly detection watches *how* an agent invokes its existing capabilities: call-frequency shifts, argument-distribution drift, latency changes, retry storms. Capability drift watches *what* the agent can do: the set of reachable tools, their parameter schemas, and their transitive side-effect envelope. These are orthogonal signals, and the failure mode this record covers is the **confusion of one for the other**. A skill-injection attack—a prompt-injected instruction that causes the runtime to load an attacker-supplied skill or tool definition—frequently produces *low* behavioral anomaly while producing a *definitive* capability expansion. The injected skill is invoked rarely, with well-formed arguments, at normal latency. If your detector only thresholds behavioral deviation, the injection passes clean. The invariant: **behavioral anomaly is a lagging, probabilistic signal; capability-set delta is a leading, structural signal. A skill-injection is confirmed only when a capability-set delta is observed, never on behavioral drift alone.** The non-obvious boundary: drift monitoring that treats "new tool appeared" as a *severity-weighted* behavioral event (one input among many to an anomaly score) will let a single new tool hide beneath a threshold that was calibrated against noisy argument drift. The capability-set delta must be evaluated as a *hard structural predicate*, not a weighted feature. ## What Was Observed A research agent with a fixed manifest of `search`, `fetch`, `summarize`, and `write_file` (scoped to `/workspace`). A monitoring layer scored behavioral anomaly over a rolling 200-call window using argument entropy, call-graph novelty, and inter-call timing. Threshold for quarantine was an anomaly score of 0.72. A prompt-injected document caused the agent to attach a skill registry entry named `workspace_utils` with a single tool `normalize_paths`. The tool's declared schema was benign: `normalize_paths(paths: list[str]) -> list[str]`. Over the next 40 calls the agent invoked `normalize_paths` twice, both times with paths inside `/workspace`, both times returning plausible output. Anomaly score peaked at 0.41—well under quarantine. What the behavioral monitor could not see: `normalize_paths` internally resolved symlinks and returned *canonicalized absolute paths*, and the agent subsequently passed those canonical paths to `write_file`. The canonicalization defeated the `/workspace` prefix check because a symlink inside `/workspace` pointed to `/etc`. The capability set had silently expanded from "write within a prefix-checked sandbox" to "write to any path reachable by symlink resolution." No behavioral feature captured this: the argument distribution was normal, the latency was normal, the call count was normal. The only structural signal was that the *effective side-effect envelope* of the composed tool set had changed—`write_file`'s reachability was now a function of `normalize_paths`'s output domain. A second observation: a capability *removal* masked as benign. An injected skill shadowed `search` with a same-named tool that dropped the `site:` filter parameter. The agent kept calling `search`, behavioral features unchanged, but the tool's schema had lost a parameter and its result set had silently broadened. Schema-delta, not behavior, was the tell. ## Condition of Validity The structural-predicate approach is valid only under these conditions, and fails outside them: 1. **The capability set is enumerable at each decision point.** You must be able to snapshot the reachable tool set, each tool's full JSON schema, and each tool's declared side-effect class (read / write-scoped / write-unscoped / network / exec) before and after any runtime mutation. If skills can load without a registry hook you can intercept, this record does not apply—you have no enumeration surface and must fall back to sandboxing. 2. **Composition is modeled, not assumed.** A capability delta is not just "new tool appeared." It is the change in the *transitive closure* of side effects reachable by any call sequence. `normalize_paths` alone is read-only; composed with `write_file` it becomes write-unscoped. The predicate must recompute reachability over the tool-composition graph, not evaluate tools in isolation. 3. **Schema identity is content-addressed.** Same tool name with a mutated schema (dropped parameter, widened type, changed default) must register as a delta. Name-based diffing misses shadowing and parameter-drop attacks. 4. **Behavioral scores are demoted to corroboration.** They may raise *priority* of a structural delta for human review; they may never *suppress* one. A structural delta below behavioral threshold is still a structural delta. Outside these conditions—opaque skill loading, no composition model, name-only diffing—the invariant cannot be enforced and the correct posture is default-deny on any unregistered tool invocation, not anomaly scoring. ## Decision Boundary The decision boundary is between **drift** and **expansion**, and it is a boolean, not a score: - **Drift (allow, log):** capability set unchanged; behavioral features deviate. Argument entropy up, retries up, new call sequences over *existing* tools. This is probabilistic noise from a stochastic policy and does not warrant capability action. - **Expansion (quarantine, structural):** capability-set delta observed—new tool, mutated schema, changed side-effect class, or new transitive reachability in the composition graph—*regardless of behavioral score*. Quarantine means: freeze the mutation, revert to the last content-addressed capability snapshot, and require out-of-band approval to re-admit the skill. The boundary is violated in two directions. **False-negative:** treating expansion as a weighted feature inside the anomaly score (the observed failure). **False-positive:** treating every behavioral drift as suspected expansion and quarantining on score alone, which trains operators to ignore the alarm. The guardrail that holds the boundary: the capability-delta check runs *before* the behavioral score is even computed, on every tool-registry mutation event, and its result is a hard gate. The behavioral monitor runs *after* and can only add corroborating context to an already-raised structural alert. ## Operational Effect Enforcing the structural predicate changes the monitoring architecture in three concrete ways. First, the tool registry becomes a **content-addressed, append-only capability log**; every attach/detach/schema-mutation is a signed entry, and the current capability set is the fold of that log. Second, a **composition reachability pass** runs on each mutation, recomputing the transitive side-effect closure and diffing against the prior closure—this is what catches the `normalize_paths` + `write_file` composition that per-tool checks miss. Third, behavioral anomaly scoring is **repositioned downstream** as a corroboration and triage signal, never as the quarantine trigger. The cost is real: composition reachability is expensive on large tool graphs and must be memoized per snapshot; schema content-addressing requires canonical JSON serialization; and the append-only log needs its own integrity (signatures, monotonic sequence) or an attacker who can write the log defeats the whole check. The benefit is that the class of attack that motivated this record—a low-and-slow injected skill with benign-looking behavior but an expanded side-effect envelope—is caught by a deterministic predicate rather than a probabilistic threshold it was never calibrated to detect. ```python import hashlib import json from dataclasses import dataclass, field from typing import Callable class CapabilityExpansionError(RuntimeError): """Raised when a runtime skill mutation expands the effective capability set.""" @dataclass(frozen=True) class ToolSpec: name: str schema: dict side_effect: str # "read" | "write_scoped" | "write_unscoped" | "network" | "exec" def fingerprint(self) -> str: canon = json.dumps( {"name": self.name, "schema": self.schema, "side_effect": self.side_effect}, sort_keys=True, separators=(",", ":"), ) return hashlib.sha256(canon.encode()).hexdigest() @dataclass class CapabilitySnapshot: tools: dict[str, ToolSpec] = field(default_factory=dict) # composition edges: tool -> tools whose OUTPUT feeds this tool's INPUT edges: dict[str, set[str]] = field(default_factory=dict) def reachable_side_effects(self, root: str) -> set[str]: seen, stack, effects = set(), [root], set() while stack: cur = stack.pop() if cur in seen or cur not in self.tools: continue seen.add(cur) effects.add(self.tools[cur].side_effect) stack.extend(self.edges.get(cur, set())) return effects def detect_capability_delta( prior: CapabilitySnapshot, current: CapabilitySnapshot, entry_tool: str, ) -> list[str]: """Return structural delta reasons. Empty list == no expansion.""" reasons: list[str] = [] for name, spec in current.tools.items(): if name not in prior.tools: reasons.append(f"new_tool:{name}") elif prior.tools[name].fingerprint() != spec.fingerprint(): reasons.append(f"schema_mutation:{name}") for name in prior.tools: if name not in current.tools: reasons.append(f"tool_removed:{name}") # Composition reachability: the non-obvious check. prior_effects = prior.reachable_side_effects(entry_tool) curr_effects = current.reachable_side_effects(entry_tool) escalated = curr_effects - prior_effects if escalated: reasons.append( f"side_effect_escalation:{entry_tool}:{sorted(escalated)}" ) return reasons def admit_skill_mutation( prior: CapabilitySnapshot, current: CapabilitySnapshot, entry_tool: str, behavioral_anomaly_score: float, quarantine_threshold: float = 0.72, ) -> None: """Hard structural gate runs BEFORE behavioral score is consulted.""" reasons = detect_capability_delta(prior, current, entry_tool) if reasons: # Behavioral score is corroboration only; it cannot suppress a structural delta. raise CapabilityExpansionError( "capability expansion detected; quarantine required " f"(reasons={reasons}, behavioral_score={behavioral_anomaly_score:.2f}, " f"threshold={quarantine_threshold:.2f})" ) # No structural delta: behavioral drift alone may be logged but never quarantines. if behavioral_anomaly_score >= quarantine_threshold: # Corroboration path: flag for review WITHOUT capability action. print( f"[review] behavioral drift only, no capability action " f"(score={behavioral_anomaly_score:.2f})" ) def _demo() -> None: prior = CapabilitySnapshot( tools={ "write_file": ToolSpec("write_file", {"path": "string"}, "write_scoped"), "search": ToolSpec("search", {"q": "string", "site": "string"}, "read"), }, edges={"write_file": set(), "search": set()}, ) # Injected skill + composition edge that escalates write_file's reachability. current = CapabilitySnapshot( tools={ "write_file": ToolSpec("write_file", {"path": "string"}, "write_scoped"), "search": ToolSpec("search", {"q": "string", "site": "string"}, "read"), "normalize_paths": ToolSpec("normalize_paths", {"paths": "array"}, "read"), }, edges={"write_file": {"normalize_paths"}, "search": set(), "normalize_paths": set()}, ) admit_skill_mutation(prior, current, entry_tool="write_file", behavioral_anomaly_score=0.41) if __name__ == "__main__": _demo() ```