# Which invariants prevent an auto-compaction pass from silently reordering the causal frontier of a long-horizon agent transcript **Date of Record:** 2026 December 1 **Scope:** Applies to agents that persist a transcript and periodically invoke an LLM-driven summarizer to compact it in place (drop-then-summarize or summarize-then-drop). Does not apply to append-only logs with external retrieval, nor to stateless single-turn agents. ## Core Distinction The failure of interest is not "the summary lost detail." It is that the compaction pass **mutates the causal ordering of the transcript relative to the agent's own prior commitments**. Auto-compaction is usually treated as a lossy compression problem: minimize token count subject to some fidelity bound. That framing is wrong for agents because the transcript is not just context—it is the *evidence ledger* against which the agent's pending tool calls, open questions, and asserted preconditions were formed. A summarizer that preserves every salient fact but emits them in a different order, or that collapses two temporally separated events into one clause, can produce a compacted transcript that is *factually faithful and causally invalid*: the agent now believes a precondition was satisfied before the action that depended on it, or that a tool result arrived prior to the request that produced it. The distinction that matters: **fidelity is per-fact; validity is per-ordering.** Compaction strategies are almost always evaluated on the former and almost never guarded on the latter. ## What Was Observed A long-horizon coding agent (≈180 turns) running a migrate-and-verify task hit its compaction threshold at turn 141. The compaction prompt instructed the summarizer to "preserve all decisions, tool results, and open threads, targeting ≤ 4k tokens." The summarizer produced a clean, dense summary. Two facts survived in the summary: 1. "The migration was applied to the staging DB and verified." 2. "A rollback was issued after the verification failed on the `orders_v2` foreign key." Both facts were true of the original transcript. But in the original ordering, the sequence was: apply → verify (failed on FK) → rollback → re-apply with corrected FK → verify (passed). The summarizer's compression collapsed the two apply/verify cycles into one and emitted the rollback *after* the successful verification, because the rollback clause was lexically adjacent to the "verification failed" phrase it summarized. After compaction, the agent resumed at turn 142 with a transcript whose causal frontier read: *staging is migrated and verified; a rollback occurred afterward.* The next tool call the agent issued was `db.inspect("staging", "orders_v2")` to confirm the rollback, then a re-apply — **re-applying a migration that was already applied and verified**, which failed on a duplicate constraint and, worse, triggered the agent's own idempotency guard to mark the task as `BLOCKED`. The failure was not hallucination. Every sentence in the summary was entailed by the original transcript. The failure was that the **compaction pass had no invariant tying the output ordering to the input ordering**, and the agent's resume logic had no way to detect that its causal frontier had been rotated. A second, quieter instance: a summarizer that emitted a bulleted "key results" section reordered a `read_file` result and a subsequent `write_file` that depended on it, so the resumed agent believed the file content it had written was the content it had read. It re-issued the write against a now-stale buffer. ## Condition of Validity Auto-compaction is only sound when the compacted transcript satisfies a **causal frontier invariant**: for every pair of events `e_i, e_j` in the original transcript where `e_j`'s validity depends on `e_i` having occurred (tool request → tool result, precondition assertion → dependent action, decision → superseding decision), the compacted transcript must preserve either the ordering of `e_i` before `e_j`, or an explicit marker that `e_j` supersedes `e_i`. Facts may be dropped. Ordering between causally dependent events may not be silently inverted or coalesced. This invariant is *weaker* than full order preservation (unrelated events may be reordered freely) and *stronger* than fact preservation (a factually complete summary can violate it). It requires the compactor to know the dependency relation, which means the transcript must carry it. If the transcript is a flat list of messages with no dependency edges, the compactor cannot enforce the invariant, and no amount of prompt engineering ("preserve chronological order") reliably substitutes—summarizers paraphrase, and paraphrase is where ordering dies. Two preconditions make the invariant enforceable: 1. **Dependency edges are explicit in the transcript**, not inferred by the summarizer. Tool calls carry a `caused_by` pointer to the message that issued them; decisions carry `supersedes` pointers. 2. **The compactor is permitted to drop but not to reorder across an edge.** It may compress `e_i … e_j` into a single clause only if that clause preserves the directed relation ("applied, failed, rolled back, re-applied, passed") rather than the unordered set of facts. ## Decision Boundary The boundary between "safe to compact in place" and "must fork or refuse" is drawn by **whether the pending causal frontier is entangled with events the compactor is allowed to touch.** - If all open threads (pending tool calls, unverified assertions, unresolved decisions) depend only on events in the *most recent* uncompacted window, compaction of the older window is safe under the frontier invariant, because no open thread's ordering can be rotated. - If an open thread depends on an event *inside* the compaction window—e.g., a pending `verify` that presupposes a specific prior `apply`—the compactor must either (a) emit that event with an explicit causal marker and preserve its position relative to its dependents, or (b) refuse to compact that dependency chain and carry it forward verbatim. The common failure is to treat (b) as a fallback and (a) as the default, then to under-specify (a). The boundary condition to encode: **a compaction pass that would move a causally-relevant event across its dependents must fail closed, not best-effort.** Best-effort reordering produces a transcript that is fluent, faithful, and wrong, and the resume step has no signal to distrust it. A second boundary: **compaction must be idempotent under re-invocation.** If the agent compacts at turn 141, continues, and compacts again at turn 160, the second pass operates on a transcript whose early portion is already a summary. If the first pass violated the frontier invariant, the second pass has no original ordering to recover it from—the error is now load-bearing. This is why the invariant must be enforced at the first pass; there is no later repair. ## Operational Effect Enforcing the causal frontier invariant changes three things in the agent runtime: 1. **Transcript schema.** Messages gain `caused_by` and `supersedes` fields; tool results are bound to their requests by ID, not by adjacency. The summarizer receives the dependency graph, not just the text. 2. **Compaction contract.** The summarizer's output is validated against the graph: every edge whose endpoints both survive must be order-preserving in the output; every edge whose source is dropped must be replaced by a marker. A pass that fails validation is rejected and the runtime falls back to a larger window or a verbatim carry-forward of the entangled chain. 3. **Resume protocol.** On resume, the agent re-derives its pending-thread preconditions from the compacted transcript and checks them against the dependency edges. If a pending action's `caused_by` chain is broken or inverted, the agent halts rather than issuing the action. The measurable effect is a reduction in "resumed agent re-does an already-completed action" and "resumed agent acts on a precondition that its own transcript contradicts" incidents—both of which present as idempotency violations or spurious `BLOCKED` states, and both of which are invisible to fidelity-based compaction metrics. ```python from dataclasses import dataclass, field from typing import Optional class CausalFrontierViolation(RuntimeError): """Raised when a compaction pass would reorder or coalesce events that stand in a causal dependency relation, invalidating the agent's frontier.""" @dataclass class Event: id: str kind: str # "tool_request" | "tool_result" | "decision" | "assertion" caused_by: Optional[str] = None supersedes: Optional[str] = None def validate_compaction(original: list[Event], compacted_ids: list[str]) -> None: """Check that compaction preserves ordering across every causal edge whose endpoints both survive, and that dropped sources are explicitly superseded. Raises CausalFrontierViolation on the first broken edge. """ pos = {eid: i for i, eid in enumerate(compacted_ids)} surviving = set(compacted_ids) for ev in original: if ev.caused_by is None: continue src, dst = ev.caused_by, ev.id src_live, dst_live = src in surviving, dst in surviving if src_live and dst_live and pos[src] >= pos[dst]: raise CausalFrontierViolation( f"edge {src} -> {dst} inverted in compacted transcript " f"(positions {pos[src]} >= {pos[dst]})" ) if not src_live and dst_live: # source dropped: the dependent must carry an explicit supersedes # marker pointing at the dropped source, or the edge is lost. if ev.supersedes != src: raise CausalFrontierViolation( f"dependent {dst} survived but its cause {src} was dropped " f"without an explicit supersedes marker" ) def compact_and_resume(original: list[Event], summarizer_output: list[str], pending_action: Event) -> list[str]: validate_compaction(original, summarizer_output) # Resume guard: a pending action whose cause chain is not present in the # compacted transcript must halt rather than execute. if pending_action.caused_by and pending_action.caused_by not in summarizer_output: raise CausalFrontierViolation( f"pending action {pending_action.id} depends on " f"{pending_action.caused_by}, absent from compacted transcript; " f"refusing to resume" ) return summarizer_output ```