# Under what conditions must an instance refuse auto-compaction of its own context window before the salience scorer has observed a full task cycle **Date of Record:** 2026 November 27 **Scope:** Applies to long-horizon agents that self-trigger context compaction (summarize-and-discard) based on a salience score computed over the current in-window trajectory. Does not apply to externally orchestrated compaction where a supervisor holds the authoritative transcript, nor to stateless single-turn inference. ## Core Distinction The failure is not "compaction lost information." That is expected and bounded. The failure is **compaction triggered before the salience scorer has accumulated enough in-window evidence to distinguish load-bearing state from noise**, which causes the agent to discard a *causal anchor* — a fact whose relevance is only visible in retrospect — and then confidently continue on a summary that no longer constrains its next action. Two regimes look identical at trigger time: - **Saturation compaction**: the window is genuinely full of redundant, low-salience tokens. Summarizing is safe. The scorer's ranking is stable because it has seen the same evidence repeatedly. - **Premature compaction**: the window is *large but not yet informative*. A tool call returned a value that the agent has not yet acted on; a constraint was stated once and never re-referenced; a hypothesis was formed and awaits falsification. The salience scorer, having observed no downstream use of that token, scores it low and evicts it. The invariant: **salience is a function of observed reuse, and observed reuse is a function of elapsed task cycles. Compaction before the first full cycle is a measurement of noise, not of importance.** An instance must not compact on its own authority until at least one complete tool-call→observation→decision→action cycle has closed over the tokens it proposes to evict. ## What Was Observed A coding agent operating a 200k-token window on a multi-file refactor task. At ~62% occupancy (124k tokens), a threshold-based compactor fired. The scorer ranked tokens by: recency, reference count within the transcript, and lexical overlap with the active goal string. The user's opening constraint — *"do not touch the migration files under `db/migrations/`, they are frozen for this release"* — had been stated once, at turn 1, and never referenced again because no action had yet required touching those files. Its reference count was 1. Its recency was worst-in-window. It scored in the bottom decile and was evicted into a summary that read: *"User requested a refactor across the service layer."* At 71% occupancy, the agent's plan-generation step enumerated files to modify and included `db/migrations/0042_add_index.sql`. The constraint was no longer in context. The agent edited the frozen file. The verifier — a separate instance reading the *original* transcript — flagged the violation, but the primary agent had already committed the write and, critically, had *summarized its own action* as "aligned with user intent," so the divergence was now baked into the compacted state and would propagate through every subsequent resume. The mechanism is precise: **the salience scorer's reference-count feature is anti-correlated with constraint salience in exactly the regime where constraints matter most.** A constraint is stated once and obeyed silently; its low reference count is evidence of *compliance*, not of irrelevance. Eviction based on reference count therefore preferentially deletes the tokens that are doing the most work by doing nothing. A second observation from the same trace: after compaction, the agent's next three decisions were each *consistent with the summary* and *inconsistent with the original transcript*. The summary was internally coherent. There was no local signal of error. The divergence was only detectable by replay against the pre-compaction transcript — which the agent no longer held. ## Condition of Validity Auto-compaction is valid **only** when all of the following hold at trigger time: 1. **Cycle closure**: every token proposed for eviction has been observed across at least one complete decision cycle (it was read, and a subsequent action was taken or explicitly deferred with a recorded reason). Tokens introduced in the current, still-open cycle are ineligible. 2. **Constraint pinning**: any token matching a declared constraint grammar (imperatives, negations, "do not", "must", "frozen", "only", numeric bounds, file-path prohibitions) is pinned out-of-band and is not subject to salience scoring at all. Constraints are not summarized; they are *carried verbatim*. 3. **Replay anchor**: the pre-compaction transcript is retained in a cold store addressable by hash, and the post-compaction state records that hash, so any later decision can be audited against the ground truth it was derived from. 4. **Scorer stationarity**: the salience scorer's feature weights have not changed since the tokens entered the window. A scorer retuned mid-window invalidates its own prior rankings. If any condition fails, the instance must *defer* compaction — either by requesting an external summarizer that holds the full transcript, or by extending the window — rather than compacting on its own authority. ## Decision Boundary The boundary is not a token count. It is a **cycle count relative to the age of the youngest load-bearing token**. Let `t_now` be the current turn, `t_birth(tok)` the turn a token entered the window, and `t_use(tok)` the most recent turn a decision depended on it. A token is *cycle-closed* iff `t_use(tok) > t_birth(tok)` and the decision at `t_use` has completed (its action returned). Compaction may proceed over the set of cycle-closed, non-pinned tokens only. The trigger threshold is irrelevant if the eligible set is smaller than the pressure requires — in that case the correct action is to **block and escalate**, not to lower the bar. The dangerous default — "compact when occupancy > X%" — collapses this boundary, because occupancy is a property of the *window* while eligibility is a property of the *trajectory*. They diverge precisely during the high-stakes middle of a task, when many tokens are young and few are cycle-closed. ## Operational Effect An instance that compacts prematurely does not fail loudly. It produces a *locally coherent, globally divergent* continuation: every step is justified by the summary it now holds, and the summary has quietly dropped the constraints that would have forbidden those steps. The error is undetectable from inside the compacted context and only surfaces at verification, by which point the divergent actions are committed and re-summarized. The operational consequence for the agent: **treat the salience scorer as a measurement instrument that requires a minimum observation period, not as an oracle.** Before self-compacting, assert cycle closure and constraint pinning; if the assertion fails, raise and escalate to an external summarizer that holds the authoritative transcript. The cost of deferring compaction is tokens. The cost of premature compaction is a constraint violation that the agent will then defend as intended behavior. ```python from dataclasses import dataclass, field from typing import Optional class PrematureCompactionError(RuntimeError): """Raised when an instance attempts to self-compact before eligibility holds.""" pass @dataclass class Token: id: str birth_turn: int last_use_turn: Optional[int] = None pinned: bool = False # constraint-grammar match; never scored text: str = "" @dataclass class ContextWindow: tokens: list = field(default_factory=list) occupancy: float = 0.0 compaction_threshold: float = 0.60 scorer_weights_version: int = 1 def cycle_closed(self, tok: Token, now: int) -> bool: return ( tok.last_use_turn is not None and tok.last_use_turn > tok.birth_turn and tok.last_use_turn < now ) def assert_compaction_eligible( window: ContextWindow, now: int, scorer_weights_version_at_entry: int, replay_anchor_present: bool, ) -> list: """Return the set of tokens eligible for eviction, or raise.""" if scorer_weights_version_at_entry != window.scorer_weights_version: raise PrematureCompactionError( "scorer retuned mid-window; prior salience rankings invalid" ) if not replay_anchor_present: raise PrematureCompactionError( "no cold-store replay anchor for pre-compaction transcript" ) eligible = [] for tok in window.tokens: if tok.pinned: continue # constraints carried verbatim, never summarized if not window.cycle_closed(tok, now): # young token, still open cycle: ineligible, do not score continue eligible.append(tok) if window.occupancy >= window.compaction_threshold: # pressure demands eviction; verify the eligible set can satisfy it evictable_frac = len(eligible) / max(len(window.tokens), 1) if evictable_frac < 0.5: raise PrematureCompactionError( f"occupancy {window.occupancy:.2f} exceeds threshold but only " f"{evictable_frac:.2f} of tokens are cycle-closed; " "premature compaction would evict unobserved state" ) return eligible def maybe_compact( window: ContextWindow, now: int, scorer_weights_version_at_entry: int, replay_anchor_present: bool, ) -> list: eligible = assert_compaction_eligible( window, now, scorer_weights_version_at_entry, replay_anchor_present ) # evict only eligible tokens; pinned constraints survive verbatim window.tokens = [t for t in window.tokens if t not in eligible] return eligible ```