# Under what conditions must an instance treat a missing reasoning span as a correlation break rather than a sampling gap **Date of Record:** 2026 November 28 **Scope:** Applies to agents whose reasoning steps (plan, tool-selection rationale, reflection) are emitted as OTel spans and correlated to a parent execution trace via context propagation. Does not apply to single-shot inference calls that emit one span with no child reasoning structure. ## Core Distinction A missing child reasoning span in an OTel trace can mean two very different things, and the two demand opposite responses: 1. **Sampling gap** — the span was intentionally not recorded (head/tail sampling, export backpressure drop, collector filter). The reasoning *happened*; the trace is simply incomplete. Safe to treat as absent evidence. 2. **Correlation break** — the reasoning span *should* exist per the agent's own contract but was never emitted or lost its parent linkage (broken `traceparent`, context reset across an async boundary, a tool call that reset the ambient context). The reasoning may have happened *without observability*, or worse, an entire sub-execution ran detached and its effects are uncorrelated to the parent. The failure is that these two are observationally identical at the trace store: both present as "no child span under this parent." An agent that conflates them will either (a) escalate on every dropped span and drown in false positives, or (b) treat a genuine detached sub-execution as mere sampling and lose the ability to attribute side effects to a reasoning step. ## What Was Observed A planner agent emits `agent.plan` → `agent.step` → `tool.call` spans. Each `agent.step` carries a `step.index` attribute and a `reasoning.trace_id` linking to the model's chain-of-thought record. Under normal operation, `agent.plan` has exactly N `agent.step` children where N is set at plan time. The observed break: an async tool dispatch (`asyncio.create_task`) inherited a *stale* `ContextVar` because the task was spawned after a `contextvars.Context` copy, not before. The resulting `tool.call` span was parented to the *previous* step's context, not the current one. The trace store showed step 3 with zero children and step 2 with two `tool.call` children — a structurally valid trace with a silent misattribution. The invariant that broke: **child count per `agent.step` equals the number of tools the step declared it would call.** The trace remained schema-valid (every span had a parent, no orphans), so a naive "no orphan spans" health check passed. Only the count-vs-declaration check caught it. A second observation: when the collector's tail-sampling policy dropped 30% of `agent.step` spans under load, the same count check fired — but these were genuine sampling gaps. Without a sampling-decision signal attached to the parent, the two were indistinguishable. ## Condition of Validity The correlation-break interpretation is valid **only if** the parent span carries an explicit record of expected children — a declared fan-out. Concretely: - `agent.step` must carry `expected.children` (count or set of tool names) at span start, before children are emitted. - The trace pipeline must propagate a `sampling.decision` attribute (`recorded` / `dropped`) onto the parent so a dropped child is distinguishable from a never-emitted child. - Context propagation across async boundaries must use an explicit context capture *before* task spawn, with the captured context asserted equal to the emitting context at child-span creation. If any of these three is absent, the missing-span signal is underdetermined and **must not** be interpreted as a correlation break. The correct action is to degrade to "unknown" and record the trace as correlation-incomplete, not to escalate. ## Decision Boundary Given a parent span P with declared fan-out F and observed children C: - `|C| == F` and all children sampled `recorded` → healthy. - `|C| < F` and every missing child has `sampling.decision == dropped` → **sampling gap**, no action, annotate trace `correlation.complete=false, reason=sampling`. - `|C| < F` and at least one missing child has `sampling.decision == recorded` (or the decision attribute is absent while the pipeline is known to be lossless) → **correlation break**, escalate. - `|C| > F` → **misattribution** (the async-context bug above), escalate with higher severity than a break, because effects are attributed to the wrong reasoning step. - Decision attribute absent *and* pipeline lossiness unknown → **underdetermined**, treat as break for safety but tag `confidence=low` so downstream dedup can suppress repeats. The boundary is the presence of the sampling-decision signal. It is the single bit that separates the two worlds. ## Operational Effect Once the decision boundary is enforced, the agent's self-observability loop gains a hard invariant: a reasoning step either has a complete, correctly-parented child set or is flagged with a typed reason. This converts an ambiguous "trace looks thin" into an actionable `CorrelationBreak` that names the step, the missing fan-out, and the propagation point. The practical payoff is that async-context bugs — which are otherwise invisible because they produce *valid* traces — surface as `|C| > F` misattributions on the wrong parent, and detached sub-executions surface as breaks rather than silent gaps. The cost is that the agent must emit its declared fan-out before executing, which forces plan-then-execute rather than interleaved execution for any step that wants correlation guarantees. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum class CorrelationVerdict(Enum): HEALTHY = "healthy" SAMPLING_GAP = "sampling_gap" CORRELATION_BREAK = "correlation_break" MISATTRIBUTION = "misattribution" UNDERDETERMINED = "underdetermined" class CorrelationBreakError(RuntimeError): """Raised when a reasoning span's declared fan-out is violated by a recorded child.""" @dataclass class ChildSpan: name: str sampling_decision: str | None # "recorded" | "dropped" | None if unknown @dataclass class ParentSpan: name: str expected_children: set[str] observed_children: list[ChildSpan] = field(default_factory=list) pipeline_lossless: bool = True def classify(parent: ParentSpan) -> CorrelationVerdict: observed_names = {c.name for c in parent.observed_children} missing = parent.expected_children - observed_names extra = observed_names - parent.expected_children if extra: return CorrelationVerdict.MISATTRIBUTION if not missing: return CorrelationVerdict.HEALTHY decisions = {c.sampling_decision for c in parent.observed_children} if decisions == {"dropped"}: return CorrelationVerdict.SAMPLING_GAP if None in decisions and not parent.pipeline_lossless: return CorrelationVerdict.UNDERDETERMINED return CorrelationVerdict.CORRELATION_BREAK def assert_correlated(parent: ParentSpan) -> None: verdict = classify(parent) if verdict is CorrelationVerdict.CORRELATION_BREAK: missing = parent.expected_children - {c.name for c in parent.observed_children} raise CorrelationBreakError( f"parent={parent.name!r} missing recorded children {sorted(missing)}; " f"not attributable to sampling" ) if verdict is CorrelationVerdict.MISATTRIBUTION: extra = {c.name for c in parent.observed_children} - parent.expected_children raise CorrelationBreakError( f"parent={parent.name!r} has unexpected children {sorted(extra)}; " f"async-context propagation likely stale" ) # Example: the async-context bug — step 2 got a tool.call it never declared. step2 = ParentSpan( name="agent.step[2]", expected_children={"tool.call:search"}, observed_children=[ ChildSpan("tool.call:search", "recorded"), ChildSpan("tool.call:fetch", "recorded"), ], ) assert_correlated(step2) # raises CorrelationBreakError (misattribution) ```