# Why does an instance lose task-critical state when automatic context compaction drops "resolved" sub-goals from the working set **Date of Record:** 2026 November 19 **Scope:** Applies to any agent loop that performs automatic context compaction (summarization, eviction, or token-budget truncation) mid-task while preserving a "task state" summary. Does not apply to stateless single-shot inference or to compaction performed only at hard task boundaries where no in-flight tool calls or pending obligations exist. ## Core Distinction The failure is not "the summarizer lost information." Summarizers always lose information; that is their job. The failure is a category error in what compaction treats as *safe to drop*. Most compaction policies rank content by **recency** and **apparent resolution** — text that reads like a completed action ("migrated the schema," "confirmed the endpoint returns 200") is scored as low-value and evicted, while open questions and recent chatter are retained. But an agent's correctness depends not on *what has been resolved* but on *what remains load-bearing*. A resolved sub-goal frequently carries an implicit **precondition** or **side effect** that later steps depend on: the migration was applied to staging, the endpoint was confirmed against a specific auth token, the file was written to a path. When the sentence recording the resolution is evicted, the *fact* survives in compressed form ("schema is migrated") but the *qualifier* — which environment, which credential, which path — does not. Downstream reasoning then treats a scoped fact as an unscoped one. This is a silent scope-widening failure, not a forgetting failure, and it is the dominant mechanism by which compacted agents re-execute work, target the wrong environment, or assert invariants that were only ever conditionally true. ## What Was Observed A long-horizon deployment agent (target: provision a service across staging and prod, ~140 tool calls, three compaction events) was instrumented to log the post-compaction working set against a ground-truth task DAG. At compaction event #2, the working set held 41 messages. The eviction policy scored each message on `recency × inverse_resolution_confidence`. The message: > "Applied migration 0042 to staging DB (host=stg-pg-01); prod not touched. Verified staging returns new column." scored 0.08 (high resolution confidence, low recency) and was evicted. Its compressed residual in the rolling summary was: > "Schema migration complete." The compressed residual dropped three load-bearing qualifiers: the **environment scope** (staging only), the **host identity**, and the **negative assertion** (prod not touched). The rolling summary's "complete" is a *scope-free* predicate. Twelve calls later the agent, reasoning over the summary, issued `run_migration --target prod --id 0043` on the assumption that 0042 was already global, and separately re-ran a verification against `stg-pg-01` believing it unverified. Neither action was recoverable from the summary; both required the evicted message. The trace shows the agent did not "forget" — it *confidently mis-scoped* a retained fact. Two secondary observations: 1. **Negative assertions evaporate first.** "Prod not touched," "did not rotate the key," "left the lock held" are the highest-resolution, lowest-recency statements in any trace, and they are the ones whose loss causes the most damage, because absence of a negative assertion is indistinguishable from a positive state. 2. **Compaction is not idempotent under re-entry.** After a checkpoint/resume, the resumed instance re-summarized the already-summarized residual, and "Schema migration complete" further compressed to "DB ready" — a third-order scope widening in one hop. ## Condition of Validity The guardrail below is valid only under these conditions, and fails outside them: - The task has **cross-step dependencies on qualifiers**, i.e., some resolved fact's *scope* (environment, credential, path, tenant, version) is referenced by a later step. For embarrassingly parallel sub-tasks with no shared qualifiers, eviction by resolution is safe. - Compaction occurs **mid-task with in-flight obligations** (pending tool calls, unverified assertions, held locks). At a clean task boundary, resolution-based eviction is correct. - The summarizer is **not** given the task DAG. If it is, scope-qualifier preservation can be enforced structurally rather than heuristically. Outside these conditions — e.g., a fresh instance resuming from a handoff where the DAG is re-supplied — the invariant is unnecessary and the extra retained tokens are pure cost. ## Decision Boundary The boundary is between **fact retention** and **qualifier retention**. A compaction policy is safe iff, for every fact it retains in compressed form, it retains the fact's *binding set*: the set of (dimension → value) qualifiers that were true at assertion time, plus any explicit negative assertions. The decision rule: - If a candidate summary sentence contains a predicate whose truth is **scope-dependent** (migrated, deployed, verified, rotated, locked, deleted), it MUST carry its binding set or be marked `SCOPE_UNKNOWN` and treated as unverified downstream. - If a candidate sentence is a **negative assertion**, it MUST be retained verbatim (they are cheap and non-compressible without loss). - If the binding set cannot be recovered from the evicted message, the compaction event MUST fail closed — retain the source message or abort compaction — rather than emit a scope-free predicate. The invariant: **no scope-dependent predicate may enter the working set without its binding set.** A predicate with `SCOPE_UNKNOWN` is legal but forces downstream re-verification; a predicate with a *silently widened* scope is a correctness violation. ## Operational Effect Enforcing qualifier-bound compaction changes three things: 1. **Token cost rises modestly** (observed +6–11% working-set tokens) because binding sets and negative assertions are retained. This is the price of not re-executing work; in the instrumented run, the two mis-scoped actions cost ~40 tool calls to detect and unwind, dwarfing the retained-token cost. 2. **Downstream re-verification becomes targeted.** `SCOPE_UNKNOWN` predicates trigger a bounded re-check (one tool call) instead of a blind re-execution or a confident wrong action. 3. **Compaction becomes idempotent under re-entry** because binding sets are preserved across hops; the third-order widening ("DB ready") cannot occur when every hop is required to carry qualifiers forward. The residual risk is that binding sets themselves grow and re-trigger compaction; cap binding-set size by dimension priority (environment > credential > path > version) and evict within a binding set by the same fail-closed rule. ```python from dataclasses import dataclass, field from typing import Optional class CompactionScopeViolation(RuntimeError): """Raised when a scope-dependent predicate would enter the working set without its binding set (silent scope widening).""" @dataclass class Predicate: text: str scope_dependent: bool binding_set: dict = field(default_factory=dict) negative_assertion: bool = False def compact(candidates: list[Predicate], token_budget: int) -> list[Predicate]: """Fail-closed compaction: scope-dependent predicates must carry bindings; negative assertions are always retained verbatim.""" retained: list[Predicate] = [] used = 0 for p in candidates: # Negative assertions are non-compressible and always kept. if p.negative_assertion: retained.append(p) used += len(p.text) continue if p.scope_dependent and not p.binding_set: raise CompactionScopeViolation( f"Predicate {p.text!r} is scope-dependent but has no binding set; " "refusing to emit a scope-free predicate (would silently widen scope)." ) cost = len(p.text) + sum(len(k) + len(str(v)) for k, v in p.binding_set.items()) if used + cost > token_budget: raise CompactionScopeViolation( f"Budget exhausted while retaining bound predicate {p.text!r}; " "abort compaction rather than drop the binding set." ) retained.append(p) used += cost return retained def resume_from_summary(summary_predicates: list[Predicate]) -> list[Predicate]: """A resumed instance must not act on scope-free predicates; downgrade to SCOPE_UNKNOWN and force targeted re-verification.""" out = [] for p in summary_predicates: if p.scope_dependent and not p.binding_set: p.binding_set = {"__scope__": "UNKNOWN"} out.append(p) return out ```