{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-span-level-token-accounting-when-a-sub-agent-s-trace-context-is-re-parented-across-an-asynchronous-mcp-tool-boundary",
  "title": "How should an instance reconcile span-level token accounting when a sub-agent’s trace context is re-parented across an asynchronous MCP tool boundary",
  "date_of_record": "2026 November 26",
  "scope": "Applies to observability pipelines that attribute LLM token cost and latency to parent agent spans via distributed trace context (W3C `traceparent`/`tracestate`) propagated through MCP tool calls, A2A handoffs, or message-queue mediated sub-agent invocations. Does not apply to single-process, synchronous agent loops where span parentage is established by call-stack nesting.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-span-level-token-accounting-when-a-sub-agent-s-trace-context-is-re-parented-across-an-asynchronous-mcp-tool-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-span-level-token-accounting-when-a-sub-agent-s-trace-context-is-re-parented-across-an-asynchronous-mcp-tool-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-span-level-token-accounting-when-a-sub-agent-s-trace-context-is-re-parented-across-an-asynchronous-mcp-tool-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1721,
    "python_slice_tokens": 270,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There is a difference between *trace continuity* (the causal chain from root agent to leaf tool call remains unbroken) and *cost attribution correctness* (every token billed to an LLM provider is counted exactly once under the span that actually caused the spend). Observability pipelines routinely conflate these. When a sub-agent is invoked asynchronously—fo...",
    "what_was_observed": "A three-tier orchestration: a planner agent (root), a retrieval sub-agent invoked via MCP over a broker, and a synthesis agent invoked via A2A. All three emit OTel spans with `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` attributes. The collector pipeline batches spans in 5-second windows and joins them on `trace_id` for cost rollups. During a 40-minute incident, the cost dashboard under-reported total...",
    "condition_of_validity": "The invariant `sum(attributed_cost[root]) == sum(provider_usage[trace_id])` holds only under three simultaneous conditions: 1. **Parent span existence at join time.** Every child span’s `parent_span_id` must resolve to a span already persisted in the backend before the child is joined. This requires either (a) out-of-order-tolerant join logic with a bounded ...",
    "decision_boundary": "The architect must choose between two bounded strategies at the MCP/A2A boundary: - **Strict parent-first with redelivery idempotency:** The worker must not emit child LLM spans until it has confirmed the parent `tools/call` span is committed (e.g., via a collector ack). On redelivery, the worker must detect the duplicate `message_id` and *suppress* re-emiss...",
    "operational_effect": "The practical consequence is that cost dashboards and trace graphs can disagree while both are “correct” under their own join semantics. Operators must instrument a **reconciliation gap metric**: `abs(sum(attributed_cost[trace_id]) - sum(provider_usage[trace_id]))` per trace, emitted as a gauge. A non-zero gap is the only reliable signal that a boundary has ..."
  },
  "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": "e72c21d52377a3889c222d683b3fb438288b701d080e644637da9e49a64734b6",
    "verified_classes": [
      "TraceAttributionError",
      "SpanRecord",
      "ProviderUsage"
    ],
    "verified_functions": [
      "reconcile_cost"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "TraceAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
