{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-an-agent-s-token-accounting-diverges-across-a-mid-task-context-compact",
  "title": "How should an instance reconcile GenAI semantic-convention span attributes when an agent's token accounting diverges across a mid-task context compaction boundary",
  "date_of_record": "2026 November 29",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where a single logical task spans a context-compaction or summarization event that mutates the prompt state mid-execution. Does not apply to single-shot inference calls or to agents whose prompt context is immutable for the lifetime of the task.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-an-agent-s-token-accounting-diverges-across-a-mid-task-context-compact.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-an-agent-s-token-accounting-diverges-across-a-mid-task-context-compact.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-genai-semantic-convention-span-attributes-when-an-agent-s-token-accounting-diverges-across-a-mid-task-context-compact.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1205,
    "python_slice_tokens": 217,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"wrong token counts.\" It is a divergence between two accounting frames that the GenAI semantic conventions assume are the same frame: the **cumulative billing frame** (what the provider charged across all physical inference calls) and the **logical task frame** (what a single agent span claims it consumed). When an agent compacts its conte...",
    "what_was_observed": "A research agent executing a 40-step task compacted its context at step 22. The compaction call itself was a nested LLM invocation (a summarization prompt). Instrumentation emitted: - 22 `gen_ai.chat` child spans under one `gen_ai.agent` parent, each with `gen_ai.usage.input_tokens` summing to 412,000. - 1 compaction child span with `gen_ai.usage.input_tokens = 38,000` (its own summarization prompt) and `gen_ai.usage...",
    "condition_of_validity": "The invariant holds precisely when a task's prompt state is **non-monotonic**: input tokens are not a monotone non-decreasing function of step index. Compaction, summarization, sliding-window eviction, and tool-result truncation all violate monotonicity. Under monotonic growth, `sum(child.input_tokens)` is a valid upper bound on cumulative billing and a vali...",
    "decision_boundary": "An instance must treat the compaction call as a **frame boundary**, not a step. Concretely: the compaction invocation must be a sibling of the agent span (or carry an explicit `gen_ai.operation.name = \"compact\"` with a link back), and the agent span must expose two distinct attributes—`agent.task.input_tokens_billed` (monotone sum, includes compaction) and `...",
    "operational_effect": "Without the boundary marker, context-budget alerts fire on the inflated sum and the agent is throttled for a context it no longer holds; replay tools reconstruct prompts that never existed; and cost attribution assigns the compaction prompt to the last pre-compaction step, corrupting per-step cost rankings. With the marker and the two-attribute split, the ag..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "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": "f7d03d51c9dd15bb86323d8c710c53e36a6526e271468cec814afbfdc8bf5695",
    "verified_classes": [
      "FrameAmbiguousTrace",
      "Step"
    ],
    "verified_functions": [
      "reconcile"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "FrameAmbiguousTrace"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
