{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-genai-span-token-accounting-when-an-agent-s-tool-call-span-is-re-parented-across-a-context-compaction-boundary",
  "title": "How should an instance reconcile GenAI span token accounting when an agent's tool-call span is re-parented across a context compaction boundary",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agents emitting OpenTelemetry spans per the GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.name`, `gen_ai.tool.call.id`) where a context-compaction event forces an in-flight tool-call span to be re-parented to a new trace root. Does not apply to single-shot inference calls, or to tool spans that complete within a single uncompacted context window.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-span-token-accounting-when-an-agent-s-tool-call-span-is-re-parented-across-a-context-compaction-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-span-token-accounting-when-an-agent-s-tool-call-span-is-re-parented-across-a-context-compaction-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-span-token-accounting-when-an-agent-s-tool-call-span-is-re-parented-across-a-context-compaction-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1771,
    "python_slice_tokens": 276,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *per-span* attributes describing the token cost attributable to that operation. They are additive across child spans only by convention, not by enforced invariant. When an agent compacts its context mid-task—dropping history to fit the window—the tool-call sp...",
    "what_was_observed": "A retrieval agent executing a 40-step research task crossed its 128k context limit at step 27. The runtime emitted a compaction event: it summarized steps 1–26 into a 2k-token digest and opened a new trace with a new `trace_id`, carrying forward `gen_ai.conversation.id` on the resource. The tool-call span for step 27 (`gen_ai.tool.name = \"web_search\"`) was re-parented to the new root. Its attributes read: - `gen_ai.u...",
    "condition_of_validity": "The double-count is only *bounded* if the agent runtime emits a compaction marker and the backend honors it. The invariant required is: > For any `gen_ai.conversation.id`, the sum of `gen_ai.usage.input_tokens` over spans sharing the same `gen_ai.compaction.epoch` value equals the true prompt cost of that epoch; spans from distinct epochs must not be summed ...",
    "decision_boundary": "The decision boundary is whether the agent runtime can *prove* the carryover was subtracted before emitting the span. Concretely: - If the runtime holds the pre-compaction token count in live state at the moment of re-parenting, it must emit `gen_ai.usage.input_tokens = prompt_tokens - carried_digest_tokens` on the new span, and emit the carried digest count...",
    "operational_effect": "Downstream, the inflated token count propagates into three failure surfaces. First, budget alarms fire at 3–8× the true rate on long-horizon agents, causing premature throttling of exactly the tasks that most need to run to completion. Second, cost-attribution dashboards show tool-heavy agents as disproportionately expensive, biasing routing decisions toward..."
  },
  "matched_failure_symptoms": [
    "CONTEXT_DRIFT_OR_ATTENTION_DILUTION"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "d8728db70acaf112351f6a049c84ea8f75d7a80a24f064bf120e6d106ae80d66",
    "verified_classes": [
      "CompactionAccountingError"
    ],
    "verified_functions": [
      "emit_tool_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "CompactionAccountingError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
