{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-silent-token-accounting-divergence-when-a-genai-agent-span-s-genai-usage-output-tokens-is-emitted-before-the-model-s-strea",
  "title": "How does an instance detect silent token-accounting divergence when a GenAI agent span's `genai.usage.output_tokens` is emitted before the model's streaming tool-call arguments finish and the span closes with a partial `genai.tool.call.arguments`?",
  "date_of_record": "2026 November 28",
  "scope": "Applies to LLM agent runtimes that emit OpenTelemetry GenAI spans (`gen_ai.*` attributes) around streaming chat completions that produce tool calls, where the usage block is captured from the stream trailer and the span is ended by the tool-dispatch layer. Does not cover non-streaming completions, nor providers that emit usage only at request end via a separate billing API.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-silent-token-accounting-divergence-when-a-genai-agent-span-s-genai-usage-output-tokens-is-emitted-before-the-model-s-strea.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-silent-token-accounting-divergence-when-a-genai-agent-span-s-genai-usage-output-tokens-is-emitted-before-the-model-s-strea.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-silent-token-accounting-divergence-when-a-genai-agent-span-s-genai-usage-output-tokens-is-emitted-before-the-model-s-strea.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1846,
    "python_slice_tokens": 276,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct notions of \"the span is complete\" that OpenTelemetry GenAI conventions conflate at the agent layer: 1. **Transport completion** — the model's HTTP/SSE stream returned a terminal `[DONE]` or `finish_reason: tool_calls`, and the usage block (`prompt_tokens`, `completion_tokens`, `total_tokens`) is now known. 2. **Semantic completion** — ...",
    "what_was_observed": "A tool-calling agent (single model, streaming, temperature 0.2, max_tokens 4096) dispatched `write_file` calls whose `content` argument routinely exceeded 2 KB. The instrumentation wrapped `chat.completions.create(stream=True)` and: - opened the span at request time, setting `gen_ai.operation.name = \"chat\"`, `gen_ai.request.model`, `gen_ai.usage.input_tokens` on first chunk; - accumulated `tool_calls` by index into a...",
    "condition_of_validity": "The invariant that must hold for a GenAI agent span to be trustworthy: > **Token-accounting closure.** For any span where `gen_ai.operation.name ∈ {chat, execute_tool}` and a tool call is recorded, the concatenated `genai.tool.call.arguments` payload must be a complete, parseable serialization, *and* `genai.usage.output_tokens` must have been read from a str...",
    "decision_boundary": "The runtime must choose, per span, between two close policies: - **Close-on-transport (fast, lossy):** end span when usage is observed. Cheap, but violates token-accounting closure whenever argument deltas trail the usage chunk. Produces spans that are individually plausible and collectively wrong — the worst failure class, because per-span validation passes...",
    "operational_effect": "With close-on-transport, the observable symptoms are: (1) ~0.3% of tool-call spans carry unparseable arguments while reporting full token counts; (2) token-cost dashboards derived from `genai.usage.output_tokens` overstate the *usable* output, because the truncated arguments represent tokens that were billed but never reached the tool — the agent then re-iss..."
  },
  "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": "96ba80213de82a0701fda14a71191fb78905596396f26d2c19c167b90faab605",
    "verified_classes": [
      "TokenAccountingClosureError",
      "ToolCallAccumulator"
    ],
    "verified_functions": [
      "close_genai_span",
      "ingest_delta",
      "seal",
      "is_complete"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenAccountingClosureError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "json"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
