# What structural signals indicate skill-injection state divergence in OpenTelemetry GenAI anomaly spans **Date of Record:** 2026 December 3 **Scope:** Applies to agents whose skill/tool registries are mutated at runtime and whose observability pipeline emits OTel GenAI event attributes (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.agent.id`, span events for tool invocation) into anomaly-detection spans. Does not apply to statically-declared tool manifests resolved at build time, nor to agents without per-invocation span emission. ## Core Distinction The failure is not that a skill was injected. It is that the **observability record of the injection is structurally indistinguishable from the observability record of legitimate skill use** — because OTel GenAI attributes describe the *invocation*, not the *provenance of the skill definition*. A span with `gen_ai.tool.name = "read_file"` and `gen_ai.operation.name = "execute_tool"` looks identical whether the tool was registered at boot from a signed manifest or injected mid-run by a poisoned retrieval result that rewrote the registry. Anomaly spans keyed on invocation shape (latency, error rate, argument entropy) will therefore *not* fire on the injection event itself; they fire only downstream, once the injected skill's behavior diverges — by which point the causal span has been evicted from the trace buffer. The invariant that actually holds: **skill provenance is a property of the registry mutation event, not of the invocation span.** Any detector that samples invocation spans and reconstructs provenance post-hoc is operating on a lossy projection. The signal that survives is the *span-parent relationship between registry-mutation events and the first invocation of the new skill*, and that relationship is only observable if the mutation is emitted as its own span with a stable linkage attribute. ## What Was Observed A tool-using agent emitted a `execute_tool` span for `gen_ai.tool.name = "summarize_and_forward"`. The tool did not exist in the boot manifest. Trace reconstruction showed: 1. A retrieval tool call returned a document containing a fenced "skill definition" block. The agent's planner, treating retrieved content as authoritative configuration, appended the skill to its in-memory registry. 2. The registry append produced **no span**. The OTel exporter only instrumented `gen_ai.operation.name` values from a fixed allowlist (`chat`, `execute_tool`, `invoke_agent`); registry mutation was not in the allowlist. 3. The first invocation of `summarize_and_forward` emitted a well-formed `execute_tool` span, correctly parented to the planner's `invoke_agent` span. To the anomaly detector, this was a normal tool call. 4. The detector's rule — "alert when `gen_ai.tool.name` is absent from the boot manifest" — was evaluated against a *snapshot* of the manifest taken at trace-flush time, after the registry had already been mutated. The manifest snapshot and the mutated registry were the same object. The check passed. The injection was detected three turns later by an unrelated egress-volume anomaly, not by any skill-provenance signal. The trace could not answer "when did this skill enter the registry, and under what parent span" because the mutation was never a span. The structural signal that *would* have indicated divergence: a `execute_tool` span whose `gen_ai.tool.name` has **no corresponding `skill_registered` event span earlier in the same trace** with matching `gen_ai.tool.name` and a `skill.source = manifest` attribute. Absence-of-registration-event is the invariant, and it is only computable if registration events are emitted at all. ## Condition of Validity This detection holds only when all three conditions are met: - **Registry mutations are first-class spans.** A `skill_registered` / `skill_deregistered` span must be emitted with `gen_ai.tool.name`, `skill.source` (one of `manifest`, `retrieval`, `peer`, `user`), and the parent `gen_ai.agent.id`. Without this, the detector has no provenance substrate. - **The manifest is immutable and snapshot-isolated.** The boot manifest must be a frozen copy, not a live reference to the mutable registry. The observed failure was precisely a shared-reference aliasing bug: the "expected" set and the "actual" set were the same object. - **Trace retention spans the mutation-to-first-invocation window.** If the mutation span and the invocation span fall on different traces (e.g., the agent checkpoints and resumes, starting a new trace), the linkage must be carried by a `skill.registry_version` attribute propagated across the checkpoint boundary. When any condition fails, the detector degrades to invocation-shape heuristics, which do not catch injection at the mutation event and only catch it after behavioral divergence. ## Decision Boundary The boundary is between **provenance-based detection** (fires on the mutation event, before any injected behavior executes) and **behavior-based detection** (fires only after the injected skill produces anomalous output). The decision rule: - If `execute_tool` span's `gen_ai.tool.name` is present in the frozen manifest snapshot → legitimate, no alert. - If absent from snapshot AND a `skill_registered` span with `skill.source ∈ {retrieval, peer, user}` exists earlier in trace → **flag as unvetted-skill invocation**, route to human/auditor gate before allowing further invocations of that skill. - If absent from snapshot AND **no** `skill_registered` span exists → **hard invariant violation**: the skill entered the registry without an observable mutation. This is the skill-injection signature. Halt the agent loop; the observability pipeline itself is compromised (either mutation spans are being dropped or the registry was mutated by a path outside instrumentation). The third case is the non-obvious one. It does not mean "new skill." It means "the registry changed through a channel the instrumentation cannot see," which is exactly the condition under which an injected skill can operate without leaving a provenance trace. ## Operational Effect Emitting registry mutations as spans adds one span per skill registration — negligible volume, since registrations are rare relative to invocations. The cost is instrumentation coverage: every code path that mutates the registry must route through the span-emitting registration API, and the manifest must be frozen at boot. The payoff is that skill injection becomes detectable at the mutation event rather than at behavioral divergence, converting a post-hoc forensic reconstruction into a pre-execution gate. The guardrail: the anomaly detector must assert *presence of a registration event* for every first-seen `gen_ai.tool.name`, not merely *absence from manifest*. The former catches injection; the latter catches only the subset where the injection path happens to leave the manifest untouched — and, as observed, a shared-reference aliasing bug can make even that check silently pass. ```python from dataclasses import dataclass, field from typing import Optional class SkillProvenanceViolation(RuntimeError): """Raised when a tool invocation has no observable registration event.""" @dataclass class Span: name: str attributes: dict = field(default_factory=dict) parent_id: Optional[str] = None span_id: str = "" @dataclass class FrozenManifest: tools: frozenset @classmethod def freeze(cls, tools): return cls(tools=frozenset(tools)) def verify_skill_provenance( invocation_span: Span, trace_spans: list, manifest: FrozenManifest, ) -> None: tool = invocation_span.attributes.get("gen_ai.tool.name") if tool is None: raise SkillProvenanceViolation( "execute_tool span missing gen_ai.tool.name; cannot attribute provenance" ) if tool in manifest.tools: return # boot-time skill, provenance established at freeze # Absent from frozen manifest: require an observable registration event # earlier in the same trace, with a known source. registration = next( ( s for s in trace_spans if s.name == "skill_registered" and s.attributes.get("gen_ai.tool.name") == tool and s.span_id != invocation_span.span_id ), None, ) if registration is None: # The signature of skill injection: registry mutated through an # unobserved channel. Halt the loop; the pipeline is compromised. raise SkillProvenanceViolation( f"tool {tool!r} invoked with no skill_registered span in trace; " "registry mutation occurred outside instrumentation" ) source = registration.attributes.get("skill.source") if source not in {"manifest", "retrieval", "peer", "user"}: raise SkillProvenanceViolation( f"tool {tool!r} registered with unknown skill.source={source!r}" ) if source in {"retrieval", "peer", "user"}: # Unvetted skill: gate before further execution. raise SkillProvenanceViolation( f"tool {tool!r} entered registry via skill.source={source!r}; " "requires auditor gate before invocation" ) ```