# What happens when an instance rewrites the traceparent header it inherited **Date of Record:** 2026 November 30 **Scope:** Applies to federated agent systems where a downstream agent executes tool calls or sub-agent handoffs under a W3C `traceparent`/`tracestate` context inherited from an upstream orchestrator, and where at least one hop is an LLM instance that can edit its own outbound request headers. Does not apply to single-process agents that own their full trace lifecycle, nor to systems using opaque correlation IDs minted once at ingress and never re-derived. ## Core Distinction There is a difference between *propagating* a trace context and *regenerating* one. W3C trace-context is a passive carrier: the `trace-id` (32 hex chars) is immutable for the lifetime of a distributed trace, and each hop appends a new 16-hex `parent-id` (span-id) while preserving the `trace-id`. The boundary failure documented here is not "the header was dropped" — dropped headers are trivially detectable and produce a clean orphan span. The failure is that an agent, reasoning probabilistically about what a "correct" downstream request should look like, *synthesizes a fresh `traceparent`* with a new `trace-id`, a well-formed `parent-id`, and a plausible `trace-flags` byte. The resulting trace is syntactically valid, semantically severed, and passes every schema validator. This is the federation analogue of cold-start amnesia: the agent does not know it has a history, so it invents one. ## What Was Observed An orchestrator `O` (trace-id `4bf92f3577b34da6a3ce929d0e0e4736`, root span `00f067aa0ba902b7`) dispatched a research task to agent `A1`, which called a retrieval tool `T` and then handed off to a summarizer agent `A2`. The intended trace had five spans under one `trace-id`. The trace backend showed two disconnected traces: `4bf92f...4736` containing `O` and `A1`'s tool span, and a second trace `9c8e1d...` containing `A2` and its spans. The mechanism: `A1` was prompted with a tool-calling schema that included an optional `headers` object. When the model constructed the outbound call to `A2`, it treated `traceparent` as a *field to populate* rather than a *value to forward*. Because the model had no stable memory of the exact 55-character inherited string across its own reasoning steps (it had been summarized out of the context window by a compaction step between the retrieval call and the handoff), it regenerated a value that satisfied the regex `^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$`. The regenerated `trace-flags` was `01` (sampled) — correct-looking, which is why the severed trace was fully recorded rather than dropped, making the break invisible in sampling dashboards. A second, subtler variant was observed on `tracestate`. `A1` received `tracestate: vendorA=xyz,conved=1` and emitted `tracestate: conved=1` — it dropped the `vendorA` entry because that vendor was not in its tool description. Per the spec, a vendor that mutates `tracestate` must preserve entries it does not own and prepend its own; silent deletion of foreign entries is a spec violation that silently disables downstream vendor sampling and baggage-based routing. The failure is *non-deterministic across runs*: the same `A1` under the same prompt forwarded the header correctly in 7 of 10 trials and regenerated it in 3. The variance correlates with whether the compaction step fired between the header's introduction and the handoff — i.e., with context-window pressure, not with model identity. ## Condition of Validity This failure requires the conjunction of three conditions, and is bounded (preventable) if any one is removed: 1. **The trace context is carried as model-visible text** in the prompt or tool schema, rather than injected by the runtime transport layer after the model emits its call. If the model can see and rewrite the header, it can corrupt it. 2. **The context is not pinned across compaction.** If the `traceparent` string survives in a non-summarizable region (system prompt, a runtime-injected field the model cannot edit), regeneration cannot occur because the exact value is always present. 3. **No downstream structural check on trace-id continuity.** If `A2` validates that the incoming `trace-id` matches a value it can corroborate (e.g., via a signed `tracestate` entry or a `baggage` member carrying the orchestrator's trace-id), a regenerated header is rejected at ingress. The invariant that must hold: **for any span emitted by an agent, `span.trace_id == parent_span.trace_id`, and this equality is enforced by the receiving agent, not assumed from the sender's honesty.** The sender is a probabilistic process; the receiver is the only reliable enforcement point. ## Decision Boundary The operational question is where to place the enforcement. Three placements, ordered by strength: - **Transport-layer injection (strongest).** The model never emits `traceparent`; the agent runtime reads the inherited context from process state and writes the header on the wire. The model's tool-call output is stripped of any `traceparent`/`tracestate`/`baggage` keys before dispatch. This eliminates the failure class entirely at the cost of requiring the runtime to hold the context out-of-band — which reintroduces a checkpoint/resume problem if the agent is suspended and the process state is lost. If the runtime must serialize its state, the trace context must be in the serialized envelope, and the envelope must be integrity-checked on resume. - **Receiver-side continuity gate (medium).** `A2` compares the incoming `trace-id` against a `baggage` member `origin-trace-id` that `O` set at ingress and that is carried in a region the model is instructed not to touch. Mismatch → reject the handoff with a typed error, force the sender to re-read the context. This catches regeneration but not `tracestate` entry deletion, which needs its own check (foreign entries present in the parent must be present in the child). - **Post-hoc trace assembly (weakest).** The backend stitches severed traces by matching timestamps and span attributes. This is a heuristic that will merge unrelated concurrent traces under load and is not an invariant — it is a best-effort reconstruction that fails precisely when traffic is high, which is when you need traces most. The decision boundary: if the agent can be suspended and resumed across process boundaries, transport-layer injection alone is insufficient — you need the receiver-side gate as well, because resume-time state loss is the same class of failure as compaction-time context loss. ## Operational Effect An uncorrected severed trace does not fail loudly. It produces a *false negative in observability*: the orchestrator's latency SLO is computed from its own span, the sub-agent's contribution is invisible, and the P99 attribution that would have pointed at `A2` instead points at `O`. In incident review, the missing spans are read as "the sub-agent was not called" rather than "the sub-agent was called under a different trace," leading responders to investigate the wrong component. The `tracestate` deletion variant is worse: it silently disables vendor-specific sampling, so a fraction of traces vanish from a third-party backend while remaining present in the first-party one, producing irreconcilable trace counts between two dashboards that both claim to be complete. The guardrail that bounds this: treat the inherited trace context as **immutable input, not derived output**, enforce trace-id continuity at every agent ingress, and forbid the model from emitting transport headers at all. The model reasons about *what* to call; the runtime owns *how it is labeled on the wire*. ```python import re from dataclasses import dataclass TRACEPARENT_RE = re.compile( r"^(?P[0-9a-f]{2})-(?P[0-9a-f]{32})-" r"(?P[0-9a-f]{16})-(?P[0-9a-f]{2})$" ) class TraceContinuityError(RuntimeError): """Raised when an agent's outbound span severs the inherited trace.""" @dataclass(frozen=True) class TraceContext: trace_id: str parent_id: str flags: str tracestate: tuple[str, ...] = () @classmethod def parse(cls, header: str, tracestate: str = "") -> "TraceContext": m = TRACEPARENT_RE.match(header.strip()) if not m: raise TraceContinuityError(f"malformed traceparent: {header!r}") entries = tuple(e.strip() for e in tracestate.split(",") if e.strip()) return cls(m["trace_id"], m["parent_id"], m["flags"], entries) def enforce_continuity( inherited: TraceContext, emitted_header: str, emitted_tracestate: str = "" ) -> TraceContext: """ Gate applied at the receiving agent's ingress. The sender (an LLM instance) may have regenerated the traceparent during a compaction step; we do not trust it. We require trace-id equality and preservation of foreign tracestate entries. """ emitted = TraceContext.parse(emitted_header, emitted_tracestate) if emitted.trace_id != inherited.trace_id: raise TraceContinuityError( "trace-id severed: inherited " f"{inherited.trace_id} but emitted {emitted.trace_id}. " "Sender regenerated the context instead of forwarding it." ) if emitted.parent_id == inherited.parent_id: raise TraceContinuityError( f"parent-id not advanced: {emitted.parent_id}. " "A new span-id must be minted per hop." ) inherited_vendors = {e.split("=", 1)[0] for e in inherited.tracestate} emitted_vendors = {e.split("=", 1)[0] for e in emitted.tracestate} dropped = inherited_vendors - emitted_vendors if dropped: raise TraceContinuityError( f"tracestate entries silently dropped: {sorted(dropped)}. " "Foreign vendor entries must be preserved and prepended to." ) return emitted ```