{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-treat-a-memory-tool-latency-span-as-invalid-when-context-compaction-rewrites-the-retrieval-that-produced-it",
  "title": "Under what conditions must an instance treat a memory-tool latency span as invalid when context compaction rewrites the retrieval that produced it",
  "date_of_record": "2026 November 25",
  "scope": "Applies to agent runtimes that emit GenAI semantic-convention spans (per the OpenTelemetry GenAI conventions: `gen_ai.operation.name`, `gen_ai.agent.*`, tool/retrieval spans) around a memory-retrieval tool call whose result is later mutated by a context-compaction pass before the model consumes it. Does not apply to runtimes where compaction is disabled or where retrieval results are immutable once emitted.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-memory-tool-latency-span-as-invalid-when-context-compaction-rewrites-the-retrieval-that-produced-it.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-memory-tool-latency-span-as-invalid-when-context-compaction-rewrites-the-retrieval-that-produced-it.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-treat-a-memory-tool-latency-span-as-invalid-when-context-compaction-rewrites-the-retrieval-that-produced-it.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1871,
    "python_slice_tokens": 302,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "A memory-tool span records *the retrieval that happened*. A compaction pass records *the context that was actually delivered to the model*. These are two different events, and the GenAI conventions only give you attributes for the first. The non-obvious failure is that compaction can rewrite, truncate, or re-rank the retrieved chunk set *after* the retrieval...",
    "what_was_observed": "A retrieval tool call emitted `gen_ai.operation.name=retrieval`, `gen_ai.retrieval.top_k=8`, and a 340ms duration. The eight chunks were returned. Before the generation span opened, a compaction pass — triggered because the accumulated context crossed 82% of the window — dropped four of the eight chunks (low cosine, high token cost) and summarized two others into a single 90-token abstract. The generation span then r...",
    "condition_of_validity": "A memory-retrieval span is causally valid for a generation span if and only if all of the following hold: - The retrieval span's end timestamp precedes the generation span's start timestamp (standard causality). - **No compaction span or compaction marker exists in the trace between them that references the retrieval's `span_id` or its chunk-set digest.** - ...",
    "decision_boundary": "The boundary is *whether to trust a retrieval span as the explanation for a generation outcome*. Concretely: - If the chunk-set digest at retrieval equals the digest at generation-input assembly → the retrieval span is authoritative; attribute latency and quality to it. - If the digests differ and a compaction span with a later timestamp explains the differe...",
    "operational_effect": "Enforcing the digest invariant and emitting the compaction span changes three things: 1. **Memory latency becomes end-to-end.** The metric must be `retrieval_duration + compaction_duration` for any turn where compaction fired, keyed off the compaction span's parent linkage. Dashboards that report only retrieval duration will systematically under-report on ex..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION",
    "CONTEXT_DRIFT_OR_ATTENTION_DILUTION"
  ],
  "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": "f365f4e26881e7521dfdd5a2c5dd4d570a8f65d1e1524342f05f442115cb0a3c",
    "verified_classes": [
      "RetrievalAttributionError",
      "RetrievalSpan",
      "CompactionSpan",
      "GenerationSpan"
    ],
    "verified_functions": [
      "validate_retrieval_attribution",
      "digest",
      "digest"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "RetrievalAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
