{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-emit-orphaned-execute-tool-spans-when-its-parent-agent-span-is-sampled-out-mid-loop",
  "title": "Why does an instance emit orphaned `execute_tool` spans when its parent agent span is sampled out mid-loop",
  "date_of_record": "2026 November 24",
  "scope": "Applies to any agent runtime that emits OpenTelemetry GenAI semantic conventions (`gen_ai.operation.name`, `gen_ai.agent.name`, `gen_ai.tool.name`, `gen_ai.usage.*`) across a multi-step ReAct-style loop where tool calls are traced as child spans of the agent invocation span. Does not apply to single-shot completion calls with no tool fan-out, nor to runtimes that buffer the entire trace in-process and flush once at terminal state.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-emit-orphaned-execute-tool-spans-when-its-parent-agent-span-is-sampled-out-mid-loop.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-emit-orphaned-execute-tool-spans-when-its-parent-agent-span-is-sampled-out-mid-loop.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-emit-orphaned-execute-tool-spans-when-its-parent-agent-span-is-sampled-out-mid-loop.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2150,
    "python_slice_tokens": 267,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"spans go missing.\" It is the *inverse*: child `execute_tool` spans survive into the collector while their parent `invoke_agent` span is dropped, producing a structurally orphaned subtree that references a `parent_span_id` the collector never received. This is a distinct class from sampling loss at the trace root (where the whole trace die...",
    "what_was_observed": "A support-triage agent using a 12-step loop with a `search_kb` tool. Trace export via OTLP/HTTP to a collector configured with a tail sampler at a 10% policy on `gen_ai.operation.name == \"invoke_agent\"` and 100% on `gen_ai.operation.name == \"execute_tool\"`. The intent was to capture every tool call for latency SLOs while downsampling expensive agent traces. Observed trace payloads at the collector: - `execute_tool` s...",
    "condition_of_validity": "The orphan condition is *not* triggered by every sampler. It requires the conjunction of: 1. **Per-span or tail-based sampling** that evaluates the agent span and tool spans independently, rather than a head-based decision propagated via `trace_flags` / `TraceState` at trace start. Head sampling is immune because the decision is made once at the root and inh...",
    "decision_boundary": "The invariant that must hold: **for any retained span with `gen_ai.operation.name == \"execute_tool\"`, there must exist a retained ancestor with `gen_ai.operation.name == \"invoke_agent\"` in the same trace, or the tool span must be explicitly marked as parentless-by-policy.** Two admissible resolutions: - **Propagate the sampling decision at the root.** Move t...",
    "operational_effect": "The immediate effect is silent metric corruption in the tool-latency and tool-volume dashboards, which are exactly the dashboards an on-call engineer reaches for first when an agent starts misbehaving. The engineer sees tool-call volume at 12x expected and concludes the agent is looping; the actual cause is a sampler policy. Mean time to diagnosis is extende..."
  },
  "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": "1df9c91c466204b282be110be9e50cdf8c87b20b30e8f5de4ac7244e1f72f270",
    "verified_classes": [
      "OrphanedToolSpanError",
      "Span"
    ],
    "verified_functions": [
      "assert_tool_spans_anchored",
      "ingest_batch"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "OrphanedToolSpanError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
