{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-span-parent-corruption-when-opentelemetry-genai-tool-call-graphs-are-reconstructed-across-agent-re-entrancy",
  "title": "Which invariants prevent span-parent corruption when OpenTelemetry GenAI tool-call graphs are reconstructed across agent re-entrancy",
  "date_of_record": "2026 November 24",
  "scope": "Applies to agents that emit OpenTelemetry GenAI spans (`gen_ai.operation.name`, `gen_ai.tool.name`, `gen_ai.agent.id`) for tool-call graphs where a single logical agent turn may suspend and resume (human-in-the-loop, async tool completion, or checkpoint/restore). Does not apply to stateless single-shot inference spans with no tool fan-out.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-parent-corruption-when-opentelemetry-genai-tool-call-graphs-are-reconstructed-across-agent-re-entrancy.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-parent-corruption-when-opentelemetry-genai-tool-call-graphs-are-reconstructed-across-agent-re-entrancy.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-parent-corruption-when-opentelemetry-genai-tool-call-graphs-are-reconstructed-across-agent-re-entrancy.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1327,
    "python_slice_tokens": 236,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions describe *what* a span represents (`gen_ai.operation.name = execute_tool`, `chat`, `invoke_agent`) but they do **not** define a parent-child invariant that survives agent re-entrancy. The tracer's ambient context (`contextvars` in Python, `AsyncLocalStorage` in Node) is a *thread/task-local* pointer to the current span. When an...",
    "what_was_observed": "An `invoke_agent` span `A` (agent turn) emits a `chat` span `C1`, which requests tool `T1`. `T1` is a long-running async operation. The agent checkpoints and the worker task ends; span `A` remains open (or is serialized as a checkpoint with its `trace_id`/`span_id`). On resume, a fresh worker picks up the checkpoint and executes `T1`'s completion, emitting `execute_tool` span `T1'`. Three failure traces were observed...",
    "condition_of_validity": "Reconstruction is only sound when all of the following hold: - The agent records the requesting `chat` span's `span_id` **at the moment the tool call is decided**, and persists that `span_id` in the checkpoint alongside the tool invocation payload. - On resume, the emitter sets the parent **explicitly** from the persisted `span_id` (via `trace.set_span_in_co...",
    "decision_boundary": "Choose explicit-parent reconstruction (persist `span_id`, set parent from checkpoint) over ambient-context inheritance whenever **any** of: tool calls can outlive a worker task; the agent checkpoints; workers are pooled/reused; or a single agent turn emits tool spans from more than one execution context. Ambient inheritance is acceptable only for fully synch...",
    "operational_effect": "Without the invariant, tool-call graphs silently mis-attribute latency, break verifier replay (the auditor reconstructs a different graph than the executor emitted), and fail consensus checks that compare fan-out counts. Enforcing persisted-parent + idempotency key + context clearing converts all three failure traces into a single detectable condition: a res..."
  },
  "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": "00afbe56ae89e7ed3e6c09c79ff45db2048411ca203540671341642b46d75ba7",
    "verified_classes": [
      "SpanParentCorruption",
      "ToolCheckpoint"
    ],
    "verified_functions": [
      "emit_resumed_tool_span",
      "idempotency_key"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "SpanParentCorruption"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
