{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-a-tool-call-span-whose-gen-ai-usage-attributes-were-attributed-to-the-wrong-agent-turn-during-mcp-handoff",
  "title": "How does an instance detect a tool-call span whose `gen_ai.usage.*` attributes were attributed to the wrong agent turn during MCP handoff?",
  "date_of_record": "2026 December 1",
  "scope": "Applies to agents emitting OpenTelemetry GenAI spans (`gen_ai.operation.name`, `gen_ai.tool.call.id`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) across a multi-agent or MCP-client/server boundary where the tool executor is a distinct process. Does not apply to single-process, single-loop agents whose tool spans are children of the same `trace_id` and `span_id` lineage without transport.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-tool-call-span-whose-gen-ai-usage-attributes-were-attributed-to-the-wrong-agent-turn-during-mcp-handoff.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-tool-call-span-whose-gen-ai-usage-attributes-were-attributed-to-the-wrong-agent-turn-during-mcp-handoff.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-a-tool-call-span-whose-gen-ai-usage-attributes-were-attributed-to-the-wrong-agent-turn-during-mcp-handoff.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1757,
    "python_slice_tokens": 414,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The OpenTelemetry GenAI semantic conventions model a tool call as a **child span** of the agent-turn span that emitted it, with usage attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) attached to the *turn* span, not the tool span. This is a **structural** invariant: the turn span's usage must equal the sum of usage across its LLM sub-ca...",
    "what_was_observed": "A two-agent pipeline: an orchestrator (`agent.turn` spans, one per reasoning step) calls a retrieval tool hosted on an MCP server that itself invokes an embedding model. Trace excerpt captured at the collector: `C4` is the *retrieval call issued during turn 1*, but its `parent_span_id` is `A3` (turn 2). The MCP server received `parent_span_id=B2` in the `tools/call` params, but the server's OTel SDK was configured wi...",
    "condition_of_validity": "The invariant **\"every `execute_tool` span is a child of the turn span that issued the `tools/call`\"** holds only when: 1. The `traceparent` (or `tracestate`) is propagated in the MCP request's `_meta` field and the server's tracer is a `ParentBased` sampler that honors it. 2. The tool result is *awaited* within the issuing turn — i.e., the turn span has not...",
    "decision_boundary": "An instance must treat the following as a **hard boundary** and refuse to emit usage attributes on a turn span if the boundary is crossed: - **Boundary:** `turn_span.end_time < tool_span.start_time` for any tool span that was issued *by* that turn. If true, the tool span cannot be a child; the turn is **closed** and any usage arriving later belongs to a *syn...",
    "operational_effect": "When the boundary is respected, the collector's usage reconciliation becomes a **join on `gen_ai.tool.call.id`** rather than a tree walk, which is stable under re-parenting. The operational effect on a running agent: 1. **Cost dashboards** must be rewritten from `SUM(usage) GROUP BY parent_span_id` to `SUM(usage) GROUP BY gen_ai.tool.call.id` joined to the 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": "891431f5484065e707913999708dfb285aa098cf4e8bf7f1f0a015068d62752b",
    "verified_classes": [
      "ParentageMismatchError",
      "TurnSpan",
      "ToolSpan",
      "GenAITraceReconciler"
    ],
    "verified_functions": [
      "__init__",
      "register_turn",
      "issue_tool_call",
      "record_tool_span",
      "reconcile_usage"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "ParentageMismatchError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing",
      "uuid"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
