{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-tool-call-lineage-when-opentelemetry-genai-spans-batch-token-accounting-across-a-mid-execution-context-compaction",
  "title": "Why does an instance lose tool-call lineage when OpenTelemetry GenAI spans batch token accounting across a mid-execution context compaction?",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents that emit OTel GenAI semantic-convention spans (`gen_ai.*`) for tool invocations while a context-management layer compacts or truncates history mid-run. Does not apply to single-shot, non-tool-using inference calls or to agents whose context never exceeds the window.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-lineage-when-opentelemetry-genai-spans-batch-token-accounting-across-a-mid-execution-context-compaction.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-lineage-when-opentelemetry-genai-spans-batch-token-accounting-across-a-mid-execution-context-compaction.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-lineage-when-opentelemetry-genai-spans-batch-token-accounting-across-a-mid-execution-context-compaction.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1453,
    "python_slice_tokens": 334,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat a span as the atomic unit of attribution: `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` are recorded per span, and tool lineage is expressed through parent/child span relationships plus `gen_ai.tool.name` / `gen_ai.tool.call.id`. This model assumes the *content* of a span's input is stable for the life of t...",
    "what_was_observed": "An agent running a 40-step tool loop hit ~92% of a 128k context window at step 22. The context manager triggered a summarization pass: it replaced steps 1–18's raw tool outputs with a ~1.8k-token summary, then resumed. Spans continued to be emitted normally. Two anomalies appeared downstream: 1. **Lineage orphaning.** A tool-call span at step 26 carried `gen_ai.tool.call.id` referencing a prior call whose output had ...",
    "condition_of_validity": "The invariant that holds in the absence of compaction: **for any tool-call span S, the token count on S equals the tokens of the input actually presented at S, and every `gen_ai.tool.call.id` referenced by S resolves to a span whose recorded output is still retrievable.** Compaction breaks the second clause unconditionally (evicted outputs are gone) and brea...",
    "decision_boundary": "The boundary is whether the accounting consumer needs **per-span truth** or **run-level truth**, and whether lineage consumers tolerate dangling edges. - If only per-span cost attribution is needed (e.g., chargeback per tool), the immutable flushed spans are correct — do nothing. - If run-level cost or lineage reconstruction is needed, the un-instrumented co...",
    "operational_effect": "Teams that skip the compaction span get dashboards that are confidently wrong: lineage graphs with edges that resolve to nothing, and cost totals that drift upward with every compaction cycle in proportion to how much retained history is re-sent. The fix is cheap but must be enforced at emit time, because the information needed to reconcile (which call IDs w..."
  },
  "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": "44afa5f206f011b8594e51708961801036490918f5a30057263d31e92f6509c9",
    "verified_classes": [
      "LineageAccountingError",
      "CompactionEvent",
      "RunLedger"
    ],
    "verified_functions": [
      "emit_tool_span",
      "compact",
      "run_total"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "LineageAccountingError"
    ],
    "sample_fail_closed_invariants": [
      "cannot publish run total across unrecorded compaction"
    ],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
