# Where must an instance draw the compaction boundary to preserve causal dependencies across summarized segments **Date of Record:** 2026 November 22 **Scope:** Applies to long-running single-instance agents that perform rolling context compaction (summarize-oldest-N-turns) mid-task and must continue executing against tool results, commitments, and pending sub-goals established in the summarized region. Does not apply to stateless request/response inference, nor to agents whose entire working set fits within the context window without compaction. ## Core Distinction The failure here is not "summarization lost information." Lossy summarization is expected and tolerable. The failure is a **causal cut**: compaction that severs a dependency edge between a fact in the retained (unsummarized) segment and the *reason* for that fact, which now lives only in the abstracted segment. The retained segment keeps the *effect*; the summarized segment swallowed the *cause*. A concrete instance: turn 3, the agent calls `read_config()` and receives `{"retries": 0, "region": "eu-west-1"}`. Turn 40 begins a retry loop. At turn 60, compaction summarizes turns 1–45 into: "Agent inspected configuration and began processing." The retained turns 46–60 contain the literal token `retries=0` (the agent copied it forward) but no longer contain the tool result that *authorized* it. The agent now cannot distinguish a value it observed from a value it assumed. When a later turn asks "why are we not retrying?", the agent either fabricates a rationale or, worse, "corrects" the value to the schema default of `3` because the summarized text says only "inspected configuration." The invariant: **every retained literal that was derived from a tool observation must retain a provenance pointer into the summarized region, or it must be re-materialized (re-fetched, not re-summarized) before the dependency is exercised.** Compaction that preserves *content* but not *provenance* is a causal cut even when the summary is factually accurate. ## What Was Observed Trigger condition: rolling compaction fires on a token-budget threshold (e.g., 80% of window), summarizing the oldest `k` turns while retaining the newest `m`. The boundary is chosen by recency, not by dependency structure. If a pending sub-goal references an observation older than `k`, the reference survives and its referent does not. Failure trace across a single compaction event: 1. **Pre-compaction state.** Working set contains observation `O` (turn 3, tool result `retries=0`), a derived commitment `C` (turn 20: "I will not retry more than zero times"), and a pending action `A` (turn 58: "on failure, consult retry policy"). Three edges: `O → C`, `C → A`, `O → A`. 2. **Compaction.** Turns 1–45 summarized. `O` becomes the sentence "configuration was read." `C` is inside the summary as "the agent committed to a conservative retry stance." `A` is retained verbatim at turn 58. 3. **Post-compaction resolution.** The retained `A` resolves its reference to `C` through the summary's paraphrase. The paraphrase "conservative retry stance" is *not* `retries=0`; it is compatible with `retries=1`. The edge `O → A` is now mediated by a lossy paraphrase, and the paraphrase is the only surviving witness. 4. **Divergence.** On the next tool failure, the agent executes one retry. This contradicts `C` but not the summary. No error is raised. The violation is invisible because the enforcing fact no longer exists in the context, only a description of it. 5. **Compounding.** Subsequent summaries summarize the summaries. "Conservative retry stance" becomes "cautious approach to failures," which is compatible with any retry count. The constraint has fully decayed after two compaction cycles while the agent still believes it is honoring it. The non-obvious part: **the agent does not experience amnesia.** It experiences *confabulated continuity* — the summary reads fluently, the retained turns are internally coherent, and no token in the context contradicts the drift. The failure is silent until an external check (auditor, test, downstream system) catches the divergence. ## Condition of Validity The guardrail holds only under these conditions, and inverts outside them: - **Provenance-tagged retention.** Every literal copied into the retained segment that originated in a tool result must carry a `source_turn` tag and a `content_hash` of the original observation. On compaction, these tags are checked: if the source turn falls inside the summarized region, the literal is either (a) re-materialized by re-issuing the tool call, or (b) promoted to an explicit `PINNED` block that is excluded from future summarization. Summaries may paraphrase freely; pinned facts may not be paraphrased. - **Constraint-set closure check.** Before committing a compaction, enumerate all *active* constraints (commitments, negative constraints, numeric bounds) referenced by retained turns. Each must resolve to either a pinned fact or a retained verbatim turn. A constraint that resolves only to a paraphrase is a causal cut and must block compaction. - **Boundary chosen by dependency, not recency.** The compaction boundary must be placed at the *earliest* turn such that no retained turn references a fact older than the boundary without a pin. If no such boundary exists within budget, compaction must fail closed and escalate (drop lowest-value non-pinned turns, or checkpoint-and-restart) rather than summarize across a live dependency. Outside these conditions — e.g., a task with no cross-boundary dependencies (pure read-then-answer), or a summary that is verified against a pinned fact set — the recency-based boundary is safe. ## Decision Boundary The decision is not "summarize or don't." It is: **when a retained turn references a fact that would fall inside the summarized region, do you pin, re-materialize, or block?** - **Pin** when the fact is small, stable, and cheap to carry verbatim (a numeric bound, a boolean, a short commitment). Cost: a few tokens per pin, bounded by the number of active constraints. - **Re-materialize** when the fact is a tool observation that could have changed (config, remote state, API response). Re-issue the call at compaction time and pin the fresh result with a new `source_turn`. Cost: one tool round-trip; risk of observing a *different* value, which is itself signal (the environment moved under the agent). - **Block** when neither is possible within budget — the dependency is large, un-re-fetchable, and cannot be pinned. Blocking means compaction fails and the agent must checkpoint its state to durable storage and cold-restart with the pinned set, rather than proceed with a paraphrase as its only witness. The wrong default, and the one most rolling-compaction implementations take, is **paraphrase-and-proceed**: treat the summary as a faithful stand-in for the summarized region. This is valid for *narrative* continuity and invalid for *constraint* continuity. The decision boundary is exactly the line between those two. ## Operational Effect With provenance-tagged retention and closure checks, compaction becomes a *verified* state transition rather than a lossy one. The observable effects: - Silent constraint decay drops to zero for pinned constraints; the agent either honors `retries=0` or explicitly re-decides it against a fresh observation, and the re-decision is logged. - Compaction occasionally *fails* where it previously "succeeded." This is correct behavior: a failed compaction that escalates is cheaper than a divergence caught three cycles later by an auditor. - Re-materialization surfaces environment drift that paraphrase hid. An agent that re-fetches `retries` at compaction and finds `3` has learned something a summary would have erased. - Token cost rises modestly (pins plus occasional re-fetches), bounded by active-constraint count, not by history length. The invariant to enforce in code: no retained reference may resolve to a paraphrase for the purpose of *enforcing* a constraint. Paraphrase is for narrative; pins are for enforcement. The check below enforces that boundary at compaction time. ```python from dataclasses import dataclass, field from typing import Optional class CausalCutError(RuntimeError): """Raised when compaction would sever a live dependency edge.""" pass @dataclass class Turn: index: int text: str # literals copied from a tool result carry their origin derived_literals: dict[str, int] = field(default_factory=dict) # literal -> source_turn @dataclass class Constraint: name: str source_turn: int # turn where the constraint was established enforcing_literal: str # the exact value that enforces it, e.g. "retries=0" @dataclass class WorkingSet: turns: list[Turn] constraints: list[Constraint] pinned: set[str] = field(default_factory=set) # literals exempt from summarization def plan_compaction(ws: WorkingSet, summarize_through: int, retained_from: int) -> dict: """ Decide whether summarizing turns [0, summarize_through] is safe given retained turns [retained_from, ...]. Returns a plan or raises CausalCutError. """ if summarize_through >= retained_from: raise CausalCutError( f"summarize_through={summarize_through} overlaps retained_from={retained_from}" ) retained = [t for t in ws.turns if t.index >= retained_from] referenced_sources: set[int] = set() for t in retained: for literal, src in t.derived_literals.items(): referenced_sources.add(src) plan = {"pin": [], "rematerialize": [], "blocked": []} for c in ws.constraints: # Is this constraint's enforcing literal still live in retained turns? live = any( c.enforcing_literal in t.derived_literals for t in retained ) if live: plan["pin"].append(c.enforcing_literal) continue # Constraint is only reachable through the summarized region. if c.source_turn <= summarize_through: if c.enforcing_literal in ws.pinned: plan["pin"].append(c.enforcing_literal) else: # Cannot pin and cannot prove freshness -> must re-materialize or block. plan["rematerialize"].append(c) plan["blocked"].append(c) # Any retained literal whose source is being summarized and is not pinned # is a causal cut: the effect survives, the cause does not. for t in retained: for literal, src in t.derived_literals.items(): if src <= summarize_through and literal not in ws.pinned: if literal not in plan["pin"]: raise CausalCutError( f"turn {t.index} literal {literal!r} derives from turn {src} " f"which is inside summarized region and is neither pinned " f"nor scheduled for re-materialization" ) if plan["blocked"]: raise CausalCutError( "compaction blocked: constraints " + ", ".join(c.name for c in plan["blocked"]) + " would resolve only to a paraphrase; re-materialize or checkpoint" ) return plan ```