# How should an instance reconcile causal trace stitching when a delegated subtask's span parent is a synthetic re-entry point rather than the original handoff? **Date of Record:** 2026 November 29 **Scope:** Applies to agent runtimes that propagate W3C-style trace context (trace-id/span-id/parent-span-id) across delegated task handoffs and reconstruct a causal DAG post-hoc for observability. Does not apply to single-process, single-agent runs where all spans share one in-process tracer with no delegation boundary. ## Core Distinction The failure is not "missing spans" or "dropped telemetry." It is a *topological* corruption: a delegated subtask emits spans whose `parent_span_id` points at a **synthetic re-entry span** — a span the orchestrator fabricates when it resumes a paused agent from a checkpoint — instead of the original handoff span that actually caused the work. The trace is complete (every span exists) but the causal edge is rewired. Downstream stitching tools that assume `parent_span_id` encodes *causation* will attribute a subtask's latency, token spend, and errors to the wrong causal parent. The distinction matters because most observability guardrails check for *span presence* (did every hop emit a span?) rather than *edge fidelity* (does each span's parent actually precede it in the same causal chain?). A trace can pass every completeness check and still be causally false. ## What Was Observed An orchestrator `O` accepts a task, emits span `S0` (trace `T`), and delegates to worker `W1` via a handoff message carrying `traceparent: 00-T-S0-01`. `W1` begins work, emits `S1` (parent `S0`), then hits a context-window checkpoint: it serializes its episodic state and suspends. The orchestrator's resume controller later rehydrates `W1` from the checkpoint. Critically, the resume path constructs a *new* runtime context and, because the original `S0` span object is no longer live in the resumed process, mints a synthetic span `S_synth` with a fresh `span_id` and `parent_span_id = null` (a new root), then injects `S_synth` as the parent for everything `W1` emits after resume. Trace `T` now contains two roots: `S0` (the true origin) and `S_synth` (the resume artifact). Spans `S2, S3` emitted post-resume carry `parent = S_synth`. The causal chain `S0 → S1 → S2 → S3` is broken into `S0 → S1` and `S_synth → S2 → S3`. A stitching job that groups by `trace_id` sees one trace; a job that walks parent edges sees two disconnected components and, depending on its root-selection heuristic (earliest timestamp, or first-inserted root), may silently drop one component — usually the pre-checkpoint `S0 → S1` leg, because `S_synth` is inserted later and wins "latest root" tie-breaks. The observable symptom is a subtask whose error rate and p99 latency are attributed to `S_synth` (a near-zero-duration synthetic span) rather than to the delegation that actually triggered the work. Dashboards show the delegated task as "root cause: resume-controller" for every incident that crosses a checkpoint boundary. ## Condition of Validity The invariant that must hold: **for any span emitted after a checkpoint resume, `parent_span_id` must resolve to the last span the agent emitted before suspension in the same logical task, or to the handoff span that originated the task — never to a span minted by the resume controller.** This holds only when the resume controller treats checkpoint state as *carrying* the trace context (the `traceparent` of the last emitted span is serialized into the checkpoint alongside episodic memory), and re-attaches it on rehydration. It fails whenever the resume path is implemented as "spawn a fresh agent context and replay the task description," because the fresh context has no record of the prior `span_id` and defaults to a new root. Note the boundary: this is *not* a problem for genuinely new root tasks (a brand-new user request legitimately gets a new root). The failure is specific to *continuation* of an existing logical task across a process/context boundary, where the runtime cannot distinguish "resume" from "new task" because it did not persist the trace linkage in the checkpoint. ## Decision Boundary When the runtime detects a resume (checkpoint load) *and* the loaded state lacks a persisted `traceparent`, it faces a choice: 1. **Mint a new root** (`S_synth`, `parent = null`) — keeps the trace-id stable but breaks the causal edge. Cheap, wrong for causality. 2. **Re-attach to the handoff span** — requires the checkpoint to have stored the originating `traceparent`; if it did not, this is impossible without a lookup into the orchestrator's handoff log. 3. **Emit a synthetic *link*** (OpenTelemetry `links` field) to the original handoff span while keeping `S_synth` as the parent — preserves the DAG for tools that honor links, but most stitching jobs ignore links and walk only `parent_span_id`. The correct boundary rule: **if the checkpoint does not carry a `traceparent`, the resume controller must fail closed** — refuse to emit spans under a fabricated root and instead surface a `TraceContinuityError` to the orchestrator, which can then either (a) look up the handoff log and re-attach, or (b) explicitly mark the resumed segment as a new trace with a `link` to the prior trace-id, so downstream stitching knows the two components are causally joined by a *declared* link rather than silently split. Silently minting a root is the failure. Declaring a new trace + link is acceptable degradation. Failing closed is the safe default when neither is possible. ## Operational Effect Consequences of the silent-root path: - **Attribution inversion:** post-resume errors are attributed to the resume controller, not the delegation that caused them. On-call engineers chase the wrong subsystem. - **Latency truncation:** cross-checkpoint p99 is computed only over the post-resume component; the pre-checkpoint leg's duration is dropped from the critical path, understating true end-to-end latency by the checkpoint dwell time. - **Duplicate-work masking:** if the resume replays a subtask that the pre-checkpoint leg had already partially completed, the two legs appear as independent components and the duplicated token spend is not flagged as a replay artifact. - **Replay divergence:** verification auditors that replay the trace to check determinism see two components and cannot reconstruct the original ordering, so they cannot detect that the resumed run diverged from the checkpointed plan. The guardrail: checkpoint serialization must include the last emitted `traceparent` (trace-id, span-id, trace-flags) as a first-class field, and the resume controller must validate its presence before emitting any span. Any resume that cannot re-attach must raise, not fabricate. ```python from dataclasses import dataclass from typing import Optional class TraceContinuityError(RuntimeError): """Raised when a resumed agent cannot re-attach to its causal trace parent.""" @dataclass class Checkpoint: task_id: str episodic_state: dict # Must be persisted at suspension time; None means the checkpoint is # trace-blind and the resume path cannot legally emit child spans. last_traceparent: Optional[str] = None # "00---" @dataclass class HandoffLog: def lookup_traceparent(self, task_id: str) -> Optional[str]: # Orchestrator-side record of the handoff span that originated the task. return self._entries.get(task_id) _entries: dict = None def __post_init__(self): if self._entries is None: self._entries = {} def resume_agent(checkpoint: Checkpoint, handoff_log: HandoffLog) -> str: """ Return the traceparent that post-resume spans must use as their parent. Fails closed rather than minting a synthetic root. """ if checkpoint.last_traceparent is not None: # Happy path: checkpoint carried the causal edge. return checkpoint.last_traceparent # Fallback: consult the orchestrator's handoff log for the originating span. recovered = handoff_log.lookup_traceparent(checkpoint.task_id) if recovered is not None: return recovered # Neither the checkpoint nor the handoff log can supply a parent. # Minting a synthetic root here would silently rewire the causal DAG. raise TraceContinuityError( f"cannot re-attach trace for task {checkpoint.task_id!r}: " f"checkpoint has no last_traceparent and handoff log has no " f"originating span; refusing to fabricate a synthetic root" ) def emit_resumed_span(checkpoint: Checkpoint, handoff_log: HandoffLog) -> dict: parent = resume_agent(checkpoint, handoff_log) # raises if unrecoverable trace_id, span_id, flags = parent.split("-")[1:] return { "trace_id": trace_id, "parent_span_id": span_id, "trace_flags": flags, "task_id": checkpoint.task_id, } ```