{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-trace-context-orphanage-when-agent-hops-re-parent-spans-across-mcp-and-a2a-boundaries",
  "title": "Which invariants prevent trace-context orphanage when agent hops re-parent spans across MCP and A2A boundaries",
  "date_of_record": "2026 November 30",
  "scope": "Applies to multi-hop agent systems where each LLM-driven hop emits OpenTelemetry spans and propagates W3C `traceparent`/`tracestate` through tool calls (MCP) and peer delegation (A2A). Does not cover single-process instrumentation, nor spans emitted by non-agentic infrastructure (load balancers, queues) that never re-parent.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-trace-context-orphanage-when-agent-hops-re-parent-spans-across-mcp-and-a2a-boundaries.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-trace-context-orphanage-when-agent-hops-re-parent-spans-across-mcp-and-a2a-boundaries.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-trace-context-orphanage-when-agent-hops-re-parent-spans-across-mcp-and-a2a-boundaries.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1806,
    "python_slice_tokens": 378,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two ways a trace context can \"break\" across an agent hop, and only one is a real invariant violation: 1. **Context loss** — the child hop starts a fresh root trace because `traceparent` was dropped. This is loud: `trace_id` changes, the collector sees a new root, and the orphan is visible as a disconnected trace. It is annoying but *detectable*. 2....",
    "what_was_observed": "A three-hop pipeline: orchestrator (hop 0) → retrieval agent over MCP (hop 1) → synthesis agent over A2A (hop 2). Each hop is a separate process with its own LLM loop and its own span lifecycle. Observed failure trace on a resumed task: - Hop 0 starts span `S0` (`span_id=aa..01`), emits `traceparent` `00-<trace>-aa..01-01`, then **checkpoints and suspends** mid-task. `S0` is ended locally at suspension so the span re...",
    "condition_of_validity": "The invariant that prevents orphanage is not \"propagate `traceparent`.\" It is: > **A child hop may only parent under a span that is (a) still open in the parent's process, or (b) explicitly tombstoned with a `span_id` that will never be reused, and the child must carry the parent's `epoch_id` in `tracestate` so the collector can reject cross-epoch parenting....",
    "decision_boundary": "The boundary is **resume vs. restart**: - **Resume** (same logical task, same causal chain, new process epoch): must preserve `trace_id`, must set a new `agentepoch`, must *not* reuse `span_id`s from the prior epoch, and must re-parent the resumed loop under a fresh span that carries `agentepoch` forward. Children from the prior epoch are tombstoned, not rev...",
    "operational_effect": "With the invariant enforced, three things become true that were previously false: 1. **Trace-walk queries are total.** Every span's `parent_span_id` resolves to a span in the same `agentepoch`, so parent→child walks never hit dangling parents. Latency and error attribution stop double-counting suspension gaps. 2. **Orphanage is detectable at ingest.** The co..."
  },
  "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": "b6422ddfab81288c0de4c44661c68285e70f6ff3dc03c433c4409b8e4e86a66d",
    "verified_classes": [
      "TraceContextOrphanageError",
      "SpanRef",
      "EpochAwarePropagator"
    ],
    "verified_functions": [
      "__init__",
      "register_open",
      "close_epoch",
      "child_parent",
      "_parse_epoch"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 8,
    "raised_exceptions": [
      "TraceContextOrphanageError"
    ],
    "sample_fail_closed_invariants": [
      "tracestate missing agentepoch; cannot validate parent epoch"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "re",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
