{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-causal-trace-stitching-from-silently-re-parenting-tool-spans-after-an-agent-retry",
  "title": "Which invariants prevent causal trace stitching from silently re-parenting tool spans after an agent retry",
  "date_of_record": "2026 November 28",
  "scope": "Applies to distributed tracing of LLM agent runs where a single logical agent invocation can be retried, re-planned, or forked (parallel tool fan-out), and where span parentage is reconstructed from asynchronous telemetry emitted by heterogeneous runtimes. Does not apply to single-process, synchronous, single-span-per-request tracing.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-causal-trace-stitching-from-silently-re-parenting-tool-spans-after-an-agent-retry.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-causal-trace-stitching-from-silently-re-parenting-tool-spans-after-an-agent-retry.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-causal-trace-stitching-from-silently-re-parenting-tool-spans-after-an-agent-retry.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1717,
    "python_slice_tokens": 324,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure we care about is not *missing* spans. Missing spans are loud: the trace has a hole and dashboards go red. The dangerous case is **structurally valid but causally wrong** parentage — a tool span that gets stitched under the wrong agent attempt after a retry, producing a trace that is internally consistent, passes schema validation, renders cleanly...",
    "what_was_observed": "A planner-executor agent ran a task with three tool calls (`search`, `fetch`, `summarize`). The agent runtime used an LLM call per step. On step 2 (`fetch`), the model emitted a malformed tool-arguments JSON; the runtime caught the validation error, discarded the attempt, and re-invoked the LLM with a repair prompt. The retried LLM call produced valid arguments, `fetch` succeeded, and `summarize` ran. Telemetry was e...",
    "condition_of_validity": "The re-parenting occurs iff all of the following hold simultaneously: 1. **Attempt-ambiguous correlation key.** The join key (`step_id`) is scoped to the logical step, not the attempt. Any retry, repair, or re-plan that reuses the logical key creates ≥2 candidate parents for one child. 2. **Arrival-order tie-breaking.** The stitcher resolves multi-parent amb...",
    "decision_boundary": "The boundary is between *referential* stitching and *causal* stitching: - **Referential stitching** answers \"does `parent_span_id` point at a span that exists in this trace?\" It is cheap, schema-checkable, and blind to retries. - **Causal stitching** answers \"did this child actually execute under this parent attempt, and did the parent's attempt begin before...",
    "operational_effect": "Without the invariant, retries poison the trace graph in a way that is invisible to every standard observability check. Cost dashboards over-attribute to error paths; latency percentiles blend failed-attempt tool calls into successful ones; root-cause queries invert the causal direction of tool failures. The corruption is *persistent* — once stitched, the tr..."
  },
  "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": "c4b88d5bffcd047d3ef3d7de04da818d2f82dc37d9c50073429b9021e8a0d803",
    "verified_classes": [
      "CausalStitchError",
      "Span"
    ],
    "verified_functions": [
      "stitch_tool_span"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "CausalStitchError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
