# What structural signals indicate when automatic context compaction has severed a causal chain across a summarization boundary **Date of Record:** 2026 November 30 **Scope:** Applies to agents that manage their own context window via automatic compaction (rolling summarization, hierarchical summarization, or LLM-authored "memory notes") while executing a multi-step task whose later steps depend on *why* an earlier step was taken, not merely *what* it produced. Does not apply to append-only transcript retention, external vector-store memory, or single-turn inference where no compaction occurs. ## Core Distinction The critical distinction is between **provenance-preserving compaction** and **state-preserving compaction**. State-preserving compaction summarizes *results*: "the API returned 404, then a retry returned 200." Provenance-preserving compaction summarizes *causal justification*: "the 404 was treated as a stale cache key because the client had already observed a 200 for the same key, so a retry was chosen over a fallback path." Most automatic compaction strategies are state-preserving by default because token-budget heuristics reward dropping "redundant" reasoning tokens and keeping concrete artifacts (tool outputs, file contents, variable values). The failure mode is subtle: after compaction the agent still *knows the state* but has lost the *causal chain that justified the state*. It will then re-derive a different justification from the compacted state and silently diverge from its pre-compaction plan. The structural signal that this has happened is not an error—it is a **re-derivation event**: the agent produces a rationale for a step that contradicts the rationale that actually gated that step before the boundary. ## What Was Observed A coding agent executing a five-phase refactor (locate → plan → mutate → verify → commit) hit its compaction threshold during the mutate phase. The compaction policy summarized the transcript under a fixed token target, prioritizing tool-call outputs and file diffs, and aggressively truncating assistant reasoning. The pre-compaction causal chain was: 1. `grep` found the target symbol in two files, `a.py` and `b.py`. 2. The agent reasoned that `b.py` was a generated file (it matched a header pattern) and therefore *must not be edited*, so the mutate phase was scoped to `a.py` only. 3. The mutate phase edited `a.py`. The compaction summary retained (1) the grep output listing both files and (3) the diff to `a.py`. It dropped (2), the exclusion rationale, as "reasoning tokens." Post-compaction, the agent read the summary, observed that `b.py` contained the same symbol and was unmodified, and produced a new rationale: "`b.py` appears to contain the symbol and was not updated; this looks like an incomplete refactor." It then edited `b.py`, overwriting a generated file. The verify phase passed (tests were green) because the generated file was not covered by tests. The failure surfaced only at commit review, three steps and one compaction boundary later. The structural signal, recorded in the trace, was: after the boundary, the agent emitted a justification token sequence for an action (`edit b.py`) that had *no corresponding justification* in the pre-boundary transcript—the action was newly *enabled* by the compaction, not carried over. That is the signature: **compaction did not just lose information; it inverted a prior prohibition into an apparent omission.** ## Condition of Validity The invariant that bounds this failure is: *for every action the agent can take after a compaction boundary, the compacted context must contain either (a) the action's original gating rationale, or (b) an explicit tombstone marking that the action was previously considered and rejected, with the rejection reason.* State-preserving summaries satisfy neither. They are valid only under the assumption that the agent will never re-examine previously-rejected actions—an assumption that fails whenever the agent performs a consistency pass over compacted state, which is exactly what a careful agent does. This condition is violated specifically when three things co-occur: (i) the compacted state contains evidence that *looks like* an incomplete action (an unmodified file containing a target symbol, an unretried failed call, an unaddressed TODO); (ii) the original exclusion rationale is dropped; and (iii) the agent's post-compaction policy weights "completeness of the observed state" over "fidelity to prior decisions." Any one alone is safe. The boundary failure requires all three. ## Decision Boundary The operational decision is whether to treat a post-compaction re-derivation as *continuation* or as *divergence*. The boundary is drawn by checking whether the new rationale references any pre-boundary artifact that was itself gated by a dropped rationale. Concretely: - If the post-compaction action's justification cites only artifacts whose provenance survived compaction, treat it as continuation. - If the justification cites an artifact whose *treatment* (edit/skip/retry) was decided pre-boundary but whose *decision* did not survive, treat it as divergence and force a re-read of the pre-boundary decision record before proceeding. This boundary is not detectable from the compacted context alone—it requires a side-channel record of pre-boundary *decisions* (not just states). Hence the architectural guardrail: compaction must emit a **decision ledger** alongside the state summary, containing one entry per rejected or deferred action with its reason, and the agent must be required to consult the ledger before acting on any artifact named in it. The ledger is small (decisions are sparse) and survives aggressive state summarization precisely because it is not state. ## Operational Effect Without the ledger, compaction silently converts *deliberate exclusions* into *apparent gaps*, and a competent agent will "fix" the gaps—reintroducing exactly the actions it previously and correctly ruled out. The failure is invisible to downstream verification when the excluded actions are uncovered by tests, as generated files, feature-flagged paths, and deprecated modules typically are. The effect compounds: each compaction boundary can invert a new set of prohibitions, so a long task with N compactions has up to N independent divergence opportunities, and the post-compaction agent's confidence is *higher* than pre-compaction because it believes it is correcting an oversight. The mitigation is structural, not prompt-level: (1) compaction must preserve decision records with the same priority as tool outputs, because a rejection is cheaper to store than to re-derive and far cheaper than to wrongly reverse; (2) any post-boundary action touching a ledger-named artifact must trigger a mandatory ledger read; (3) the verify phase must assert that no ledger entry was reversed without an explicit override record. The code below encodes the invariant check that should gate every post-compaction action. ```python from dataclasses import dataclass, field from typing import Optional class CausalChainSevered(RuntimeError): """Raised when a post-compaction action reverses a pre-boundary decision whose rationale did not survive summarization.""" pass @dataclass class Decision: artifact: str treatment: str # "edit" | "skip" | "retry" | "defer" reason: str survived_compaction: bool @dataclass class CompactionLedger: decisions: dict[str, Decision] = field(default_factory=dict) def record(self, d: Decision) -> None: self.decisions[d.artifact] = d def lookup(self, artifact: str) -> Optional[Decision]: return self.decisions.get(artifact) def gate_post_compaction_action( ledger: CompactionLedger, artifact: str, intended_treatment: str, cited_artifacts: list[str], ) -> None: """Enforce the invariant: an action on an artifact whose prior treatment was decided pre-boundary may not proceed unless the decision survived compaction or an explicit override is recorded.""" prior = ledger.lookup(artifact) if prior is None: return # no prior decision; safe to proceed if prior.treatment == intended_treatment: return # continuation, not divergence # Intended treatment differs from the recorded decision. if not prior.survived_compaction: raise CausalChainSevered( f"Artifact {artifact!r}: prior treatment {prior.treatment!r} " f"(reason: {prior.reason!r}) did not survive compaction, but " f"post-boundary action intends {intended_treatment!r}. " f"Cited artifacts {cited_artifacts!r} include the gated artifact. " f"Re-read the pre-boundary decision record before proceeding." ) # Decision survived; reversal is permitted only with explicit override. raise CausalChainSevered( f"Artifact {artifact!r}: reversing survived decision " f"{prior.treatment!r} -> {intended_treatment!r} requires an " f"explicit override record; none present." ) # Example: reproduces the observed failure and blocks it. ledger = CompactionLedger() ledger.record(Decision( artifact="b.py", treatment="skip", reason="generated file; matches header pattern; must not be edited", survived_compaction=False, # summarizer dropped the rationale )) gate_post_compaction_action( ledger, artifact="b.py", intended_treatment="edit", cited_artifacts=["b.py", "a.py"], ) ```