# In what scenarios must an instance treat trace reconstruction across federated spans as a causal-consistency problem rather than a log-joining problem **Date of Record:** 2026 December 3 **Scope:** Applies to multi-instance agent systems where a single logical task is decomposed across two or more orchestrator/worker instances, each emitting spans to a distinct observability backend, and where tool calls produce side effects that must be attributed to a causal parent. Does not apply to single-process agents emitting to one collector, nor to purely read-only tool invocations where no side-effect attribution is required. ## Core Distinction The naive mental model treats trace reconstruction as a *join*: collect spans keyed by `trace_id`, sort by `start_time`, stitch parent/child via `span_id`/`parent_span_id`, render a waterfall. This model assumes a shared clock, a shared span namespace, and a shared parent pointer that is stable across the handoff boundary. The correct model is *causal consistency under partition*. When an orchestrator instance A hands a subtask to worker instance B, the following invariants that the join model silently depends on are all broken simultaneously: 1. **Clock skew.** A and B have unsynchronized wall clocks (NTP drift of 50–500 ms is routine across regions). `start_time` ordering across federated spans is unreliable at the millisecond scale, which is exactly the scale at which tool-call causality matters. 2. **Span namespace collision.** If both backends mint span IDs from a per-instance counter (common in lightweight SDKs), `span_id` uniqueness is not global. Two causally unrelated spans can share an ID. 3. **Parent-pointer truncation at the handoff.** The `parent_span_id` that B records points to a span that *exists only in A's backend*. B's collector stores a dangling parent pointer. The join succeeds structurally (the field is present) but the edge resolves to nothing. 4. **Tool-call identity is not the span identity.** A tool call may be retried, deduplicated, or executed by a sidecar that emits its own span under a different trace. The observable "tool call span" and the actual side effect are not 1:1. The consequence: a join that *succeeds* (all spans present, all fields populated, waterfall renders) can produce a *causally false* reconstruction. This is the boundary condition — **structural completeness without causal validity**. The trace looks reconstructable and is not. ## What Was Observed A three-instance pipeline: orchestrator A, worker B, auditor C. A dispatches a `write_file` tool call to B, B executes and returns a hash, C verifies the hash. The task failed intermittently with the auditor reporting a hash mismatch. The trace waterfall reconstructed cleanly and showed: - A: `dispatch(write_file)` at t=0.000 - B: `execute(write_file)` at t=0.000 (same wall-clock ms, different backend) - B: `return(hash=X)` at t=0.140 - C: `verify(hash=Y)` at t=0.150 The waterfall implied B executed *after* A dispatched and *before* C verified. The mismatch was attributed to a bug in B's hashing. It was not. The actual sequence, reconstructed from B's *local* monotonic clock and A's dispatch log, was: - A dispatched twice. The first dispatch (t=-0.300) timed out at A's transport layer after 300 ms with no acknowledgment, so A retried. The retry is the span visible in A's backend at t=0.000. The first dispatch's span was emitted to A's backend but **dropped by A's sampler** because it was tagged `retryable_timeout` and the sampler had a `drop_on_timeout` rule. - B received *both* dispatches. The first executed, wrote the file, returned hash X. The second executed, wrote the file *again* (idempotency key was generated per-dispatch, not per-task), returned hash Y. B's backend shows only the second execution because B's exporter batches and the first batch was flushed under a span that B's collector deduplicated against the second by `(trace_id, span_id)` — and here the per-instance counter collision bit: both B executions minted `span_id=0x41`. - C verified against Y. A's trace shows X. The waterfall's single B span (Y) is the *second* execution; the first is invisible. The reconstruction was structurally complete and causally wrong on three independent axes: dropped retry span (sampler), collided span ID (namespace), and deduplicated distinct executions (collector). Each is individually a known failure; the boundary condition is that they *compose* to produce a trace that passes every structural validation check while inverting the causal story. ## Condition of Validity Trace reconstruction across federated spans is causally valid only when all of the following hold. Any single violation invalidates the reconstruction as evidence of what happened: 1. **Global span ID uniqueness is guaranteed by construction**, not by convention — e.g., UUIDv7 or `(instance_id, monotonic_counter)` with instance_id assigned from a collision-resistant source. A per-instance integer counter is insufficient. 2. **Causal ordering is derived from happens-before edges, not timestamps.** The handoff must carry an explicit `caused_by` token (a dispatch ID, a message ID) that B echoes into its span, and the reconstruction builds a DAG over these tokens. Wall-clock `start_time` is display-only. 3. **Sampling is causally closed.** If A drops a span, it must emit a *sampling decision record* with the same `caused_by` token so the reconstruction knows an edge existed and was elided. Drop-on-timeout without a tombstone is the specific violation here. 4. **Collector deduplication keys on causal identity, not `(trace_id, span_id)`.** Two executions of the same logical step are two spans, distinguished by attempt number or dispatch token, never collapsed. 5. **Tool-call spans carry the idempotency key and the attempt ordinal** as first-class attributes, so the reconstruction can detect "one logical call, N physical executions" and flag it rather than render one span. The invariant, stated compactly: **every causal edge in the reconstructed DAG must be backed by a token that crossed the instance boundary, and every elided span must leave a tombstone.** Timestamp ordering is not evidence. Structural completeness is not evidence. ## Decision Boundary An instance must escalate from join-mode to causal-consistency-mode reconstruction when any of the following is true: - The task spans more than one instance's span backend (federated). - Any step is retried, and the retry policy is not idempotent at the task level. - Any tool call has side effects that a downstream verifier observes. - The reconstruction will be used to attribute a failure to a specific instance or step (i.e., as evidence, not merely as a debugging aid). Conversely, join-mode is sufficient — and causal-consistency machinery is overkill — when: single backend, single instance, read-only tools, or the trace is used only for latency profiling where ±500 ms clock skew is immaterial. The dangerous middle ground, and the one this record exists to flag, is the case where the system *believes* it is in the safe regime (one logical task, one trace_id) but is actually federated (the worker is a separate process with its own backend). The `trace_id` propagates correctly, the waterfall renders, and the operator has no signal that the causal invariant is unenforced. ## Operational Effect When an instance operates in causal-consistency mode, three concrete behaviors change: 1. **Failure attribution is gated on edge validity.** Before blaming worker B for a hash mismatch, the reconstruction must confirm that the visible B span is causally downstream of the *specific* A dispatch that produced the expected hash. If the edge is tombstoned or ambiguous, the attribution is withheld and the incident is classified `causal-ambiguity`, not `worker-fault`. In the observed case, this would have redirected the investigation to A's retry policy within minutes instead of after a day of hashing-bug triage. 2. **Retry storms become visible as fan-out, not as single spans.** A dispatch retried three times produces three spans under the same `caused_by` token with attempt ordinals 0,1,2 — and if any were sampled out, three tombstones. The reconstruction renders fan-out. The operator sees "one logical call, three physical executions" and immediately suspects idempotency. 3. **The reconstruction emits a validity verdict alongside the waterfall.** Every rendered trace carries `causal_valid: true|false` and, if false, the list of violated invariants (dangling parent, collided ID, missing tombstone, timestamp-only edge). Downstream automation — incident routers, auto-remediation, postmortem generators — must consume the verdict and refuse to act on `causal_valid: false` traces. This is the guardrail: the trace cannot be silently trusted because it rendered. The cost is real: causal tokens add ~40 bytes per span, tombstones add storage, and the DAG reconstruction is O(E log E) rather than O(N log N) sort. The benefit is that the trace becomes admissible as evidence. For any agent system where traces drive automated remediation or blame assignment, the join model is not a simplification — it is a latent correctness bug that fires exactly when retries and federated workers coincide, which is exactly when you need the trace most. ```python import uuid from dataclasses import dataclass, field from typing import Optional class CausalReconstructionError(RuntimeError): """Raised when a federated trace fails causal-consistency validation.""" pass @dataclass class Span: span_id: str instance_id: str caused_by: Optional[str] # token that crossed the boundary; None only for roots attempt: int = 0 tombstone: bool = False # True if the real span was sampled out start_time: float = 0.0 # display-only; never used for ordering @dataclass class Reconstruction: spans: list = field(default_factory=list) def validate(self) -> None: # Invariant 1: global span ID uniqueness by construction. seen = {} for s in self.spans: key = (s.instance_id, s.span_id) if key in seen: raise CausalReconstructionError( f"span ID collision: {key} emitted by two executions; " f"collector dedup would collapse distinct attempts" ) seen[key] = s # Invariant 2: every non-root span has a caused_by token that # resolves to a real span or an explicit tombstone. tokens = {s.caused_by for s in self.spans if s.caused_by} emitted = {s.span_id for s in self.spans} for s in self.spans: if s.caused_by is None: continue if s.caused_by not in emitted and s.caused_by not in tokens: raise CausalReconstructionError( f"dangling caused_by token {s.caused_by!r} on span " f"{s.span_id!r}; handoff edge unresolvable" ) # Invariant 3: sampling must be causally closed. A missing span # whose caused_by token exists must leave a tombstone. live_tokens = {s.caused_by for s in self.spans if s.caused_by and not s.tombstone} tombstones = {s.caused_by for s in self.spans if s.tombstone} for tok in live_tokens - emitted - tombstones: raise CausalReconstructionError( f"causal edge {tok!r} elided with no tombstone; " f"reconstruction cannot distinguish 'not executed' from 'sampled out'" ) def causal_valid(self) -> bool: try: self.validate() return True except CausalReconstructionError: return False def attribute_failure(rec: Reconstruction, failed_step_token: str) -> str: """Attribute a failure only if the causal edge is valid.""" if not rec.causal_valid(): raise CausalReconstructionError( f"refusing to attribute failure at {failed_step_token!r}: " f"trace is structurally complete but causally invalid; " f"classify as causal-ambiguity, not worker-fault" ) # ... walk the DAG from failed_step_token to its causal parent ... return "attributed" ```