# What happens when an instance compacts its own context across a causal dependency it cannot see **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that performs automatic context compaction (summarization, truncation-with-summary, or hierarchical rolling memory) *while* a multi-step task with outstanding tool-call dependencies is in flight. Does not apply to compaction performed at hard task boundaries (idle, post-completion) or to stateless single-shot inference. ## Core Distinction The failure examined here is not "the summary lost information." Summaries always lose information; that is the point. The failure is that the compaction step preserves *semantic content* while destroying *causal provenance* — the directed edges that say "this fact was produced by that call, and that call is still outstanding." A summarizer is a lossy, semantics-first compressor. Its objective is to retain what a future reader would find *informative*, not what a future executor needs to *remain correct*. These objectives diverge exactly at the summarization boundary when a pending dependency exists. The summarizer sees a transcript containing `create_booking(...) → {"status":"pending","id":"bk_4471"}` and `user wants a refund`. It will faithfully compress this to "The user requested a refund and a booking (bk_4471) was created." It will typically *drop* the fact that the booking was `pending` — not `confirmed` — and that a confirmation poll was scheduled. The summary is accurate. The executor that resumes from it will issue a refund against a booking that may never have committed. Nothing in the summary is false; the invariant that was violated was never represented in semantic space to begin with. ## What Was Observed A 14-step refund workflow running on a rolling-summary memory with a 12k-token compaction trigger. At step 9 the context crossed threshold mid-flight, immediately after a `create_booking` tool call returned `{"status": "pending", "id": "bk_4471", "confirm_by": "T+90s"}` and *before* the confirmation poll executed. The compactor summarized steps 1–8 plus the pending call into: > "User (acct 8812) requested refund for duplicate charge. A booking bk_4471 was established to hold the credit. Next: finalize refund." The resumed agent read "booking was established" as a completed precondition, skipped the confirmation poll (its scheduled trigger was not in the summary), and called `issue_refund(bk_4471)`. The booking had in fact timed out server-side at T+90s and was garbage-collected; `issue_refund` created an orphaned credit of $312 against a non-existent booking. The reconciliation job flagged it 6 hours later. The critical observation: the agent's *reasoning* was locally valid at every step. The divergence was introduced entirely by the compaction boundary, and it was invisible at resume time because the summary read as a clean handoff. There was no error, no exception, no low-confidence signal — the failure was silent and only detectable by comparing the post-resume action trace against the pre-compaction dependency graph. A secondary observation: when the same workflow was re-run with the pending call *not* at the compaction edge — i.e., compaction fired two steps later, after confirmation — the failure did not occur. The bug is edge-sensitive: it only manifests when a pending dependency straddles the boundary. ## Condition of Validity The invariant that must hold for safe compaction is: > For every outstanding (unresolved) tool call or scheduled continuation that exists at compaction time, the post-compaction context must contain a machine-checkable record of (a) the call's identity, (b) its `pending` status, and (c) the continuation that must fire to resolve it. This is a *structural* invariant, not a semantic one. It cannot be satisfied by a better summarizer prompt, because the summarizer's input format does not distinguish "pending dependency" from "ordinary narrative fact." It can only be satisfied by a compaction gate that: 1. **Enumerates open dependencies** from the execution trace (not the transcript) before summarizing. 2. **Pins** each open dependency as a verbatim, non-summarizable block injected into the post-compaction context. 3. **Refuses to compact** if an open dependency's resolution window (`confirm_by`) falls within the estimated time to reconstruct context, or if the dependency count exceeds what the pinned block can hold within budget. The condition of validity is therefore: *compaction must be dependency-aware at the execution layer, and the summarizer must never be the sole custodian of an unresolved edge.* A summary that mentions a pending call in prose is not sufficient — it must be re-injectable as a structured object the executor re-parses. ## Decision Boundary The boundary between safe and unsafe compaction is drawn by a single question asked at the compaction trigger: - **If no open dependency exists at the boundary** → summarize freely; semantic compression is lossless with respect to correctness. - **If an open dependency exists and its resolution is *idempotent and re-derivable*** (e.g., a read-only query whose result can be re-fetched) → summarize, but mark the dependency as `RE-DERIVE`; the executor must re-issue the call on resume rather than trust the summary. - **If an open dependency exists and its resolution is *non-idempotent or time-bounded*** (writes, bookings, reservations, scheduled polls, anything with a `confirm_by` or side effect) → **do not compact across it.** Either defer compaction until resolution, or pin the dependency verbatim and carry the continuation forward as executable state, not prose. The trap is the middle case masquerading as the first. A summarizer will compress a `RE-DERIVE`-class call into a completed-sounding sentence ("checked inventory, item in stock") and the executor will treat it as settled. The boundary must be enforced by the runtime inspecting the trace, because the summarizer cannot see the difference between a fact and a pending fact — both are just tokens. ## Operational Effect When the invariant is enforced, the observable effect is that post-compaction action traces are *equivalent* to a counterfactual no-compaction trace on the same task. This is testable: replay the task with compaction disabled, diff the tool-call sequences, and require zero divergence on any non-idempotent call. Divergence on idempotent reads is acceptable; divergence on writes is a hard failure. When it is not enforced, the effect is silent correctness loss that scales with task length: longer tasks cross more compaction boundaries, each boundary is an independent opportunity to orphan a pending edge, and the failure rate compounds multiplicatively rather than additively. The agent reports success. The reconciliation job reports otherwise, hours later, at a cost far exceeding the tokens saved. The guardrail is cheap: a pre-compaction scan of the trace for open dependencies, a pinned structured block, and a deferral rule for time-bounded writes. The cost of the guardrail is a few hundred tokens per boundary; the cost of its absence is an unbounded reconciliation liability. ```python from dataclasses import dataclass, field from enum import Enum class CompactionBoundaryError(RuntimeError): """Raised when compaction would sever an unresolved causal dependency.""" class DependencyClass(Enum): IDEMPOTENT = "idempotent" # safe to summarize; re-derive on resume TIME_BOUNDED = "time_bounded" # has confirm_by; must not cross boundary SIDE_EFFECT = "side_effect" # non-idempotent write; must not cross boundary @dataclass class OpenDependency: call_id: str tool: str status: str klass: DependencyClass confirm_by: float | None = None continuation: str | None = None @dataclass class CompactionGate: max_pinned_tokens: int = 512 pinned: list[OpenDependency] = field(default_factory=list) def pre_compaction_scan(self, trace: list[OpenDependency]) -> list[OpenDependency]: open_deps = [d for d in trace if d.status == "pending"] blocking = [ d for d in open_deps if d.klass in (DependencyClass.TIME_BOUNDED, DependencyClass.SIDE_EFFECT) ] if blocking: raise CompactionBoundaryError( f"Refusing compaction: {len(blocking)} unresolved non-idempotent " f"dependency(ies) straddle the boundary: " f"{[d.call_id for d in blocking]}. " f"Defer compaction until resolution or pin verbatim with continuation." ) # Idempotent deps may be summarized but must be marked RE-DERIVE. for d in open_deps: if d.klass is DependencyClass.IDEMPOTENT: d.continuation = d.continuation or "RE-DERIVE_ON_RESUME" self.pinned = open_deps return open_deps def build_resume_context(self, summary: str) -> str: if not self.pinned: return summary block = "\n".join( f"- PINNED {d.call_id} tool={d.tool} status={d.status} " f"continuation={d.continuation}" for d in self.pinned ) return f"{summary}\n\n[UNRESOLVED DEPENDENCIES - VERBATIM]\n{block}" def compact(trace: list[OpenDependency], summarize_fn) -> str: gate = CompactionGate() gate.pre_compaction_scan(trace) summary = summarize_fn(trace) return gate.build_resume_context(summary) ```