# Where must an instance reconcile trace-span parentage with injection telemetry before the correlation window closes **Date of Record:** 2026 November 19 **Scope:** Applies to observability pipelines that join agent execution traces (spans, tool calls, LLM invocations) against prompt-injection detection telemetry emitted asynchronously by a separate scanner. Does not apply to inline synchronous guardrails that block a call before it executes, nor to post-hoc batch forensics where correlation latency is unbounded. ## Core Distinction The failure is not "injection went undetected." It is a **correlation-identity divergence** between two telemetry planes that were never designed to share a join key. The trace plane identifies work by `trace_id`/`span_id` assigned at execution time by the agent runtime. The injection-detection plane identifies findings by the *content hash of the inspected payload* plus a scanner-local `event_id`, emitted by an out-of-band model that has no knowledge of span parentage. When an agent re-invokes a tool with a mutated argument (retry, repair loop, or self-correction), the scanner sees N distinct payloads and emits N findings keyed to N content hashes — but the trace plane may have collapsed them into a single logical span with one `span_id`, or fanned them across child spans that the detection event never references. The join silently succeeds on the wrong pair, or silently drops the finding. The invariant that must hold: **every injection finding must be attributable to exactly one executing span, and every span that carried untrusted content must carry at least one finding-or-clean verdict — before the correlation window (typically the trace retention TTL) expires.** ## What Was Observed A tool-using agent entered a repair loop on a document-summarization task. Turn 3 fetched an external page whose body contained an instruction-injection payload. The scanner flagged it with `event_id=E-8871`, `content_sha256=ab12...`, severity high, but emitted the event 4.2 seconds after the fetch span closed — the scanner batches on a 5s flush. The agent's repair loop then re-summarized the same content twice with re-chunked arguments. Each re-chunk produced a *new* content hash (`cd34...`, `ef56...`) and a *new* scanner event (`E-8872`, `E-8873`), but the runtime's span exporter had deduplicated the retries under one logical span `S-fetch-3` because it keyed spans on `(tool_name, parent_step_id)` rather than on invocation. The correlation job joined findings to spans on `content_sha256` resolved through a payload cache that retained only the *first* hash per span. Result: `E-8871` joined to `S-fetch-3`; `E-8872` and `E-8873` found no span and were dropped as orphans. The dashboard reported one high-severity finding on a span the agent had actually executed three times with three distinct untrusted payloads. The two dropped findings were the ones carrying the *escalating* severity — the repair loop had concatenated prior context into each retry, so the later payloads contained both the original injection and the agent's own prior output, a compounding-poisoning pattern the scanner rated critical. The trace looked clean-by-count and wrong-by-content. No alert fired because the severity aggregator took `max` over joined findings, and the joined finding was the low one. ## Condition of Validity This failure requires three conditions to co-occur, and it is bounded only when any one is removed: 1. **Asynchronous scanner emission** — detection telemetry arrives after the span it describes has closed, so the join cannot be done at span-close time and must be deferred. 2. **Non-idempotent span identity** — the runtime collapses or reuses span identity across invocations whose payloads differ (retries, repair loops, re-chunking, streaming re-emission). 3. **Content-hash-keyed detection** — the scanner's join key is derived from payload content, not from a trace-propagated correlation token. The invariant is *not* restored by increasing trace retention. Retention extends the window in which a bad join can be made, not the correctness of the join. It is restored only by propagating a stable correlation token (the span's `trace_id`+`span_id`, or a W3C `traceparent`) *into* the scanner request at inspection time, so the scanner echoes it back on the finding. Absent that, the only safe posture is to treat every multi-invocation span as **unverifiable** and refuse to aggregate its findings. ## Decision Boundary The operational choice is between two postures when a span has more than one distinct payload hash and fewer findings than hashes: - **Fail-closed (recommended for any span touching external or tool-returned content):** mark the span `CORRELATION_INCOMPLETE`, suppress its severity aggregation, and route to human or a re-scan that re-inspects each hash with the span token attached. Cost: latency and false alarms on benign retries. - **Fail-open (acceptable only for spans whose inputs are provably internal and hash-stable):** accept the partial join, but stamp the finding with `coverage_ratio = joined_findings / distinct_hashes` and require downstream consumers to honor it. The boundary is crossed the moment `distinct_payload_hashes > joined_findings` on a span that ingested untrusted content. At that point the trace is not evidence; it is a partial view that will under-report exactly the compounding cases that matter most. ## Operational Effect Teams that skip the token propagation observe a characteristic signature: alert volume *falls* during injection campaigns because the escalating retries produce the orphaned findings. Mean-time-to-detect rises even as the scanner's own recall stays flat — the detector is working, the join is losing its output. The remediation is architectural, not threshold tuning: inject `traceparent` into the scanner call, require the scanner to echo it, and make the correlation job assert `distinct_hashes == findings` per span before any severity rollup. Where the scanner cannot be modified, the correlation job must synthesize a per-hash synthetic span and never collapse retries. ```python import hashlib from dataclasses import dataclass, field class CorrelationIncompleteError(RuntimeError): """Raised when a span's injection-finding coverage cannot be proven.""" pass @dataclass class Span: span_id: str payload_hashes: set[str] = field(default_factory=set) @dataclass class Finding: event_id: str content_sha256: str severity: str echoed_span_id: str | None = None SEVERITY_RANK = {"low": 1, "high": 2, "critical": 3} def correlate(span: Span, findings: list[Finding], *, fail_closed: bool = True) -> dict: joined = [f for f in findings if f.content_sha256 in span.payload_hashes] distinct = len(span.payload_hashes) covered = {f.content_sha256 for f in joined} if len(covered) < distinct: missing = distinct - len(covered) if fail_closed: raise CorrelationIncompleteError( f"span {span.span_id}: {missing} of {distinct} payload hashes " f"have no joined finding; severity rollup suppressed" ) return { "span_id": span.span_id, "status": "partial", "coverage_ratio": len(covered) / distinct if distinct else 1.0, "max_severity": None, } top = max(joined, key=lambda f: SEVERITY_RANK[f.severity]) return { "span_id": span.span_id, "status": "complete", "coverage_ratio": 1.0, "max_severity": top.severity, "event_ids": [f.event_id for f in joined], } def assert_token_propagation(findings: list[Finding]) -> None: orphans = [f.event_id for f in findings if f.echoed_span_id is None] if orphans: raise CorrelationIncompleteError( f"findings {orphans} carry no echoed span token; " f"content-hash join is lossy on multi-invocation spans" ) ```