{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-genai-span-trees-from-misattributing-tool-call-latency-to-the-wrong-turn-in-multi-turn-agents",
  "title": "Which invariants prevent GenAI span trees from misattributing tool-call latency to the wrong turn in multi-turn agents",
  "date_of_record": "2026 November 21",
  "scope": "Applies to agents emitting OpenTelemetry spans under the GenAI semantic conventions (`gen_ai.*`) where a single logical conversation spans multiple turns and each turn issues one or more tool calls. Does not apply to single-shot inference calls or to agents whose tool invocations are stateless and never re-entered across turns.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-trees-from-misattributing-tool-call-latency-to-the-wrong-turn-in-multi-turn-agents.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-trees-from-misattributing-tool-call-latency-to-the-wrong-turn-in-multi-turn-agents.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-genai-span-trees-from-misattributing-tool-call-latency-to-the-wrong-turn-in-multi-turn-agents.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2027,
    "python_slice_tokens": 394,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define span attributes (`gen_ai.operation.name`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.tool.name`, `gen_ai.conversation.id`) but they do **not** mandate a parent-child topology that binds a tool span to the *turn* that emitted it. The convention binds attributes to spans; it does not bind spans to a conve...",
    "what_was_observed": "A three-turn agent session against a retrieval tool. Turn 1 issues `search_docs`, the tool returns in 40 ms, the model then produces a partial answer and requests a second tool (`fetch_page`) on turn 2. The runtime had wrapped both tool calls in a single `execute_tool` span that opened on turn 1 and closed on turn 2 after the second tool returned. Observed span tree after export: - `gen_ai.chat` (turn 1) — parent of ...",
    "condition_of_validity": "The invariant holds — that is, span topology faithfully reflects turn topology — only when all three of the following are true: 1. **The tool span's lifetime is bounded by the turn that dispatched the tool.** The span must open when the tool is dispatched and close when the tool result is returned to the model, before the model's next generation begins. A to...",
    "decision_boundary": "The boundary is whether to model the tool call as a **child of the turn** or as a **child of a session-scoped executor**. The convention is silent, and both are defensible in isolation. The decision rule: - If the agent can dispatch multiple tools *concurrently within one turn* and the model waits on all of them, a session-scoped executor span is acceptable ...",
    "operational_effect": "The practical consequences: - **Latency SLOs computed per turn are wrong in the direction of over-attributing to tools.** A p99 tool-latency alert built on `gen_ai.tool` spans parented under `execute_tool` will fire on model-thinking stalls, not tool stalls. On-call chases the retrieval service while the model is the actual slow component. - **Token accounti..."
  },
  "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": "765c8d076097f8bb0818236fc1ce862950ce384c879d1227635b5ee7749f5f37",
    "verified_classes": [
      "GenAISpanInvariantError",
      "SpanRecord"
    ],
    "verified_functions": [
      "validate_tool_span",
      "validate_replay_disambiguation"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 7,
    "raised_exceptions": [
      "GenAISpanInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
