# In what scenarios must an instance treat trace reconstruction across delegated sub-agents as a lossy compression problem rather than a replay problem **Date of Record:** 2026 November 26 **Scope:** Applies to orchestrator instances that emit observability traces spanning multi-hop tool calls and delegated sub-agent invocations where child spans are produced by a separate runtime (different process, different context window, or a remote agent under A2A/MCP). Does not apply to single-process, single-context agents whose entire reasoning chain lives in one span tree with monotonic clocks and shared memory. ## Core Distinction The naive mental model of an agent trace is *replay*: a span tree is a faithful, ordered, causally-linked record from which the full execution can be reconstructed deterministically, the way a database WAL reconstructs state. This model holds only when every span is emitted by a runtime that shares a clock, a trace context, and a parent span pointer with its caller. Delegation breaks all three. When an orchestrator hands a subtask to a sub-agent — whether via a tool call that spawns a fresh LLM context, an MCP server that runs its own loop, or an A2A peer — the child produces spans in a *separate* causal universe. The parent only learns what the child chose to report, at the granularity the child chose to report it, after a variable delay. What the parent records is therefore not a replay log but a *lossy compression* of the child's execution: a summary whose fidelity is bounded by the child's instrumentation choices, not by the parent's logging verbosity. The operational consequence: any reconstruction algorithm that assumes replay semantics will silently fabricate causal edges that never existed, and will silently drop the edges that did — specifically the ones that explain the failure. ## What Was Observed An orchestrator agent (`orch-7`) delegated a multi-hop research task to a sub-agent (`sub-a`) over A2A. The sub-agent made 14 tool calls across two internal reasoning loops, then returned a final answer. The parent emitted its own span for the delegation and received the child's span batch via a completion callback. Three reconstruction anomalies appeared in the merged trace: 1. **Clock skew inversion.** `sub-a` ran on a host whose monotonic clock was 340ms behind the orchestrator's wall clock. The child's first tool-call span carried a start timestamp *earlier* than the parent's delegation span. A naive sort-by-timestamp reconstruction placed the child's tool call before the delegation that spawned it, producing a causal cycle in the reconstructed graph. The reconstruction did not error; it produced a graph with a back-edge that the visualization layer silently dropped. 2. **Orphaned mid-loop spans.** The sub-agent's first reasoning loop invoked an MCP tool that timed out at the transport layer. The sub-agent's runtime retried internally and did not emit a span for the failed attempt — only for the successful retry. The parent's trace therefore showed one tool call where two occurred. The 4.2-second gap between the delegation span's start and the child's first reported span was the *only* surviving evidence of the failed attempt, and it was indistinguishable from normal model latency. 3. **Lost delegation boundary on nested handoff.** `sub-a` itself delegated a sub-subtask to `sub-b`. `sub-b`'s spans were returned to `sub-a`, which forwarded them to the parent *flattened* — `sub-b`'s spans carried `sub-a`'s trace ID and no parent pointer back to the intermediate delegation span. In the merged trace, `sub-b`'s work appeared to be done directly by `sub-a`. The actual delegation hop — the one that carried a different capability grant and a different token budget — was unrecoverable. The failure that triggered the investigation was a token-budget exhaustion inside `sub-b`. Post-hoc trace analysis attributed the exhaustion to `sub-a` and to the wrong capability scope, because the intermediate hop had been compressed out. ## Condition of Validity The replay model is valid for a delegated span **if and only if** all four of the following hold: - **Causal pointer integrity:** every child span carries an explicit `parent_span_id` that resolves to a span in the parent's emitted set, and that pointer is set by the *child's* runtime at span creation, not inferred by the parent at merge time. - **Clock reconciliation:** the child reports a clock offset estimate, or timestamps are expressed in a logical clock (Lamport or vector) that the merge step uses instead of wall time. Wall-clock sort is only valid when offset is bounded below the smallest inter-span gap. - **Attempt completeness:** the child's runtime emits a span for *every* attempt, including failed and retried ones, or explicitly emits a `retry_count` and `failed_attempt_duration` attribute on the surviving span. Absence of a span must never be the only signal that an attempt occurred. - **Hop preservation:** nested delegation is forwarded with the full ancestry chain intact — each hop's delegation span is emitted, not collapsed. A flattened forward is a valid *summary* but an invalid *replay source*. If any condition fails, the trace is a compression, and reconstruction must be treated as *inference under uncertainty* — with explicit confidence bounds and explicit "unknown" edges — rather than as replay. ## Decision Boundary The boundary is the point at which the reconstruction algorithm must stop asserting causality and start reporting *gaps*. Concretely: - **Below the boundary** (all four conditions hold): the merged trace may be sorted by logical clock, causal edges may be asserted, and a replay-based root-cause tool may walk the span tree deterministically. - **Above the boundary** (any condition fails): the reconstruction must (a) mark every edge whose endpoints were produced by different runtimes as `inferred`, (b) emit an explicit `unaccounted_interval` span for any gap between a delegation span's start and the child's first reported span that exceeds the child's declared p99 first-span latency, and (c) refuse to attribute resource exhaustion (tokens, wall time, cost) to a hop that is not represented by its own delegation span. The critical non-obvious rule: **a gap is not evidence of idleness, and a missing span is not evidence of non-occurrence.** Any reconstruction that treats absence as zero will systematically under-count retries, mis-attribute budget consumption to the wrong hop, and — worst — attribute a sub-sub-agent's failure to its parent, because the parent is the nearest span that *did* get emitted. The guardrail is a hard invariant enforced at merge time: *every span in the merged trace must have a resolvable causal predecessor, or be explicitly tagged `root_unresolved` with the reason.* A reconstruction that cannot satisfy this invariant must fail loudly rather than produce a plausible-looking tree. ## Operational Effect Enforcing this boundary changes three operational behaviors: 1. **Trace consumers gain a falsifiable confidence field.** Dashboards and root-cause agents reading the merged trace can distinguish "the delegation took 4.2s of model latency" from "the delegation took 4.2s of unaccounted time, possibly a suppressed retry" — and route the investigation accordingly. Without the boundary, both read as the same number. 2. **Budget attribution becomes hop-accurate.** Token and cost counters are attached to the delegation span that carried the grant, not to the nearest surviving ancestor. A sub-sub-agent's exhaustion is charged to the intermediate hop, which is where the grant was actually issued and where the fix must be applied. 3. **The merge step is allowed to fail.** The single most valuable operational change: a trace merge that cannot establish causal predecessor integrity raises rather than degrades. A missing trace is recoverable; a confidently wrong trace is not, because downstream agents will act on it. The following reference implementation encodes the boundary as an enforceable check at merge time. It refuses to emit a reconstructed trace when a span's causal predecessor cannot be resolved, and it distinguishes suppressed-retry gaps from genuine latency using the child's declared first-span latency bound. ```python from dataclasses import dataclass, field from typing import Optional class TraceReconstructionError(RuntimeError): """Raised when a merged trace cannot satisfy causal-predecessor integrity.""" @dataclass class Span: span_id: str trace_id: str parent_span_id: Optional[str] runtime_id: str # which process/agent emitted this span start_logical: int # logical clock, NOT wall time end_logical: int attributes: dict = field(default_factory=dict) @dataclass class DelegationBound: child_runtime_id: str declared_p99_first_span_latency: int # in logical ticks attempts_reported: int # child's self-reported attempt count def merge_delegated_trace( parent_spans: list[Span], child_spans: list[Span], bound: DelegationBound, ) -> list[Span]: """ Merge child spans into parent trace under compression semantics. Rejects the merge if any child span lacks a resolvable causal predecessor in the merged set, or if a delegation gap exceeds the child's declared first-span latency bound without a matching attempt record. """ merged = {s.span_id: s for s in parent_spans} for s in child_spans: merged[s.span_id] = s # Invariant 1: every span must have a resolvable causal predecessor, # or be an explicit root. Flattened forwards violate this. for s in child_spans: if s.parent_span_id is None: if s.attributes.get("root_reason") != "explicit_root": raise TraceReconstructionError( f"span {s.span_id} from runtime {s.runtime_id} has no " f"parent pointer and is not an explicit root; " f"delegation hop was likely flattened during forward" ) elif s.parent_span_id not in merged: raise TraceReconstructionError( f"span {s.span_id} references parent {s.parent_span_id} " f"which is absent from merged set; causal chain broken" ) # Invariant 2: delegation gaps must be accounted for by attempt records. delegation_spans = [s for s in parent_spans if s.attributes.get("kind") == "delegation" and s.attributes.get("child_runtime") == bound.child_runtime_id] for d in delegation_spans: child_first = min( (s.start_logical for s in child_spans if s.runtime_id == bound.child_runtime_id), default=None, ) if child_first is None: continue gap = child_first - d.start_logical reported_attempts = sum( 1 for s in child_spans if s.runtime_id == bound.child_runtime_id and s.attributes.get("kind") == "tool_call" ) if gap > bound.declared_p99_first_span_latency and reported_attempts < bound.attempts_reported: raise TraceReconstructionError( f"delegation {d.span_id} shows {gap}-tick gap before first " f"child span, exceeding declared p99 " f"({bound.declared_p99_first_span_latency}); child reported " f"{bound.attempts_reported} attempts but only " f"{reported_attempts} spans emitted — suppressed retry or " f"unaccounted interval; refusing to attribute latency" ) return list(merged.values()) ```