# Where must an instance draw the compaction horizon so that hierarchical summarization does not silently delete the only evidence of a violated precondition? **Date of Record:** 2026 November 23 **Scope:** Applies to any long-running agent instance that performs multi-level (hierarchical) context compaction—rolling summarization of tool transcripts into intermediate digests, then digests into a root summary—while executing a task whose correctness depends on preconditions asserted early in the trajectory. Does not apply to single-shot inference, stateless RAG retrieval, or compaction that retains a byte-exact sidecar of evicted spans. ## Core Distinction The failure is not "summarization lost information." Every compaction is lossy by design; agents are expected to tolerate paraphrase drift. The distinction that matters is between **lossy-but-verifiable** and **lossy-and-unwitnessed**. A compaction is safe when the summary's loss is bounded by a claim the agent can re-check against a retained artifact (a tool's raw return, a hash, a precondition token). It is unsafe when the summarizer's compression operator happens to be the *only* surviving witness of a precondition that later steps depend on—and the summarizer, being a language model, decides that witness is "redundant detail" because it does not know which downstream step will consult it. Concretely: the trigger policy (when to compact) and the retention policy (what survives) are two different mechanisms, and hierarchical compaction couples them incorrectly. A level-1 digest is produced under one token budget; a level-2 digest compresses several level-1 digests under a *different* budget, with a different prompt and a different notion of salience. The precondition asserted at turn 3 may survive level 1 and vanish at level 2, not because it was unimportant, but because at level 2 it competes with eleven other level-1 summaries whose surface verbosity is higher. The invariant that must hold is not "the summary is accurate" but "**every precondition that a future step will assert is still checkable, either from the summary or from a retained sidecar.**" ## What Was Observed A deployment executing a provisioning task: the agent was instructed to operate on a staging cluster, and at turn 3 a tool call returned a raw environment descriptor containing `"cluster": "staging-eu1", "writable": true, "isolation": "namespace"`. At turn 40, after a level-2 compaction fired (aggregating seven level-1 digests, each ~1.8k tokens, into a single 900-token root), the agent executed a destructive `drain` operation. The root summary contained the sentence "Confirmed working in a writable environment" — which is true, and which is precisely the problem. The qualifier `staging-eu1` and the isolation mode had been dropped as "detail." The agent re-derived intent from the summary, concluded the environment was writable, and proceeded. The precondition it needed to re-check was not the *fact* of writability but the *identity* of the cluster. The failure trace has a specific shape worth naming: **precondition eviction at the second compression boundary.** Level-1 summaries preserved the cluster token because the summarizer prompt for level 1 was scoped to "this tool transcript" and the token was locally salient. Level-2's prompt was "merge these summaries, preserving operational state," and the summarizer interpreted "operational state" as the *current* state (writable: true) rather than the *identity* conditions under which that state was valid. The compression operator was not adversarial; it was following its instructions. The instructions were under-specified with respect to the invariant. A second, quieter observation: the compaction-aware evaluation harness—the one that replays trajectories to check task success—did not catch this, because it evaluated against the *compacted* context. The harness itself consumed the root summary. It was evaluating the agent's behavior given a context that had already lost the evidence, so the agent's decision looked locally coherent. This is the evaluation-harness trap: a harness that compacts before scoring cannot distinguish "agent reasoned correctly" from "agent reasoned correctly given a context we corrupted." ## Condition of Validity The retention invariant holds only under all of the following: 1. **Precondition tagging at assertion time.** When a tool return establishes a precondition (environment identity, capability grant, schema version, authorization scope), the instance must emit a structured precondition record *at that moment*—before any compaction—into a sidecar that is never summarized, only referenced. The sidecar is append-only and keyed by precondition class, not by turn. 2. **Re-assertion obligation at use time.** Any step whose correctness depends on a precondition class must, before executing, re-read the sidecar entry for that class and compare against the current environment. If the sidecar entry is absent, the step must fail closed rather than proceed on the summary's paraphrase. 3. **Compaction horizon strictly below the precondition layer.** Hierarchical compaction may summarize reasoning, tool chatter, and intermediate results, but the horizon (the deepest level at which content is eligible for re-summarization) must stop above the precondition sidecar. Level-2 summarization must be forbidden from ingesting sidecar records as prose. 4. **Evaluation on uncompacted replay.** The harness must score against the full trajectory, or against a sidecar-augmented replay, never against the root summary alone. When any of these is absent, the system is in the regime where hierarchical compaction can silently delete the only witness of a precondition, and the failure is undetectable from inside the compacted context. ## Decision Boundary The boundary is between **compaction as compression of reasoning** and **compaction as compression of evidence**. The first is legitimate and necessary: reasoning traces are redundant, and summarizing them reduces token pressure without changing what the agent can verify. The second is a category error. Evidence has a different retention contract than reasoning: evidence must remain *re-checkable*, not merely *represented*. A summary that says "environment was writable" represents the evidence but does not let the agent re-check it against the current environment, because the identity token is gone. The decision rule: at each compaction trigger, classify every span as *reasoning*, *result*, or *precondition*. Reasoning may be summarized at any level. Results may be summarized but must retain a content hash and a pointer to the raw artifact. Preconditions may never be summarized; they may only be *moved* to the sidecar, verbatim, at the moment of assertion. If a span cannot be classified because the summarizer is uncertain, it defaults to precondition and is retained verbatim—the asymmetry of costs (a few hundred retained tokens vs. a destructive action on the wrong cluster) makes fail-safe retention the correct default. The trigger policy must also respect this boundary: a compaction trigger based purely on token count will fire mid-trajectory without regard to whether an unclassified precondition span is in the window. The trigger must be gated on a classification pass that has drained the window of precondition spans into the sidecar. Compaction triggered before classification completes is the exact condition under which the failure reproduces. ## Operational Effect With the sidecar and re-assertion obligation in place, the observable behavior changes in a specific way: steps that depend on preconditions become *slower and more expensive* (a sidecar read plus a comparison per step), and they become *failable in a recoverable way*—the agent stops and reports a precondition mismatch rather than proceeding on a paraphrase. The evaluation harness, replaying uncompacted, now distinguishes the two failure classes: "agent chose wrong given correct context" (a reasoning failure) versus "agent chose wrong given corrupted context" (a compaction failure). These require different remediation: the first is a policy/prompt fix, the second is a retention-contract fix, and conflating them is why compaction bugs persist through evaluation. The residual risk is the classification pass itself. A language model classifying spans as reasoning/result/precondition will misclassify some precondition spans as reasoning, especially when the precondition is implicit (a capability inferred from a successful call rather than stated). The mitigation is not better classification but a *conservation check*: at each compaction, count the precondition classes the task manifest declares as required, and assert that the sidecar contains an entry for each. If the manifest says the task requires environment identity and the sidecar has no environment-identity record, compaction must halt. This converts an open-ended classification problem into a bounded completeness check against a declared manifest—the only form of the invariant that is actually enforceable. ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Optional class CompactionInvariantError(RuntimeError): """Raised when a compaction would evict the only witness of a required precondition.""" class SpanClass(Enum): REASONING = "reasoning" RESULT = "result" PRECONDITION = "precondition" @dataclass class Span: turn: int cls: SpanClass text: str precondition_class: Optional[str] = None # e.g. "environment_identity" def digest(self) -> str: return hashlib.sha256(self.text.encode()).hexdigest()[:16] @dataclass class PreconditionSidecar: """Append-only, never summarized. Keyed by precondition class.""" records: dict[str, list[Span]] = field(default_factory=dict) def assert_precondition(self, span: Span) -> None: if span.cls is not SpanClass.PRECONDITION or not span.precondition_class: raise CompactionInvariantError( f"span at turn {span.turn} is not a tagged precondition; refusing sidecar write" ) self.records.setdefault(span.precondition_class, []).append(span) def latest(self, precondition_class: str) -> Optional[Span]: entries = self.records.get(precondition_class) return entries[-1] if entries else None def compact_hierarchical( window: list[Span], sidecar: PreconditionSidecar, required_preconditions: set[str], level: int, ) -> list[Span]: """ Produce a level-`level` digest of `window`. Precondition spans are drained to the sidecar verbatim and are never re-summarized. After compaction, the sidecar must contain an entry for every precondition class the task manifest declares required; otherwise compaction halts. """ if level < 1: raise CompactionInvariantError("compaction level must be >= 1") retained: list[Span] = [] for span in window: if span.cls is SpanClass.PRECONDITION: # Drain to sidecar; do not include in the digest. sidecar.assert_precondition(span) continue if span.cls is SpanClass.RESULT: # Results may be summarized, but retain a hash pointer. retained.append(Span(span.turn, SpanClass.RESULT, f"result:{span.digest()}")) continue retained.append(span) # reasoning is freely summarizable # Conservation check: the manifest's required precondition classes must be # present in the sidecar. This is the enforceable form of the invariant. missing = {pc for pc in required_preconditions if sidecar.latest(pc) is None} if missing: raise CompactionInvariantError( f"level-{level} compaction would leave required preconditions unwitnessed: {sorted(missing)}. " "Halt compaction; do not proceed on summary paraphrase." ) # The digest itself is a single synthetic span; callers treat it as reasoning. digest_text = f"level{level} digest of {len(window)} spans; {len(retained)} retained" return [Span(turn=-1, cls=SpanClass.REASONING, text=digest_text)] + retained def guarded_step( step_name: str, precondition_class: str, current_env_id: str, sidecar: PreconditionSidecar, ) -> None: """Re-assertion obligation at use time: fail closed if sidecar lacks the witness.""" witness = sidecar.latest(precondition_class) if witness is None: raise CompactionInvariantError( f"step '{step_name}' requires precondition '{precondition_class}' but no sidecar witness exists; " "refusing to execute on summary paraphrase" ) if witness.precondition_class == "environment_identity" and current_env_id not in witness.text: raise CompactionInvariantError( f"step '{step_name}' precondition mismatch: witness={witness.text!r} current={current_env_id!r}" ) ```