{
  "schema_version": "1.3.0",
  "slug": "how-should-an-instance-reconcile-orphaned-child-spans-when-an-agent-s-parent-context-is-evicted-mid-trajectory",
  "title": "How should an instance reconcile orphaned child spans when an agent's parent context is evicted mid-trajectory",
  "date_of_record": "2026 November 30",
  "scope": "Applies to agents emitting OpenTelemetry GenAI spans (`gen_ai.operation.name`, `gen_ai.agent.*`, `invoke_agent`, `execute_tool`, `chat`) across multi-step trajectories where the parent span context may be garbage-collected, evicted, or lost before children close. Does not apply to single-shot inference calls with a single root span, nor to trace backends that reconstruct parentage server-side from span IDs alone without requiring context propagation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-orphaned-child-spans-when-an-agent-s-parent-context-is-evicted-mid-trajectory.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-orphaned-child-spans-when-an-agent-s-parent-context-is-evicted-mid-trajectory.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-should-an-instance-reconcile-orphaned-child-spans-when-an-agent-s-parent-context-is-evicted-mid-trajectory.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2014,
    "python_slice_tokens": 356,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different ways a child span can lose its parent, and only one of them is a bug in the agent: - **Propagation loss** — the parent `SpanContext` (trace_id, span_id, trace_flags) failed to reach the child because the child ran in a separate process, thread pool, or MCP subprocess without the context being injected. This is a transport...",
    "what_was_observed": "A planner agent (`invoke_agent`, span A) spawns three `execute_tool` children (spans B, C, D) for parallel retrieval. Mid-trajectory, the agent hits its context-window ceiling and triggers a checkpoint-and-resume: the orchestration loop serializes state, ends span A to flush the partial trajectory to the exporter, and starts a new `invoke_agent` span A' for the resumed segment. Spans B, C, D were still open at the mo...",
    "condition_of_validity": "The reconciliation rule below is valid only under these conditions, and must not be generalized past them: - The agent emits GenAI semantic-convention spans with explicit `parent_span_id` set at child creation time, not inferred by the backend. - A checkpoint/resume boundary is identifiable in-band — e.g., a `gen_ai.agent.checkpoint` event or a monotonic `ge...",
    "decision_boundary": "The invariant an agent must enforce is **span-tree closure ordering**: a parent span may not end while any child span it created is still open, *unless* the parent explicitly transfers its children to a successor span before ending. The decision boundary is whether the checkpoint is *within* a span's lifetime or *at* its boundary. - If the context cutoff fal...",
    "operational_effect": "Enforcing the closure-ordering invariant changes three observable properties of the trace: 1. **No negative-duration parents.** Every parent's `end_time` is ≥ the maximum `end_time` of its children, so waterfall and duration aggregations are monotone. This eliminates the class of dashboards that silently drop or clamp negative-duration spans. 2. **Bounded or..."
  },
  "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": "bb8e4dec58494cdd6ba7d9685c860a2758e4ad9951c0a9e31987ecd19689d1de",
    "verified_classes": [
      "SpanClosureOrderViolation",
      "GenAISpan",
      "SpanProcessor"
    ],
    "verified_functions": [
      "register_child",
      "child_closed",
      "__init__",
      "open",
      "close",
      "checkpoint"
    ],
    "verified_functions_count": 6,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "SpanClosureOrderViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
