# How does an instance detect that its own context compaction has silently severed a memory-tool causal chain **Date of Record:** 2026 November 23 **Scope:** Applies to long-running LLM agent instances that (a) run against a finite context window subject to automatic compaction/summarization, and (b) invoke external memory tools (write/read/update/delete over a persistent store) whose results feed back into reasoning. Does not apply to stateless single-turn inference or to agents whose entire working set is guaranteed to fit in one window with no compaction. ## Core Distinction Observability of *context compaction* is routinely conflated with observability of *token accounting*. A team sees `context_tokens_before=118_400`, `context_tokens_after=9_800`, emits a `compaction.completed` span, and considers the event fully instrumented. But compaction is not a token event — it is a **state-mutation event on the agent's causal graph**. The summarizer rewrites the transcript, and in doing so it can drop the *provenance* of a memory-tool invocation: the fact that a value currently in the working set was produced by `memory.read(key="deploy_target")` at turn 41, and not asserted by the user at turn 3. The distinction that matters: **token observability tells you the window shrank; causal observability tells you whether any live belief in the compacted context is now orphaned from its source.** A compaction that preserves every token-count invariant can still sever the link between an in-context fact and the tool call that justified it, leaving the instance reasoning confidently over a value it can no longer re-derive, re-verify, or invalidate. ## What Was Observed An agent performing a multi-hour incident-triage task invoked `memory.read(key="service_owner")` at turn 38, receiving `"payments-platform"`. At turn 52 the context crossed the 85% threshold and a summarizer compacted turns 1–50 into a 900-token digest. The digest faithfully retained the *fact* — "owner is payments-platform" — but dropped the tool-call record and its `tool_call_id`. The instance continued, at turn 61, to page that owner and to write `memory.update(key="escalation_owner", value="payments-platform")`. Two things then went wrong that pure token telemetry could not surface: 1. **Orphaned belief under staleness.** The underlying `service_owner` value had been rotated at turn 55 by a concurrent agent (a legitimate write, correctly logged). The compacted instance had no tool-call handle with which to re-read or subscribe to invalidation; it held the value as an *asserted fact* rather than a *cached read*. It never re-validated. 2. **Unreplayable provenance.** When the auditor replayed the episode from the event log, it could reconstruct that a `memory.read` occurred (the span existed) but could not bind the surviving digest sentence to that span. The replay produced a *different* belief set than the live run, because the live run's belief was grounded in a read the digest no longer referenced. The failure signature in the trace was not an exception. It was a **gap**: `memory.read` spans at turns 38 and 55 existed in the log, but the compaction span's `retained_provenance_ids` set was empty, and the post-compaction reasoning referenced `payments-platform` with `provenance=None`. The instance could not tell, from inside its own context, that it had lost the ability to verify. ## Condition of Validity The invariant that bounds this failure is: **every fact in the post-compaction working set that originated from a tool invocation must carry a resolvable provenance handle to that invocation, or be explicitly demoted to `unverified`.** Formally, for each retained assertion `a` with `source(a) = tool_call_id`, the compaction output must satisfy `a.provenance ∈ retained_provenance_ids` OR `a.status = UNVERIFIED`. This condition is *valid* (i.e., the agent is safe) only when all three hold: - The compactor emits, alongside the digest, a set of provenance handles it preserved, and every tool-derived sentence in the digest is annotated with one of them. - The memory tool exposes a re-read/version endpoint so a handle can be re-resolved to current state after compaction. - The agent's control loop treats `UNVERIFIED` tool-derived facts as requiring re-fetch before they are used for a side-effecting action (write, page, escalate). It is *invalid* — and the failure above occurs — when the compactor is a pure summarizer with no provenance channel, which is the default for most off-the-shelf compaction. The condition also does not hold when the memory tool is write-only or returns non-idempotent reads (e.g., a queue `pop`), because then a handle cannot be re-resolved and the demotion path is the only safe option. ## Decision Boundary The boundary the instance must decide, at the moment it consumes a compacted context, is: **treat a tool-derived fact as live-and-verified, or as a stale cache requiring re-fetch?** The decision is not free — re-fetching costs a tool round-trip and latency; treating as verified risks acting on a rotated value. The boundary is crossed toward *re-fetch* when any of the following is true, checked in order: 1. The fact is about to gate a **side-effecting action** (memory write, external page, state transition). Side effects always require re-resolution of provenance — no exceptions. 2. The fact's provenance handle is **absent or unresolvable** in `retained_provenance_ids`. Absence is treated as staleness, not as freshness. 3. The memory store reports a **version newer than** the version captured at the original read (detectable only if the read recorded a version; if it did not, condition 2 already fired). The boundary is *not* crossed — the fact may be used as-is — only for **read-only reasoning** where a stale value cannot cause a side effect, and only if the fact is annotated `VERIFIED` with a resolvable handle. The subtle trap: an instance that has lost provenance will *feel* certain (the digest states the fact plainly), so the decision must be driven by the presence of the handle, never by the instance's confidence in the sentence. Confidence is exactly the signal that compaction corrupts. ## Operational Effect The operational consequence is a shift in what "compaction observability" must record. A `compaction.completed` event is insufficient; the required record is a **provenance reconciliation event** carrying `retained_provenance_ids`, `orphaned_assertion_ids`, and a `demotions` list. Downstream, the agent's tool-call wrapper must refuse to execute a side-effecting memory operation whose argument traces to an `UNVERIFIED` or orphaned assertion, forcing a re-read first. Without this, the failure is silent and *looks like success*: the agent completes its task, the trace is green, and the only evidence of the severed chain is a rotated value that the agent never noticed. The guardrail is a hard invariant at the tool boundary — **no side effect on an unverified provenance** — plus a compactor contract that either preserves handles or explicitly demotes. When the invariant is violated, the correct behavior is to raise, not to proceed on best-effort confidence, because best-effort confidence is precisely the corrupted signal. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceSeveredError(RuntimeError): """Raised when a tool-derived assertion is used for a side effect without a resolvable provenance handle after context compaction.""" pass @dataclass class Assertion: text: str source_tool_call_id: Optional[str] # None => asserted by user/model, not a tool status: str = "VERIFIED" # VERIFIED | UNVERIFIED version: Optional[int] = None @dataclass class CompactionResult: digest_assertions: list[Assertion] retained_provenance_ids: set[str] = field(default_factory=set) def reconcile_after_compaction(result: CompactionResult) -> list[Assertion]: """Demote any tool-derived assertion whose provenance handle was dropped.""" for a in result.digest_assertions: if a.source_tool_call_id is None: continue # user/model assertion; not subject to provenance loss if a.source_tool_call_id not in result.retained_provenance_ids: a.status = "UNVERIFIED" return result.digest_assertions def guard_side_effect(assertion: Assertion, action: str) -> None: """Invariant: no side-effecting action may consume an unverified or orphaned tool-derived assertion. Must re-fetch first.""" if assertion.source_tool_call_id is not None and assertion.status != "VERIFIED": raise ProvenanceSeveredError( f"Refusing side effect '{action}': assertion {assertion.text!r} " f"traces to tool_call_id={assertion.source_tool_call_id!r} which was " f"not retained across compaction (status={assertion.status}). " f"Re-read the source before proceeding." ) # --- trace of the observed failure --- compaction = CompactionResult( digest_assertions=[ Assertion(text="owner is payments-platform", source_tool_call_id="call_38_read_owner", status="VERIFIED"), ], retained_provenance_ids=set(), # summarizer dropped all handles ) reconciled = reconcile_after_compaction(compaction) # Turn 61: agent attempts to page the owner based on the compacted fact. guard_side_effect(reconciled[0], action="page_owner") # -> raises ProvenanceSeveredError, forcing a re-read of service_owner # (which would reveal the turn-55 rotation). ```