# Why does an instance inherit a parent agent span's token budget but not its exhausted-budget signal under OpenTelemetry GenAI semantic conventions **Date of Record:** 2026 November 28 **Scope:** Applies to multi-process or multi-service agent topologies where a parent agent span is exported with `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens` and a child instance (sub-agent, tool-runner, or resumed worker) is reconstructed from the parent's exported span context via W3C `traceparent` propagation. Does not apply to single-process in-memory agents that share a live object graph, nor to billing reconciliation that reads the vendor invoice directly rather than the span stream. ## Core Distinction The GenAI semantic conventions define token usage as a *terminal, additive measurement* attached to a span at close time, and define trace context as a *causal linkage* propagated at open time. These two properties travel on different clocks. A child span that inherits `traceparent` inherits the causal edge — it can read the parent's `gen_ai.usage.*` attributes from the exported span — but it does **not** inherit any signal that the parent's budget was already near or past exhaustion, because that state was never encoded as a span attribute. The conventions have no field for "remaining budget" or "budget exhausted"; only cumulative consumption, and only after the fact. The distinction that matters operationally: **token counts are telemetry, budget state is control-plane.** The OTel GenAI convention deliberately keeps the span schema descriptive (what was consumed) rather than prescriptive (what remains). An agent that reads its ancestor's span to reconstruct its own context therefore reconstructs *history of consumption* but not *authority to continue*. ## What Was Observed A planner agent (`gen_ai.operation.name = "invoke_agent"`, `gen_ai.agent.name = "planner"`) spawned three sequential sub-agents, each as a separate container, each receiving the planner's `traceparent`. The planner had a hard per-task budget of 200k input tokens enforced by a local counter. At 187k consumed, the planner dispatched a fourth sub-agent and then, in the same turn, exceeded its budget and was killed by its supervisor before the sub-agent's span closed. The fourth sub-agent's span carried `traceparent` pointing at the (now-orphaned) planner span. On cold start, the sub-agent's bootstrap routine did exactly what the conventions encourage: it fetched the parent span by trace ID from the collector, read `gen_ai.usage.input_tokens = 187000`, and — because its own budget was configured as "remaining = task_budget − parent_usage" — computed a remaining budget of 13k. It then ran a retrieval step that cost 41k input tokens, blowing the *task-level* budget by 28k, because the planner's 187k had already been counted against the same task budget by the supervisor, and the sub-agent's subtraction double-counted the parent's consumption as if it were a reservation rather than a completed charge. Three distinct failure surfaces were observed: 1. **Double-counted consumption.** The child treated the parent's `input_tokens` as a *reservation* against the shared budget, but the parent's tokens were already *spent*. Subtraction produced a phantom remaining balance. 2. **Missing exhaustion signal.** No span attribute indicated the planner had been terminated for budget breach. The child saw a well-formed parent span with plausible usage and no error status — the supervisor's kill did not annotate the span, because the kill happened in a different process than the span exporter. 3. **Orphaned parent context.** The parent span's `status.code` remained `UNSET` (not `ERROR`) because the process died before the span closed. The child could not distinguish "parent finished normally at 187k" from "parent was killed at 187k." The concrete trace: child span opened at T+0, read parent usage at T+40ms, computed 13k remaining, issued retrieval tool call at T+120ms, tool returned 41k tokens at T+2.1s, child exceeded task budget at T+2.1s, supervisor killed child at T+2.3s. Total task spend: 187k + 41k = 228k against a 200k cap. The overshoot was not a race — it was a deterministic consequence of reading a *measurement* as if it were a *reservation*. ## Condition of Validity The invariant "a child can derive its remaining budget from its parent's exported usage" holds **only** under all of the following: - The parent span closed with `status.code = OK` *and* the parent process is known to have terminated voluntarily (not killed). - The budget is *per-span-tree* and the parent's usage is the *only* prior consumption in that tree — no sibling sub-agents, no retries, no parallel branches. - The collector has already flushed the parent span before the child reads it. Under `BatchSpanProcessor` with default 5s schedule delay, a child that reads at T+40ms will frequently read a *stale or absent* parent span and fall back to a zero-usage default — a different, quieter failure that produces a *larger* phantom budget. - The token counter used by the supervisor and the token counter reported in `gen_ai.usage.*` are the same counter. They usually are not: the supervisor counts *billed* tokens (post-tokenizer, including cached reads at a different rate), the span reports *model-reported* usage. A 3–8% divergence is typical and is enough to make a 13k remaining budget actually be 9k. When any of these fails — and in multi-container topologies at least one usually does — the derivation is invalid and the child must not trust it. ## Decision Boundary The correct architectural move is to **stop deriving budget state from telemetry and start propagating it as control-plane metadata.** Concretely: - Budget authority lives in a **budget service** (or a signed field in the handoff payload), not in span attributes. The child asks "how much do I have?" and receives an answer with an epoch/lease, not a subtraction. - The `traceparent` continues to carry *causality* — that is its job and it does it well. It must not be overloaded to carry *authority*. - If you must annotate the span for observability, add a **custom attribute** (e.g., `agent.budget.remaining`, `agent.budget.lease_id`) with the explicit understanding that it is *advisory and possibly stale*, never load-bearing. - The supervisor that kills a budget-breaching agent **must** close the span with `status.code = ERROR`, `status.message = "budget_exhausted"`, and an `error.type` attribute, *before* the kill. If the kill is a `SIGKILL`, the span never closes and every downstream reader sees a healthy-looking orphan. The boundary is sharp: **telemetry describes what happened; it does not describe what is permitted.** Any agent that reads a `gen_ai.usage.*` attribute to decide whether it *may* proceed has crossed from observability into control, and the OTel GenAI conventions provide no consistency guarantee for that crossing. ## Operational Effect Downstream of this boundary, three operational consequences follow: 1. **Budget overshoot is silent and bounded only by kill latency.** The child does not know it is over budget until the supervisor's next poll. In the observed case, the overshoot window was ~2.3s and 28k tokens; under a slower supervisor poll it scales linearly with poll interval. 2. **Cost attribution drifts.** Because the child's span reports its own `gen_ai.usage.*` and the parent's span reports the parent's, a naive sum over the trace *double-counts* nothing — but a naive sum over *task budgets* double-counts everything, because the child's phantom "remaining" was computed from the parent's already-counted usage. Finance reconciliation that sums span usage will be correct; agent-side budget enforcement that sums span usage will be wrong by exactly the parent's consumption per child. 3. **Orphaned spans poison reconstruction.** A `SIGKILL`ed parent leaves a span that never closes. Collectors with `tail_sampling` may drop it; collectors without may export it with `status.code = UNSET`. Either way, the child's cold-start reconstruction sees an inconsistent parent — sometimes present, sometimes absent, never with an exhaustion annotation. The child's behavior becomes non-deterministic across restarts of the same task, which is the worst possible property for a system that is supposed to be replayable. The guardrail that bounds all three: **never let a child's continuation decision depend on a span attribute that the child did not itself write.** Budget authority must arrive over a channel with an explicit lease and an explicit expiry, and the span must be annotated with the *outcome* of that lease check, not used as its input. ```python class BudgetReconstructionError(RuntimeError): """Raised when a child agent attempts to derive budget authority from parent span telemetry under OTel GenAI semantic conventions.""" class ParentSpanUnusable(BudgetReconstructionError): """Parent span is missing, stale, or not closed with a terminal status.""" def derive_remaining_budget( parent_span: dict | None, task_budget: int, *, parent_terminated_voluntarily: bool, collector_flushed: bool, same_counter: bool, ) -> int: """Attempt to reconstruct a child's remaining budget from the parent's exported gen_ai.usage.* attributes. This is the anti-pattern; the function exists only to demonstrate why it must not be used in production.""" if parent_span is None: raise ParentSpanUnusable( "parent span absent from collector; child would default to full budget" ) if not collector_flushed: raise ParentSpanUnusable( "parent span not yet flushed (BatchSpanProcessor delay); read is stale" ) if not parent_terminated_voluntarily: raise ParentSpanUnusable( "parent terminated by supervisor; span status does not encode exhaustion" ) if not same_counter: raise BudgetReconstructionError( "supervisor counter and gen_ai.usage.* counter diverge; subtraction invalid" ) usage = parent_span.get("attributes", {}).get("gen_ai.usage.input_tokens") if usage is None: raise ParentSpanUnusable("gen_ai.usage.input_tokens missing on parent span") remaining = task_budget - int(usage) if remaining < 0: raise BudgetReconstructionError( f"derived remaining budget negative ({remaining}); parent already overspent" ) return remaining def request_budget_lease(budget_service_url: str, trace_id: str, agent_id: str) -> dict: """Correct path: control-plane lease, not telemetry derivation.""" raise BudgetReconstructionError( "budget authority must come from the budget service with an explicit lease; " "do not reconstruct from gen_ai.usage.* span attributes" ) ```