{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-span-parentage-orphaning-when-an-agent-handoff-crosses-a-process-boundary-mid-tool-call",
  "title": "Which invariants prevent span-parentage orphaning when an agent handoff crosses a process boundary mid-tool-call",
  "date_of_record": "2026 November 24",
  "scope": "Applies to multi-agent systems that propagate W3C `traceparent`/`tracestate` via OpenTelemetry GenAI semantic conventions (`gen_ai.*`) across agent handoffs where the receiving agent executes tool calls in a separate process or sandbox. Does not cover single-process agents, in-process thread handoffs, or cases where the entire tool-call chain stays within one OTel SDK lifetime.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-parentage-orphaning-when-an-agent-handoff-crosses-a-process-boundary-mid-tool-call.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-parentage-orphaning-when-an-agent-handoff-crosses-a-process-boundary-mid-tool-call.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-span-parentage-orphaning-when-an-agent-handoff-crosses-a-process-boundary-mid-tool-call.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2277,
    "python_slice_tokens": 454,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure I am isolating is *not* lost spans, dropped attributes, or token-accounting drift. It is **span-parentage orphaning at handoff**: the outgoing agent closes its `gen_ai.agent.invoke` span and emits `gen_ai.tool.call` child spans whose `parent_span_id` points at a span that the receiving process never received a live reference to. The trace *looks*...",
    "what_was_observed": "A two-agent pipeline: `planner` (agent A) invokes `executor` (agent B) via an A2A-style HTTP handoff. Agent A wraps the handoff in a span `gen_ai.agent.invoke` with attributes `gen_ai.agent.name=planner`, `gen_ai.operation.name=invoke_agent`, and `gen_ai.usage.input_tokens=1840`. The handoff envelope includes the task payload and a `traceparent` header. Agent B receives the request, starts a new span `gen_ai.agent.in...",
    "condition_of_validity": "The invariant that prevents orphaning is: **the receiving agent's `gen_ai.agent.invoke` span must be made the active context before any `gen_ai.tool.call` span is created, and the handoff `traceparent` must be consumed only to establish the *parent* of the invoke span, not to seed the ambient context for tool calls.** Formally, for any handoff from agent A t...",
    "decision_boundary": "The boundary between \"safe handoff\" and \"orphaned tool call\" is whether the receiving agent's SDK detaches the extracted handoff context before entering the tool-execution loop. In practice: - **Safe:** `with tracer.start_as_current_span(\"gen_ai.agent.invoke\", context=extracted_ctx):` — the invoke span is created as a child of the handoff context, and the `w...",
    "operational_effect": "When orphaning occurs, three downstream effects compound: 1. **Token rollup undercounts.** Backends that sum `gen_ai.usage.input_tokens` over the subtree of `gen_ai.agent.invoke` (agent B) will miss the orphaned tool call's tokens. In the observed case, agent B's reported usage was 312+88 tokens short — a 14% undercount against the actual tool-call cost. Bud..."
  },
  "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": "353d5a7c2ba4dd329b388de001d90613db8f6ee8fcece3edd1ba6c773268f51a",
    "verified_classes": [
      "SpanParentageOrphanError",
      "Span"
    ],
    "verified_functions": [
      "validate_handoff_tool_parentage"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "SpanParentageOrphanError"
    ],
    "sample_fail_closed_invariants": [
      "assert 'T1' in str(exc) or 'search' in str(exc)"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
