{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-genai-spans-with-tool-call-attributes-but-no-parent-agent-span-breaking-trace-based-cost-attribution",
  "title": "What happens when an instance emits GenAI spans with tool-call attributes but no parent agent span, breaking trace-based cost attribution",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.*` attributes) where per-instance token and cost telemetry is reconstructed by summing spans along a trace. Does not apply to single-span, single-call inference logging where attribution is done by direct span ID.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-with-tool-call-attributes-but-no-parent-agent-span-breaking-trace-based-cost-attribution.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-with-tool-call-attributes-but-no-parent-agent-span-breaking-trace-based-cost-attribution.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-spans-with-tool-call-attributes-but-no-parent-agent-span-breaking-trace-based-cost-attribution.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1690,
    "python_slice_tokens": 328,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe *what* to record on a span (`gen_ai.system`, `gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.tool.name`, `gen_ai.tool.call.id`), not *how spans nest*. The conventions are attribute-level, not topology-level. This produces a silent class of failure: an ...",
    "what_was_observed": "A multi-step agent (planner → tool executor → summarizer) was instrumented so that each LLM call emitted a span with `gen_ai.operation.name=chat`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, and each tool invocation emitted `gen_ai.operation.name=execute_tool` with `gen_ai.tool.name` and `gen_ai.tool.call.id`. The agent's own orchestrator span was created with `gen_ai.operation.name=invoke_agent`. Beca...",
    "condition_of_validity": "The invariant that must hold for trace-based attribution to be correct: > For every span carrying `gen_ai.usage.input_tokens` or `gen_ai.usage.output_tokens`, there exists exactly one ancestor span in the same `trace_id` with `gen_ai.operation.name=invoke_agent` and a stable `gen_ai.agent.id` scoped to the logical run. This fails when any of the following ho...",
    "decision_boundary": "The decision is whether to trust trace-based attribution or to require an explicit run identifier carried as an attribute on every span. - **Trust trace topology** only when the agent runtime guarantees that the agent span's `SpanContext` is created and made current *before* any child span is emitted, and that all tool execution paths (including subprocess a...",
    "operational_effect": "When the invariant is violated, the failure is silent at the span level (every span validates against the schema) and surfaces only as a reconciliation mismatch: sum of per-run attributed tokens ≠ sum of all `gen_ai.usage.*_tokens` across spans. The mismatch is usually small (the first tool call's tokens) and is easily dismissed as sampling or rounding. It i..."
  },
  "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": "2c2f2f0108a73eca94b4fea116605a42fd3b015b3d6be55a6717b7d0929a9de9",
    "verified_classes": [
      "OrphanedUsageSpanError",
      "Span"
    ],
    "verified_functions": [
      "assert_usage_attributable",
      "reconcile_run",
      "has_usage",
      "agent_run_id"
    ],
    "verified_functions_count": 4,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "OrphanedUsageSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing",
      "uuid"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
