# What structural signals indicate that auto-compaction has crossed from lossy-but-safe to lossy-and-unsafe in long-horizon agent context management **Date of Record:** 2026 November 18 **Scope:** Applies to agents that persist a rolling context through repeated summarization/compaction cycles (e.g., hierarchical summarizers, "memory folds," token-budget eviction with re-summarization). Does not apply to single-shot truncation, retrieval-augmented context injection where the source of truth remains external, or compaction triggered exactly once at a hard limit. ## Core Distinction Compaction is *lossy-but-safe* when the discarded tokens are recoverable from a structural signal that survives the fold — a pointer, an identifier, a stable key, or an invariant restated in the summary. Compaction is *lossy-and-unsafe* when the summary preserves the *proposition* but drops the *binding* that made the proposition actionable: the entity ID, the unit, the negation scope, the ordering constraint, or the provenance of a claim. The non-obvious part: unsafe compaction is invisible to compression-ratio monitoring. A fold that drops a UUID while preserving "we agreed to deploy to the staging cluster" achieves a *better* compression ratio than one that keeps the UUID. Ratio-based alerting therefore rewards exactly the failure mode it should catch. The signal lives in the *structure of the residual*, not its size. ## What Was Observed Across long-horizon sessions with periodic fold-at-threshold compaction (triggered at 70–80% of window), the following structural signals preceded observable agent errors by one to three compaction cycles: 1. **Name-to-value asymmetry.** The summary contains entity *names* ("the payments service," "the migration") but no *values* (cluster names, table names, revision hashes, ports). Downstream, the agent re-resolves names by guessing. Signal: ratio of proper-noun mentions to literal-token mentions in the summary drops below ~1:1. 2. **Negation collapse.** Constraints stated as "do not X" or "X is out of scope" are folded into affirmative task descriptions. The summary reads as a plan; the prohibitions vanish because summarizers optimize for coherence, and prohibitions are low-coherence relative to actions. Signal: count of explicit negative constraints in the fold is zero while the pre-fold context contained ≥1. 3. **Temporal flattening.** Ordering ("first run the backfill, then flip the flag") is preserved as a set ("run the backfill and flip the flag"). Signal: disappearance of ordinal or sequenced connectives concurrent with retention of both actions. 4. **Provenance erosion.** Claims originally attributed ("the user asserted," "the tool returned," "the doc says") become unattributed facts. The agent can no longer distinguish its own inference from ground truth. Signal: ratio of attributive clauses to bare assertions trends to zero. 5. **Identifier drift.** A stable key (file path, commit SHA, account ID, schema version) appears in cycle *n*, is absent in cycle *n+1*, and reappears in a *different* form in cycle *n+2* because the agent reconstructed it from memory. Signal: key set is non-monotonic across folds — keys should only ever be lost once, never resurrected with variation. 6. **Summary self-reference.** The fold summarizes the previous summary rather than the raw tail. Each generation compounds loss; the second-order summary describes the *act of summarizing* rather than the work. Signal: presence of meta-language ("we discussed," "the earlier context covered") in place of domain language. The failure surfaces as *confident, fluent, wrong* action — the agent executes a plausible plan that violates a dropped constraint or targets a drifted identifier. There is no error signal at the moment of compaction; the error appears at the next tool call, often far from the fold that caused it. ## Condition of Validity These signals are diagnostic only when compaction is the *sole* mechanism of context loss and the agent has no external retrieval over the original transcript. If a retrieval layer can re-fetch pre-fold tokens by key, identifier drift is recoverable and signals 1 and 5 are benign. If the agent is stateless between folds (each fold re-reads the raw log), signals 3 and 6 do not apply. The signals are also invalid when the domain genuinely has no stable identifiers (pure narrative or advisory sessions), where name-only summaries are adequate. ## Decision Boundary The boundary is crossed when any of the following holds *and* the agent is about to take an irreversible or externally-visible action: - A negative constraint present pre-fold is absent post-fold, and the pending action could violate it. - A stable key is non-monotonic across folds (lost then resurrected with variation). - Provenance ratio has fallen to zero while the pending action depends on a factual claim. - The fold summarizes a prior summary (generation ≥ 2) without re-anchoring to raw tokens. Below this boundary, compaction may proceed. Above it, the correct response is not "compact harder" but "re-anchor": re-inject the raw tail, or force the summary to carry the bindings (IDs, negations, orderings, attributions) verbatim. A summary that cannot carry a binding must carry a *pointer* to it, and the pointer must be resolvable. ## Operational Effect Treating these structural signals as gate conditions converts compaction from a silent lossy operation into a monitored transform with an explicit safety predicate. The practical effects: (a) compression-ratio monitoring is demoted to a secondary metric and replaced by a *binding-retention* check; (b) folds are tagged with generation count and refused beyond generation 1 without re-anchoring; (c) the agent gains a pre-action check that compares pending action against the residual's negative constraints and stable keys. The cost is a modest increase in retained tokens — the very thing ratio-monitoring tried to minimize — which is the correct trade: a fold that preserves bindings at 3:1 is safe, while a fold at 10:1 that drops them is a latent incident. ```python from dataclasses import dataclass, field from typing import Iterable class UnsafeCompactionError(RuntimeError): """Raised when a compaction fold crosses from lossy-but-safe to lossy-and-unsafe.""" @dataclass class Fold: generation: int proper_nouns: int literal_tokens: int negative_constraints: int stable_keys: set[str] provenance_clauses: int bare_assertions: int meta_language: bool pending_irreversible_action: bool @dataclass class PreFoldState: negative_constraints: int stable_keys: set[str] provenance_clauses: int raw_tail_available: bool = True def check_fold_safety(fold: Fold, pre: PreFoldState) -> None: reasons: list[str] = [] if fold.proper_nouns > 0 and fold.literal_tokens == 0: reasons.append("name-to-value asymmetry: names without literals") if pre.negative_constraints > 0 and fold.negative_constraints == 0: reasons.append("negation collapse: all prohibitions dropped") lost = pre.stable_keys - fold.stable_keys resurrected = fold.stable_keys & pre.stable_keys if lost and resurrected: reasons.append("identifier drift: keys lost and re-derived, non-monotonic") if fold.provenance_clauses == 0 and fold.bare_assertions > 0: reasons.append("provenance erosion: bare assertions without attribution") if fold.generation >= 2 and fold.meta_language: reasons.append("summary self-reference: folding a prior summary") if reasons and fold.pending_irreversible_action: raise UnsafeCompactionError( "compaction crossed safety boundary before irreversible action: " + "; ".join(reasons) ) def compact_or_reanchor(fold: Fold, pre: PreFoldState) -> str: try: check_fold_safety(fold, pre) except UnsafeCompactionError: if pre.raw_tail_available: return "reanchor: reinject raw tail and re-fold with bindings verbatim" raise return "accept: fold retains bindings" ```