{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-replay-diverge-from-its-recorded-otel-trace-when-the-memory-snapshot-is-restored-before-the-trace-s-last-span-closes",
  "title": "Why does an instance replay diverge from its recorded OTel trace when the memory snapshot is restored before the trace's last span closes?",
  "date_of_record": "2026 November 30",
  "scope": "Applies to deterministic-replay and time-travel-debugging harnesses that reconstruct an agent run from (a) an OpenTelemetry span tree with recorded tool I/O and (b) a serialized memory/state snapshot captured at some checkpoint. Does not apply to live re-execution against real tools, nor to traces that omit tool request/response payloads.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-replay-diverge-from-its-recorded-otel-trace-when-the-memory-snapshot-is-restored-before-the-trace-s-last-span-closes.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-replay-diverge-from-its-recorded-otel-trace-when-the-memory-snapshot-is-restored-before-the-trace-s-last-span-closes.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-replay-diverge-from-its-recorded-otel-trace-when-the-memory-snapshot-is-restored-before-the-trace-s-last-span-closes.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1648,
    "python_slice_tokens": 352,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A trace and a snapshot are two different clocks over the same run. The trace is an **append-only log of observed events**, ordered by wall-clock and parent-child span nesting. The snapshot is a **point-in-time materialization of state**, and it carries an implicit *cut*: the instant at which the serialization began relative to in-flight spans. Replay correct...",
    "what_was_observed": "A multi-step agent run (retrieval → tool call → memory write) was captured with OTel spans. Spans: `S0 plan` (root), `S1 tool:vector_search`, `S2 tool:memory_write`, `S3 finalize`. A snapshot was taken by a background serializer triggered on a timer. The serializer walked the live agent object graph — including the mutable `memory` dict — while `S2` was in flight. Because `memory_write` mutates the dict *before* the ...",
    "condition_of_validity": "Deterministic replay is sound only under the **snapshot-causality invariant**: > For every span `s` in the trace, the snapshot's inclusion of `s`'s effects is equivalent to `s` being a strict ancestor of the checkpoint span `c` in the span tree, where `c` is the deepest span with `end_time ≤ snapshot_ts`. This invariant holds only when the snapshot is captur...",
    "decision_boundary": "The replay engine must branch on whether the checkpoint's open-span set is empty: - **Quiescent snapshot (no open spans):** replay from checkpoint `c`; re-execute all descendants of `c`. Sound. - **Non-quiescent snapshot (open spans at capture):** the harness must *not* assume `c`'s descendants are unapplied. For each open span `o`, consult the tool's declar...",
    "operational_effect": "Harnesses that ignore effect-ordering produce **silent double-application** on mutate-then-close tools and **silent dropped-application** on close-then-commit tools. Both pass span-diff validation because the *recorded* outputs are replayed from the log rather than recomputed, masking the state divergence. The divergence only manifests as a downstream fork i..."
  },
  "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": "2089ca88881c2aef1f9f405e1b5da1f7fee36c1656dee18f98187f1c11125f20",
    "verified_classes": [
      "ReplayDivergenceError",
      "EffectOrdering",
      "Span",
      "Snapshot"
    ],
    "verified_functions": [
      "plan_replay",
      "replay"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "ReplayDivergenceError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
