What structural signals indicate a trace has lost causal closure across sub-agent fan-out

**Date of Record:** 2026 December 2 **Scope:** Applies to observability pipelines that reconstruct a single causal trace from spans emitted by a parent agent and N delegated sub-agents (fan-out). Does not apply to single-agent single-span traces, nor to purely sequential delegation where each child span nests under exactly one parent span.

Core Distinction

The failure is not "missing spans." Missing spans are visible and loud. The failure is **causal closure loss**: the reconstructed trace contains every emitted span, every span has a valid parent reference, and yet the trace is *wrong* because the parent reference chain was satisfied by a *structurally valid but semantically incorrect* edge.

This happens at fan-out because delegation is where a parent agent emits `k` concurrent child invocations, and the identity of "which child answered which sub-question, in which order, on whose behalf" lives in the parent's *context*, not in the spans. When the parent's context is compacted, retried, or the delegation is replayed, the span parent-links survive but the *semantic binding* (child → originating sub-task → warrant) does not. The trace closes causally in the graph sense and fails causally in the execution sense.

What Was Observed

A planner agent fans out to five sub-agents (`S1..S5`), each carrying a `trace_id` propagated by the SDK and a `parent_span_id` set to the fan-out span. Sub-agent `S3` times out at the transport layer, is retried by the parent's retry policy, and the retry `S3'` succeeds. Both `S3` (error) and `S3'` (ok) are emitted with the *same* `parent_span_id`. Meanwhile `S4` was cancelled by the parent after `S3'` returned an answer that made `S4` redundant.

Reconstruction produces a trace graph where:

The trace *renders*. The waterfall looks correct. The invariant that broke is: **every child output consumed by a parent span must be connected by an explicit data-dependency edge, not inferred from timestamps.** Timestamp inference is the boundary condition. Under fan-out with retries and cancellations, timestamp ordering is not causally sufficient, because concurrent children overlap and retries interleave.

Concretely, reconstruction that infers dependency from `child.end_time < parent.start_time` will, in this trace, also falsely attribute `S4`'s partial (cancelled) output as a dependency if `S4`'s end timestamp precedes the synthesis start. The trace then claims the synthesis used a cancelled sub-agent's output. It did not. This is the closure loss: the graph is connected, the semantics are inverted.

Condition of Validity

Timestamp-based dependency inference is valid **only** when the fan-out is strictly sequential per child (no concurrent children share a time window) **and** no child is retried or cancelled. Both conditions must hold. Under any fan-out with `k > 1` concurrent children, the first condition fails by construction. Under any retry or cancellation policy, the second fails. Therefore for the common case—concurrent fan-out with retry—timestamp inference is invalid, and closure requires explicit edges.

The guardrail is an invariant enforced at emit time, not reconstruct time:

  1. Every child span MUST carry a `delegation_id` (the parent's sub-task identifier, stable across attempts) and an `attempt` counter.
  2. Every retry MUST carry `retry_of: <span_id>` pointing at the prior attempt.
  3. Every cancellation MUST carry `cancelled_by: <span_id>` pointing at the deciding parent span.
  4. Every parent consumption of a child output MUST emit a `consumes: <child_span_id>` edge on the synthesis span.

Reconstruction MUST reject any trace where a synthesis span has zero `consumes` edges but non-empty child spans, rather than falling back to timestamp inference. The fallback is the bug.

Decision Boundary

The decision boundary is: **does the trace need to answer "why did the agent do this?" or only "what did the agent do?"**

The boundary is crossed silently because both modes produce a visually identical waterfall. The signal that you have crossed it undetected: a trace where a synthesis/aggregation span's declared inputs (from the parent's own logged context) differ from the set of child spans that temporally precede it. That mismatch is the structural signal of closure loss. If they match, you are probably fine; if they differ, the trace is lying about causality.

Operational Effect

Downstream consumers of the trace inherit the inversion. A replay/verification agent that trusts the trace will replay `S4`'s cancelled output as an input, producing a divergent result and a false "replay mismatch" alarm attributed to nondeterminism—when the actual cause is a reconstruction artifact. Debugging then chases model nondeterminism for days while the real defect is a missing edge. The fix is at emit time: make delegation identity and consumption explicit, and make reconstruction fail closed (raise) rather than infer when closure is unprovable. Fail-closed reconstruction converts a silent semantic inversion into a loud, actionable error at the exact span where the binding was lost.

from dataclasses import dataclass, field
from typing import Optional


class CausalClosureError(RuntimeError):
    """Raised when a reconstructed trace cannot prove causal closure."""


@dataclass
class Span:
    span_id: str
    parent_span_id: Optional[str]
    kind: str  # "fanout", "child", "synthesis"
    status: str  # "ok", "error", "cancelled"
    delegation_id: Optional[str] = None
    attempt: int = 1
    retry_of: Optional[str] = None
    cancelled_by: Optional[str] = None
    consumes: list = field(default_factory=list)
    start_time: float = 0.0
    end_time: float = 0.0


def assert_closure(synthesis: Span, children: list, allow_timestamp_fallback: bool = False) -> None:
    if synthesis.kind != "synthesis":
        raise CausalClosureError(
            f"span {synthesis.span_id} is not a synthesis span; closure check inapplicable"
        )

    if not children:
        return  # nothing to close over

    # Invariant 1: retries must be explicitly linked, never inferred.
    for c in children:
        if c.attempt > 1 and c.retry_of is None:
            raise CausalClosureError(
                f"child {c.span_id} has attempt={c.attempt} but no retry_of edge; "
                f"retry provenance lost under fan-out"
            )

    # Invariant 2: cancellations must point at their decider.
    for c in children:
        if c.status == "cancelled" and c.cancelled_by is None:
            raise CausalClosureError(
                f"child {c.span_id} cancelled without cancelled_by edge; "
                f"causal attribution to parent decision lost"
            )

    # Invariant 3: every consumed child must be an explicit edge.
    if not synthesis.consumes:
        if not allow_timestamp_fallback:
            raise CausalClosureError(
                f"synthesis {synthesis.span_id} has {len(children)} child spans "
                f"but zero consumes edges; refusing timestamp-based inference "
                f"(closure unprovable under concurrent fan-out)"
            )
        # Explicit opt-in fallback: infer, but flag it.
        inferred = [c.span_id for c in children if c.end_time <= synthesis.start_time]
        if any(c.status == "cancelled" for c in children if c.span_id in inferred):
            raise CausalClosureError(
                f"timestamp fallback would attribute a cancelled child's output "
                f"to synthesis {synthesis.span_id}; closure inverted"
            )
        return

    # Invariant 4: declared consumption must reference a real, non-cancelled child.
    child_ids = {c.span_id for c in children}
    for cited in synthesis.consumes:
        if cited not in child_ids:
            raise CausalClosureError(
                f"synthesis {synthesis.span_id} consumes unknown span {cited}"
            )
        child = next(c for c in children if c.span_id == cited)
        if child.status == "cancelled":
            raise CausalClosureError(
                f"synthesis {synthesis.span_id} consumes cancelled child {cited}; "
                f"dependency inversion"
            )


# Example trigger: fan-out with a retried child and a cancelled sibling,
# synthesis emitted without consumes edges.
children = [
    Span("s3_a", "fan", "child", "error", delegation_id="d3", attempt=1),
    Span("s3_b", "fan", "child", "ok", delegation_id="d3", attempt=2, retry_of="s3_a"),
    Span("s4", "fan", "child", "cancelled", delegation_id="d4", cancelled_by="decide"),
]
synthesis = Span("syn", "root", "synthesis", "ok", start_time=10.0, end_time=11.0)
try:
    assert_closure(synthesis, children)
except CausalClosureError as e:
    print("closure loss detected:", e)