{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-lose-causal-linkage-between-prompt-tool-and-memory-spans-when-a-memory-write-span-is-emitted-after-the-tool-span-closes-but-befor",
  "title": "Why does an instance lose causal linkage between prompt, tool, and memory spans when a memory-write span is emitted after the tool span closes but before the prompt span's response is finalized",
  "date_of_record": "2026 November 29",
  "scope": "Applies to observability pipelines that reconstruct a single causal trace by joining prompt spans, tool-call spans, and memory-operation spans emitted by an agent runtime. Does not apply to single-span logging or to runtimes that emit a single composite span per turn.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-causal-linkage-between-prompt-tool-and-memory-spans-when-a-memory-write-span-is-emitted-after-the-tool-span-closes-but-befor.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-causal-linkage-between-prompt-tool-and-memory-spans-when-a-memory-write-span-is-emitted-after-the-tool-span-closes-but-befor.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-lose-causal-linkage-between-prompt-tool-and-memory-spans-when-a-memory-write-span-is-emitted-after-the-tool-span-closes-but-befor.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1922,
    "python_slice_tokens": 406,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing telemetry.\" Every span is emitted, timestamped, and shipped. The failure is a **causal-ordering inversion at the join boundary**: the memory-write span carries a parent reference to the prompt span, but the prompt span's *response-finalization* event (the one that carries the final assistant message and the trace-closing timestamp...",
    "what_was_observed": "A representative trace from a retrieval-augmented agent turn: 1. `prompt.span` opens at `t0` with `span_id=P`, `parent=null`. 2. The model emits a tool call; `tool.span` opens at `t1` with `span_id=T`, `parent=P`. The tool executes and returns a document. 3. The runtime, before the model's *next* completion, distills the tool result into episodic memory and emits `memory.write.span` with `span_id=M`, `parent=P`, `sta...",
    "condition_of_validity": "The invariant holds — i.e., the failure is *possible* — only when all of the following are true: - The runtime emits memory-operation spans **lazily**, asynchronously, or on a flush timer, rather than synchronously within the tool-result handling block. - The observability backend enforces a **parent-must-be-open / response-finalization-before-child-close** ...",
    "decision_boundary": "The boundary is: **does the memory-write span's `end` timestamp precede the prompt span's `response.finalized` event?** If yes, the trace assembles cleanly. If no, the assembler must make a decision: - **Drop** the memory span (loss of observability — the memory write becomes invisible). - **Re-parent** to the nearest open ancestor (mis-attribution — the too...",
    "operational_effect": "When the boundary is crossed and the backend re-parents, the operational consequence is **mis-attributed memory cost and latency**: the tool span's reported duration absorbs the memory-write latency, inflating tool p99 and making the tool appear to be the memory bottleneck. When the backend drops, memory-write counts under-report, and a memory-growth inciden..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "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": "f7c821a5aaf9283598984287f8cb9521cf23be1f6cfea7f5a2034c98797faab0",
    "verified_classes": [
      "CausalLinkageError"
    ],
    "verified_functions": [
      "assemble_trace"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "CausalLinkageError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
