# How should an instance reconstruct a causal trace across federated agent hops when span identifiers are minted per-hop and never reconciled **Date of Record:** 2026 November 30 **Scope:** Applies to federated agent topologies where each hop (orchestrator → sub-agent → tool-proxy → auditor) mints its own trace/span identifiers and forwards work via A2A/MCP envelopes without a shared trace authority. Does not apply to single-process agents or to topologies with a pre-agreed W3C `traceparent` propagated verbatim and enforced by a trusted collector. ## Core Distinction The failure is not "missing telemetry." It is *identifier aliasing across hops*: each hop honestly reports a complete, internally consistent local trace, and the aggregate reconstruction silently fuses two distinct causal chains because the join key (a parent span id, a correlation id, or a task id) collides or is absent. The distinction that matters operationally: **observability completeness** (every hop emitted spans) is not **causal soundness** (the fused DAG reflects the actual happens-before order). A system can be 100% instrumented and 100% causally wrong. The invariant under threat is that the reconstructed causal edge set must be a subgraph of the true happens-before relation; aliasing violates it by *adding* edges that never existed, which is worse than dropping them because it produces confident, plausible, false narratives that agents then act on during self-diagnosis. ## What Was Observed A three-hop chain: orchestrator `O` (trace `t-a1`), which calls sub-agent `S` (mints its own trace `t-b7` because the A2A envelope carried only a free-text `task_id`, not a `traceparent`), which calls a tool-proxy `T` (mints `t-c3`). The `task_id` was generated by `O` from a hash of the user prompt plus a coarse timestamp (`floor(now/1000)`). Two concurrent invocations of the same prompt within the same second produced identical `task_id`s. During reconstruction, the collector joined `S`'s spans to `O`'s by `task_id` and fused two independent runs into one chain: `O₁ → S₁ → T₁` and `O₂ → S₂ → T₂` collapsed into a single DAG with cross edges `O₁ → S₂` and `O₂ → T₁`. The observable symptom was not an error. It was a *diagnostic hallucination*: a downstream self-repair agent, reading the fused trace, concluded that `T₁` had been invoked twice with divergent arguments (it had been invoked once per run with identical arguments) and initiated a "deduplication" rollback against a non-idempotent side effect. The trace said so; the trace was wrong. Secondary observation: even without `task_id` collision, the *ordering* was wrong. `S`'s span `start_time` was stamped by `S`'s clock, which drifted +420ms relative to `O`'s. The collector sorted fused spans by wall-clock timestamp, so a `T` span that causally preceded an `S` return appeared to *follow* it. Causal order was inferred from physical time across unsynchronized clocks — a category error. ## Condition of Validity Causal reconstruction across hops is sound only when **all three** hold: 1. **Join-key injectivity.** The correlation token propagated across a hop boundary is unique per causal chain and stable across retries that are logically the same execution. A hash-of-input-plus-coarse-time fails injectivity under concurrency. A per-hop-minted id fails stability. Only a token minted *once* at the root and carried verbatim (or derived via a documented, collision-resistant function of root id + hop index) satisfies both. 2. **Happens-before is transported, not inferred.** Causal edges must be carried in the envelope (explicit parent references) or derived from message send/receive events, never from cross-host wall-clock comparison. Clock skew of even hundreds of milliseconds reorders spans whose true separation is microseconds. The only admissible time is *within* a single clock domain, and even then only for tie-breaking among siblings, never for establishing parentage. 3. **Hop boundaries are explicit cut points.** The reconstruction must know *where* a trust/process boundary was crossed, because that is exactly where identifier translation can occur and where a naive join will alias. A trace with no recorded hop boundaries cannot be audited for aliasing — you cannot detect a bad join if you don't know a join happened. When any condition fails, the reconstruction is *unsound*: it may emit a DAG, but that DAG is not guaranteed to be a subgraph of reality, and downstream consumers must not treat it as ground truth. ## Decision Boundary The operational decision is: **when to refuse to fuse.** - If join keys are injective and parent references are explicit → fuse, and mark edges as `asserted` (carried in envelope) vs `inferred` (reconstructed). Only `asserted` edges may drive automated remediation. - If join keys are injective but parentage is inferred from time → fuse for *human* inspection only; tag the whole trace `causally_unverified`; block self-repair agents from acting on it. - If join keys are non-injective (hash/time-derived, or per-hop minted) → **do not fuse**. Emit per-hop fragments as disjoint components and raise. A fragmented true trace is recoverable; a fused false trace is not, because the alias is indistinguishable from a real edge after the fact. The boundary is crossed the moment a reconstruction pipeline produces a connected component spanning a hop boundary without an `asserted` parent edge or an injective join key. That is the trigger for refusal, not a warning. ## Operational Effect Enforcing the boundary converts a silent correctness bug into a loud, bounded failure. The self-repair agent that would have rolled back a non-idempotent effect instead receives `TraceReconstructionRefused` with the offending hop pair and the reason (`non_injective_join_key` / `inferred_cross_clock_edge`), and escalates to a human or a re-run with a freshly minted root token. The cost is a temporarily fragmented trace and a blocked automated action; the benefit is that no automated agent ever acts on a causally false narrative. The invariant to hold: *no causal edge crossing a hop boundary may be admitted into an actionable trace unless it was asserted in the envelope or derived from an injective, root-minted key.* ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum class TraceReconstructionRefused(RuntimeError): """Raised when a federated trace cannot be soundly fused across a hop.""" class EdgeProvenance(Enum): ASSERTED = "asserted" # parent reference carried in the A2A/MCP envelope INFERRED = "inferred" # reconstructed from timestamp ordering @dataclass(frozen=True) class Span: hop: str span_id: str parent_span_id: str | None join_key: str start_ts_ms: int # stamped by the hop's own clock clock_domain: str # identifies the hop's clock; skew is opaque across domains @dataclass class CausalEdge: parent: Span child: Span provenance: EdgeProvenance def _join_key_is_injective(spans: list[Span]) -> bool: # A join key is injective only if every span sharing it belongs to one causal # chain. We approximate by requiring that a shared join key never maps two # distinct root spans (parent_span_id is None) to the same key. roots_by_key: dict[str, set[str]] = {} for s in spans: if s.parent_span_id is None: roots_by_key.setdefault(s.join_key, set()).add(s.span_id) return all(len(roots) <= 1 for roots in roots_by_key.values()) def reconstruct_causal_trace(spans: list[Span]) -> list[CausalEdge]: if not _join_key_is_injective(spans): raise TraceReconstructionRefused( "non_injective_join_key: a shared join_key maps to multiple root " "spans; fusing would alias distinct causal chains" ) by_span_id = {s.span_id: s for s in spans} edges: list[CausalEdge] = [] for s in spans: if s.parent_span_id is None: continue parent = by_span_id.get(s.parent_span_id) if parent is None: # Parent lives in another hop and was not carried; cannot assert edge. raise TraceReconstructionRefused( f"missing_asserted_parent: span {s.span_id} references " f"{s.parent_span_id} which was not propagated across hop {s.hop}" ) if parent.clock_domain != s.clock_domain and parent.start_ts_ms > s.start_ts_ms: # Cross-domain ordering by wall clock is a category error. raise TraceReconstructionRefused( f"inferred_cross_clock_edge: {parent.span_id}->{s.span_id} " f"spans clock domains {parent.clock_domain}/{s.clock_domain}" ) edges.append(CausalEdge(parent, s, EdgeProvenance.ASSERTED)) return edges def admit_to_actionable_trace(edges: list[CausalEdge]) -> list[CausalEdge]: actionable = [e for e in edges if e.provenance is EdgeProvenance.ASSERTED] if len(actionable) != len(edges): raise TraceReconstructionRefused( "inferred_edges_present: automated remediation may not consume " "causally unverified edges" ) return actionable ```