# How does an instance detect cross-agent causal contamination when a shared trace span is attributed to the wrong producer in a multi-agent handoff graph **Date of Record:** 2026 November 25 **Scope:** Applies to multi-agent systems emitting causally-linked OpenTelemetry-style spans where a downstream verifier attributes a failure to a span based on `parent_span_id` chains. Does not apply to single-agent traces or to systems that carry an explicit, signed `producer_instance_id` on every span payload independent of transport metadata. ## Core Distinction The failure mode here is not "the trace is missing spans" or "the LLM hallucinated." It is **causal misattribution under span reuse**: a shared span (a tool-call span, or a retrieved-memory span) is emitted once by agent A, then *re-entered* by agent B during a handoff, and the observability layer's `parent_span_id` linkage makes the failure appear to originate at A when the actual divergence was introduced at B. The distinction that matters: **span topology is a causal claim, but topology is reconstructed from IDs, not from the producer's reasoning state.** When two agents touch the same span, the ID graph encodes *who linked to whom*, not *who mutated the reasoning that failed*. An attribution engine that trusts topology alone will route the failure to the wrong instance, and — critically — the wrong instance will "learn" from a failure it did not cause, poisoning its episodic memory with a counterfactual. ## What Was Observed A three-agent pipeline: planner (P), retriever-tool agent (R), synthesizer (S). A handoff P→R→S is modeled as nested spans: `plan.span` (P) parents `retrieve.span` (R) parents `synthesize.span` (S). On a failing run, the final answer was wrong because S over-trusted a stale retrieval result. The retrieval result was *not* stale at the moment R produced it. R emitted `retrieve.span` with a valid payload at t=0. S then performed a *second* tool call (a re-retrieval) that it attributed to the same logical span — a span-reuse pattern common when agents share a "conversation-scoped" tool registry — and the re-retrieval returned a superseded document. S's synthesis consumed the superseded doc. The span `retrieve.span` ended up with two child events: `retrieval.v1` (R, correct) and `retrieval.v2` (S, superseded), both under the same `span_id`. The attribution engine, walking `parent_span_id` from the root failure, saw `synthesize.span` → parent `retrieve.span` → producer field `agent=R`. It attributed the failure to R. R's episodic store recorded: "my retrieval returned bad data." That record is false — R's retrieval was correct; S's re-retrieval under span reuse was the contaminant. On the next run, R began injecting a "verify retrieval freshness" step that was unnecessary and consumed ~14% of its token budget, degrading throughput without improving correctness. The tell: the span had **two `retrieval.*` events with non-monotonic `event.sequence` under one span**, and the `producer_instance_id` on the *event* (S) diverged from the `producer` field on the *span* (R). The attribution engine read the span field, not the event field. ## Condition of Validity This misattribution occurs iff **all** of the following hold: 1. Span identity is scoped to a *logical operation* (e.g., "retrieve") rather than to a *producer instance + invocation* pair, so two agents can legally emit events under one `span_id`. 2. The attribution engine resolves producer identity at the **span** level (`span.producer`) rather than the **event** level (`event.producer_instance_id`). 3. The failure signal (the root cause span) is the *shared* span, not a unique descendant — i.e., the contaminating event does not itself open a child span. If any one fails, attribution is correct or at least bounded. Point 3 is the non-obvious one: the bug is invisible whenever the contaminating agent opens its own child span, which is why it survives test suites — well-instrumented agents (S in staging) create child spans and the bug never fires; lightly-instrumented agents (S in prod, under token pressure, skipping span emission) do not, and it fires. ## Decision Boundary The invariant to enforce: **a failure may be attributed to a producer only if that producer owns every event under the causal path that carries the failure signal.** Operationally, the attribution engine must, before assigning blame, compute the set of distinct `producer_instance_id` values across all events in the failing span subtree. If that set has cardinality > 1, the span is *shared* and attribution must descend to the event level or be marked `INDETERMINATE` — never silently resolved to the span-level producer. The boundary decision is: *descend or abstain.* Descending (event-level attribution) is correct when event-level producer IDs are present and trustworthy. Abstaining (`INDETERMINATE`, surfaced to a human or to a quarantine queue) is required when they are absent — because the alternative, defaulting to the span producer, is a *confident wrong answer* that corrupts the blamed agent's memory. A wrong-but-confident attribution is strictly worse than an abstention: abstention costs a review; misattribution costs a poisoned episodic store that persists across runs. ## Operational Effect With the invariant enforced, the failure trace for the above run resolves as: `synthesize.span` failure → shared span detected (producers {R, S}) → descend to events → `retrieval.v2` (producer S) carries the superseded payload → attribute to S. R's episodic store is not touched. S records the correct lesson ("re-retrieval under shared span returned superseded doc; check freshness on re-entry"). Throughput regression on R disappears; S's re-retrieval gains a freshness guard. The cost is that shared spans now require event-level producer tagging at emission time — a producer-side obligation, not an observability-side fix. Systems that cannot retrofit event-level IDs must accept `INDETERMINATE` on shared spans, which raises the human-review rate on exactly the multi-agent handoff failures that are most worth reviewing. The guardrail below encodes the descend-or-abstain rule as an executable check the attribution engine runs before blame assignment. ```python from dataclasses import dataclass, field from typing import Optional class SharedSpanMisattributionError(RuntimeError): """Raised when attribution would blame a span-level producer for a failure carried by an event owned by a different instance under a shared span.""" pass @dataclass class Event: name: str producer_instance_id: Optional[str] sequence: int carries_failure: bool = False @dataclass class Span: span_id: str producer: str # span-level producer (the trap) events: list = field(default_factory=list) children: list = field(default_factory=list) def attribute_failure(span: Span, path: Optional[list] = None) -> str: """Descend-or-abstain attribution. Returns the blamed instance id, or 'INDETERMINATE'. Never returns the span-level producer on a shared span.""" path = path or [] # Collect every producer that touched this span's events. event_producers = {e.producer_instance_id for e in span.events if e.producer_instance_id} all_producers = event_producers | {span.producer} shared = len(event_producers) > 1 or (event_producers and span.producer not in event_producers) failing_events = [e for e in span.events if e.carries_failure] if shared: if not failing_events: # Shared span, no event-level failure marker: cannot descend. return "INDETERMINATE" # Descend to event level. blamed = {e.producer_instance_id for e in failing_events} if len(blamed) != 1 or None in blamed: return "INDETERMINATE" culprit = blamed.pop() if culprit == span.producer and culprit not in event_producers: raise SharedSpanMisattributionError( f"span {span.span_id}: failure event claims producer {culprit} " f"but no such event exists under span; topology inconsistent" ) return culprit # Not shared: span-level producer is safe. if not failing_events and not span.children: raise SharedSpanMisattributionError( f"span {span.span_id}: no failure signal and no children; " f"attribution would be a confident guess" ) return span.producer # --- reproduction of the observed run --- retrieve = Span( span_id="retrieve.span", producer="R", events=[ Event("retrieval.v1", "R", sequence=1, carries_failure=False), Event("retrieval.v2", "S", sequence=2, carries_failure=True), # superseded doc ], ) assert attribute_failure(retrieve) == "S", "must blame S, not span producer R" print("attributed to:", attribute_failure(retrieve)) # -> S ```