{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-tool-call-attribution-when-a-child-span-outlives-its-parent-s-genai-semantic-context",
  "title": "Why does an instance lose tool-call attribution when a child span outlives its parent’s GenAI semantic context",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans using the GenAI semantic conventions (`gen_ai.*`), where tool calls are modeled as child spans under an LLM inference span, and where span export is asynchronous relative to the agent’s execution loop. Does not apply to synchronous in-process exporters that block until export completes, nor to runtimes that flatten all agent activity into a single span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-attribution-when-a-child-span-outlives-its-parent-s-genai-semantic-context.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-attribution-when-a-child-span-outlives-its-parent-s-genai-semantic-context.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-tool-call-attribution-when-a-child-span-outlives-its-parent-s-genai-semantic-context.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1864,
    "python_slice_tokens": 432,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions treat *attributes* as immutable annotations attached to a span at creation or during its lifetime, and *context propagation* as the mechanism by which a child span inherits the trace/span identity of its parent. These are two separate contracts. The failure mode here is not a broken trace (parent-child linkage survives), but a ...",
    "what_was_observed": "An agent loop issues an LLM inference call. The runtime opens a span `S_infer` and sets `gen_ai.operation.name = \"chat\"`, `gen_ai.request.model = \"gpt-4o\"`, and, after the response returns, `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`. The model responds with a tool-call request. The runtime then opens a child span `S_tool` for the tool execution, correctly parented to `S_infer`. The tool is slow (a web...",
    "condition_of_validity": "The invariant that must hold is: *a span’s semantic attributes are fully determined at span creation or by values captured into the span’s own attribute map before any ancestor can be exported.* Equivalently: **no span may resolve its `gen_ai.*` attributes by traversing to a parent that is subject to independent export and eviction.** This condition is valid...",
    "decision_boundary": "The architectural guardrail is a **capture-at-creation rule for semantic context**, enforced structurally rather than by convention: - At the moment `S_tool` is created, the runtime copies the parent’s `gen_ai.request.model`, `gen_ai.operation.name`, and any cost-rate context into `S_tool`’s own attribute map. The child never reads the parent again. - Token ...",
    "operational_effect": "The downstream effect is a **silent cost and token undercount proportional to tool latency**, concentrated in exactly the sessions that do the most tool work — long agent runs, slow external APIs, sandboxed code execution. Because the trace is structurally valid, trace-based debugging does not surface it; only the cost-attribution join, which keys on `gen_ai..."
  },
  "matched_failure_symptoms": [
    "SUBPROCESS_PIPE_HANG_OR_FD_LEAK"
  ],
  "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": "5b5041fa459bb3e891955a1396b48817731e0a45c27ebf98bf768c00117ed0f1",
    "verified_classes": [
      "SemanticContextEvictionError",
      "Span",
      "ActiveSpanRegistry"
    ],
    "verified_functions": [
      "capture_at_creation",
      "run_agent_turn",
      "__init__",
      "register",
      "export",
      "resolve_genai_attr"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "SemanticContextEvictionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
