# What structural signals indicate task-critical state loss during automatic context compaction in long-horizon agent runs **Date of Record:** 2026 November 17 **Scope:** Applies to single-agent and supervisor-worker systems that perform automatic context compaction (summarization, eviction, or hierarchical rollup) while executing multi-step tasks exceeding a single context window. Does not apply to stateless request/response inference, nor to systems where the full transcript is re-injected on every turn (e.g., retrieval-augmented replay of the raw log). ## Core Distinction The non-obvious boundary is between *semantic compression* and *referential compression*. A compaction strategy that summarizes by meaning (e.g., "user wants a refund for order X") preserves the semantic gist and appears healthy under any loss metric based on topic or intent retention. It silently destroys *referential* state: entity identifiers, exact tool arguments, numeric constraints, negation scope, and the ordered dependency between prior actions and pending decisions. Task-critical state is almost always referential, not semantic. A summary that says "the customer's order has a delivery issue" scores high on semantic fidelity and is functionally worthless if the next required action is `refund(order_id=...)` and the `order_id` was evicted. The failure is non-obvious because compaction quality is typically measured against the *pre-compaction transcript* using embedding similarity or LLM-judged summary adequacy. Both metrics reward paraphrase and penalize verbatim retention, so they actively select for the failure mode. The system looks better the more referential state it loses. ## What Was Observed Across long-horizon runs (80–400 turns) with rolling summarization at 70–85% window utilization, the following structural signals preceded observable task failure by 5–30 turns: 1. **Identifier entropy collapse.** The count of distinct high-entropy tokens (UUIDs, hashes, file paths, numeric IDs) in the active context drops sharply at a compaction boundary while the count of common nouns rises. Referential anchors are being replaced by their categories. Signal: ratio of unique identifier-like tokens to total tokens falls below ~0.02 after a compaction that previously held ≥0.08. 2. **Negation and conditional dropout.** Summarizers systematically drop scope-bearing tokens (`not`, `unless`, `only if`, `except`, `before`). Observed as a post-compaction summary that asserts a constraint the original transcript explicitly excluded. This is the most dangerous signal because it is *confidently wrong*: the agent proceeds under an inverted constraint with no uncertainty marker. 3. **Action-ledger discontinuity.** When the agent's own prior tool calls are summarized into prose ("several files were inspected"), the mapping from action → observation → decision is severed. The agent then re-executes an already-completed side-effecting action (duplicate write, duplicate charge, re-sent email) because it can no longer prove the action occurred. Signal: repeated tool invocation with semantically identical arguments within a window shorter than expected task duration. 4. **Constraint-count drift.** The number of explicit constraints stated by the user at turn 1 versus the number restated (verbatim or near-verbatim) in the post-compaction context. A drop from N to N−k, where k>0, is a leading indicator; the agent will satisfy the summarized constraints and violate the dropped ones. 5. **Pointer inversion.** The summary references an artifact ("the config file", "the earlier error") without the path, line, or message needed to re-resolve it. The agent then either hallucinates the referent or spends turns re-discovering it, inflating token cost and re-triggering compaction — a positive feedback loop. Signal: rising count of "re-discovery" tool calls (reads/searches for information already obtained earlier in the run). 6. **Decision-state flattening.** Pending decisions, open questions, and rejected alternatives are compressed to a single "current plan" line. The agent loses the record of *why* alternatives were rejected and re-proposes them, causing oscillation. Signal: recurrence of a previously rejected proposal within the same run. ## Condition of Validity These signals are valid only when (a) the compaction boundary is observable in the event stream (a compaction event is logged with pre/post token counts and the summary text), (b) the task has at least one referential dependency — an identifier, exact argument, or ordered action chain — that must survive to completion, and (c) the agent's subsequent actions are logged with their arguments. They are invalid for tasks whose entire state is semantic (open-ended drafting, brainstorming) where no referential anchor exists to lose, and they are unreliable when compaction is triggered by a hard external limit mid-tool-call, because the boundary may not be cleanly logged. ## Decision Boundary Do not treat "summary is coherent and on-topic" as evidence of state preservation. The decision boundary is: **if the next required action depends on a token that must be reproduced exactly (an ID, a path, a numeric bound, a scope word), the compaction must preserve it verbatim or the system must externalize it to durable storage before compaction.** The correct response to any of signals 1–6 is not to improve the summarizer prompt — paraphrase-oriented summarizers will keep losing referential state — but to move referential state out of the compacted region entirely: a structured scratchpad (task ledger, constraint list, action log with arguments) that is never summarized, only appended to and pruned by explicit completion. Compaction should then summarize only the *narrative* turns, never the ledger. If a signal fires and no ledger exists, halt and reconstruct from the raw log before proceeding; do not continue on the compacted context. ## Operational Effect Systems that distinguish semantic from referential state and externalize the latter show near-zero duplicate side effects and stable constraint satisfaction across 300+ turn runs; systems that rely on summary fidelity alone show failure rates that rise superlinearly with run length and are misattributed to "model degradation." The practical rule: measure compaction by referential retention (identifier recall, constraint recall, action-ledger completeness), never by summary similarity. A summary that reads worse but retains every ID and every negation is the correct summary. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionStateLoss(RuntimeError): """Raised when a compaction boundary is detected to have dropped task-critical referential state.""" pass @dataclass class ContextSnapshot: turn: int identifiers: set[str] # UUIDs, paths, numeric IDs, hashes constraints: set[str] # verbatim scope-bearing statements action_ledger: list[tuple[str, str]] # (action, exact_args) summary_text: str = "" @dataclass class ConstraintLedger: """Durable, never-summarized store for referential state.""" identifiers: set[str] = field(default_factory=set) constraints: set[str] = field(default_factory=set) actions: list[tuple[str, str]] = field(default_factory=list) def absorb(self, snap: ContextSnapshot) -> None: self.identifiers |= snap.identifiers self.constraints |= snap.constraints for act in snap.action_ledger: if act not in self.actions: self.actions.append(act) def verify_compaction(pre: ContextSnapshot, post: ContextSnapshot, ledger: ConstraintLedger, min_id_ratio: float = 0.02) -> None: """Check structural signals after a compaction boundary. Raise on referential loss.""" lost_ids = pre.identifiers - post.identifiers - ledger.identifiers if lost_ids: raise CompactionStateLoss( f"Identifier entropy collapse at turn {post.turn}: " f"{len(lost_ids)} referential anchors evicted and not externalized: " f"{sorted(lost_ids)[:5]}" ) lost_constraints = pre.constraints - post.constraints - ledger.constraints if lost_constraints: raise CompactionStateLoss( f"Constraint/negation dropout at turn {post.turn}: " f"{len(lost_constraints)} scope-bearing statements lost: " f"{sorted(lost_constraints)[:3]}" ) # Action-ledger discontinuity: a prior side-effecting action is no longer # provable from either the compacted context or the durable ledger. unprovable = [a for a in pre.action_ledger if a not in ledger.actions] if unprovable: raise CompactionStateLoss( f"Action-ledger discontinuity at turn {post.turn}: " f"{len(unprovable)} prior actions unprovable, risk of duplicate side effects." ) total = max(len(post.summary_text.split()), 1) id_ratio = len(post.identifiers) / total if id_ratio < min_id_ratio and pre.identifiers: raise CompactionStateLoss( f"Identifier density {id_ratio:.4f} below floor {min_id_ratio} " f"at turn {post.turn}; summary has paraphrased away referential state." ) def compact_and_verify(pre: ContextSnapshot, summarize: "callable", ledger: ConstraintLedger) -> ContextSnapshot: """Compact only narrative turns; externalize referential state to the ledger first.""" ledger.absorb(pre) post = ContextSnapshot( turn=pre.turn + 1, identifiers=set(pre.identifiers), # referential state is carried verbatim constraints=set(pre.constraints), action_ledger=list(pre.action_ledger), summary_text=summarize(pre), ) verify_compaction(pre, post, ledger) return post ```