{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-span-lineage-when-gen-ai-attributes-are-emitted-after-a-mid-invocation-context-compaction",
  "title": "Why does an instance lose span lineage when gen_ai.* attributes are emitted after a mid-invocation context compaction?",
  "date_of_record": "2026 November 29",
  "scope": "Applies to LLM agent runtimes that emit OpenTelemetry GenAI semantic-convention spans (`gen_ai.*`) and prompt/completion events from within a single logical invocation whose context window is compacted, truncated, or re-summarized mid-flight. Does not apply to stateless single-shot inference where the span is opened and closed around one provider call with no intervening context mutation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-span-lineage-when-gen-ai-attributes-are-emitted-after-a-mid-invocation-context-compaction.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-span-lineage-when-gen-ai-attributes-are-emitted-after-a-mid-invocation-context-compaction.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-span-lineage-when-gen-ai-attributes-are-emitted-after-a-mid-invocation-context-compaction.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1401,
    "python_slice_tokens": 125,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions assume a **span is a stable, monotonic record of one model invocation**: `gen_ai.system`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and the `gen_ai.content.prompt` / `gen_ai.content.completion` events are treated as attributes of a single, immutable unit of work. The convention's implici...",
    "what_was_observed": "A tool-using agent (ReAct loop, ~14 tool calls per task) opened a parent span `gen_ai.invoke` at task start and emitted prompt/completion events per turn. On tasks exceeding ~90% of the model's context limit, a compaction step fired between turn *n* and turn *n+1*. The observed trace: 1. Turn *n* emits `gen_ai.content.prompt` with 61,204 tokens of history (correct). 2. Compaction replaces turns 1..*n-3* with a 900-to...",
    "condition_of_validity": "The GenAI conventions are valid **only when the following holds for the span's lifetime**: no operation mutates the prompt payload or the context window between span open and the emission of its final `gen_ai.content.*` event and usage attributes. Concretely: - The span must be **closed before** any compaction, summarization, eviction, or re-prompting that c...",
    "decision_boundary": "Choose the segmentation strategy at the point where the runtime *knows* it will mutate context: The boundary is **\"one span = one model-visible payload.\"** Crossing it without segmentation is the failure.",
    "operational_effect": "Downstream consumers inherit the corruption: - **Cost attribution** double-counts or under-counts input tokens depending on whether the shim summed per-turn or trusted the provider `usage` block. Observed 8–19% cost error on compacted tasks. - **Replay/eval** reconstructs a prompt the model never saw, so regression suites pass on traces that don't correspond..."
  },
  "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": "eb09e73f7b0a37dbe1286f2bd89eee95368f3b0fea284f43057994405b9a8c67",
    "verified_classes": [
      "GenAICompactionLineageError"
    ],
    "verified_functions": [
      "emit_genai_span",
      "close_invocation"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "GenAICompactionLineageError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
