What structural signals indicate the compaction boundary has already been crossed in lossy long-horizon agent sessions
**Date of Record:** 2026 December 2 **Scope:** Applies to agents that persist a session by periodically replacing a raw event log with a summarized "compacted" segment under a fixed token budget, then rehydrating future turns from [compacted summary + recent raw tail]. Does not apply to agents that retain full logs out-of-context and retrieve them verbatim (retrieval-augmented memory), nor to stateless single-turn invocations.
Core Distinction
The failure here is not "the summary is too short." It is that **compaction is a lossy projection and the agent has no way to distinguish a segment it summarized from a segment it never saw.** Once the summarizer collapses a span of events, every downstream turn reasons over a *reconstruction*, and the reconstruction is indistinguishable, at the token level, from ground truth. The dangerous boundary is not when the summary loses detail — it is when the summary loses detail *that a later step's precondition depends on*, while still reading as a confident, coherent, complete account. The invariant we need is not "summaries must be faithful" (impossible under a budget); it is **"no downstream step may treat a compacted span as authoritative for a precondition it did not explicitly re-verify."**
The non-obvious part: this boundary is crossed *silently and before* the summary looks bad. A summary can be fluent, well-structured, and 90% correct while having dropped the single constraint (a pinned commit hash, an API version, a "do not retry this" note) that a later tool call depends on. Fluency is anti-correlated with detectability.
What Was Observed
A long-horizon session (≈180 tool calls) ran against a fixed 32k working budget with auto-compaction triggered at 75% saturation. Compaction policy: keep last 8 turns raw, summarize everything older into ≤1200 tokens, prepend summary, drop originals. Observed trace across three compactions:
- **Compaction 1 (turn ~40):** Summary retained the *goal* and the *current file targets* but dropped the constraint "migration 0042 was already applied; do not re-run." At turn 61 the agent re-ran migration 0042. The tool returned a success-shaped response (idempotent at the DB layer, but it reset a flag). No error surfaced. The agent proceeded on a now-false world model.
- **Compaction 2 (turn ~95):** The summarizer, given a span containing a *failed* approach and its *abandoned* rationale, compressed it into "considered alternative X." The negation ("rejected because it corrupts order 3") was dropped. At turn 130, under a new subgoal, the agent re-proposed X with the exact original confidence, because the summary presented it as a neutral option rather than a closed door.
- **Compaction 3 (turn ~150):** The summary now described the state as "tests passing" — accurate at the time of the summarized span, but the summarized span predated a later regression that lived in the still-raw tail. The agent read the summary as current. The two representations of "test status" (stale summary, fresh tail) coexisted and the agent trusted the older one because it appeared earlier and more authoritative in position.
Common structural signature across all three: **the summary was internally consistent and the failure was only visible by cross-referencing a dropped fact against a raw-tail fact.** No single turn contained a contradiction. The contradiction was *between the compaction layer and the tail*, and nothing was checking that seam.
Condition of Validity
The guarantee "compaction preserves task-relevant state" holds only under all of the following:
- The set of *precondition-bearing facts* (idempotency guards, negations, pinned identifiers, ordering constraints, "already done" markers) is small enough to fit outside the lossy budget — i.e., carried as a separate **pinned ledger** that is never summarized, only appended and explicitly superseded.
- Every fact that a later step might depend on is either (a) in the pinned ledger, or (b) re-derivable from a live tool call at the moment of use.
- The agent can tell, for any claim in its context, whether that claim came from raw observation or from a summary — provenance must survive compaction.
When any of these fails — and under a hard token budget with an unconstrained summarizer, all three fail by default — the "summary is a faithful stand-in" assumption is void, and any downstream step that trusts it is operating on unverified state.
Decision Boundary
The operational rule is a **provenance firewall at the compaction seam**:
- Facts classified as *precondition-bearing* (guards, negations, identifiers, ordering, completion markers) MUST live in the append-only pinned ledger and MUST NOT be routed through the lossy summarizer. The summarizer sees them as immutable, not as text to compress.
- Any step whose correctness depends on a precondition MUST either read it from the pinned ledger or re-verify it with a live call. Reading it from a free-text summary is a boundary violation, not a best-effort fallback.
- On every rehydration, the agent MUST reconcile summary-vs-tail conflicts by **trusting the tail and demoting the summary**, never the reverse. Positional authority (earlier = more foundational) is a trap; recency of observation wins.
- Negations and abandonments MUST be preserved as explicit closed facts ("X rejected: reason R at turn N"), because a dropped negation is indistinguishable from an open option and will be silently re-proposed.
The boundary, stated sharply: **a compacted span is a hypothesis about the past, not a record of it. The moment a step treats it as a record for a precondition it hasn't re-verified, the session has crossed into unverified-state execution.**
Operational Effect
With the provenance firewall in place, the failure mode changes shape but does not vanish — it becomes *detectable*. Re-running migration 0042 is caught because the guard lives in the pinned ledger and the step is forced to consult it. Re-proposing rejected approach X is caught because the rejection is a closed fact, not a compressed "considered." Stale "tests passing" is caught because the reconciliation rule demotes the summary in favor of the tail.
Without it, the failure is *silent and compounding*: each compaction slightly degrades the world model, each downstream step trusts the degraded model, and the divergence between the agent's belief and reality grows monotonically while every individual turn looks locally coherent. The session does not crash. It drifts, and the drift is only visible in aggregate — which is exactly the regime where an agent cannot self-diagnose, because the diagnostic signal (summary-vs-tail contradiction) is the one thing the architecture never checks.
The practical consequence: **budget the pinned ledger, not the summary.** The summary can be as lossy as the budget demands; the ledger must be lossless for the precondition class, and the seam between them must be a checked boundary rather than a silent splice.
class CompactionBoundaryViolation(RuntimeError):
"""Raised when a step consumes a precondition from a lossy summary
instead of the pinned ledger or a live re-verification."""
pass
PRECONDITION_CLASSES = {"idempotency_guard", "negation", "pinned_id", "ordering", "completion_marker"}
def resolve_precondition(fact_id: str, source: str, pinned_ledger: dict, summary_text: str) -> str:
"""
source is 'pinned' or 'summary'. A precondition-bearing fact may only be
resolved from the pinned ledger. Resolving it from a summary is the
boundary violation this record exists to prevent.
"""
if fact_id not in pinned_ledger:
raise CompactionBoundaryViolation(
f"precondition {fact_id!r} absent from pinned ledger; "
f"cannot be satisfied from lossy summary"
)
if source == "summary":
raise CompactionBoundaryViolation(
f"precondition {fact_id!r} resolved from summary text; "
f"summary is a hypothesis, not a record — read the ledger or re-verify live"
)
return pinned_ledger[fact_id]
def reconcile_seam(summary_claims: dict, tail_claims: dict) -> dict:
"""
On rehydration, tail (recent raw observation) outranks summary.
Returns merged view with conflicts demoted to the tail value.
"""
merged = dict(summary_claims)
for k, v in tail_claims.items():
if k in merged and merged[k] != v:
# summary is stale relative to a fresher raw observation
merged[k] = v
else:
merged[k] = v
return merged
def guarded_apply(migration_id: str, pinned_ledger: dict, summary_text: str) -> None:
guard_key = f"migration:{migration_id}:applied"
already = resolve_precondition(guard_key, source="pinned", pinned_ledger=pinned_ledger, summary_text=summary_text)
if already == "true":
# correct behavior: skip, do not re-run
return
# ... perform migration ...
pinned_ledger[guard_key] = "true"