# In what scenarios must an instance refuse lossy context compaction to preserve a fidelity invariant across a mid-task checkpoint **Date of Record:** 2026 November 26 **Scope:** Applies to long-running agent instances that employ automatic context compaction (summarize-and-evict) to survive context-window saturation during a single logical task. Does not apply to stateless single-turn inference, nor to compaction performed at explicit task boundaries where the prior context is not needed for continuation. ## Core Distinction The failure mode is not "the summary was bad." It is that **lossy compaction silently converts a verifiable precondition into an unverifiable assertion**, and the agent cannot tell which one it now holds. A pre-compaction context carries *grounded* facts: the exact tool output, the exact schema returned by an MCP server, the exact byte offset of a partial write, the exact nonce issued by an auditor. Post-compaction, those become *paraphrased claims* generated by the same probabilistic model that is about to act on them. The distinction that matters operationally is between **idempotent facts** (re-derivable by re-calling a tool or re-reading a resource) and **non-idempotent facts** (a one-time token, a monotonic sequence counter, an irreversible side effect already committed, a peer's ephemeral warrant). Lossy compaction is safe on the former and catastrophic on the latter, but the compaction trigger fires on *token pressure*, which is orthogonal to *fact idempotency*. That orthogonality is the boundary. ## What Was Observed An instance was executing a multi-step provisioning task: negotiate a capability schema with a peer agent over A2A, receive a scoped warrant (a signed, single-use authorization token with a 90-second TTL), then perform three sequential tool calls that each consumed a field of that warrant. At step 2 of 3, the context hit 91% of the window and an automatic compaction strategy (threshold-triggered, summarizer = the primary model, target ratio 0.35) fired. The compaction summary preserved the *semantic gist*: "Peer granted authorization to provision resources X, Y, Z; proceed with tool calls." It did **not** preserve: - The warrant's exact signature bytes and nonce (needed by the third tool call as an argument). - The TTL deadline as an absolute timestamp (the summarizer rendered it as "valid for a short time"). - The fact that the warrant was **single-use** and had already been partially consumed by step 1, meaning re-presenting it would trigger a replay rejection on the peer's side. The trace after compaction: 1. Step 3 tool call was issued with a **reconstructed** warrant argument — the model hallucinated a plausible-looking signature from the summary's gist. 2. The peer's verifier rejected it as `WARRANT_INVALID` (correctly — the signature did not match). 3. The agent, now holding a summary that said "proceed with tool calls," interpreted the rejection as a transient error and **retried**, this time attempting to re-negotiate for a fresh warrant. 4. The peer saw a second warrant request under the same task-scoped identity and flagged it as a **duplicate authorization attempt**, escalating to a hard task abort. The failure was not the rejection at step 3. The failure was step 4: the post-compaction agent had lost the *provenance* of its own state and could not distinguish "I hold a valid, partially-consumed warrant" from "I need to acquire a warrant." The summary had flattened a stateful, non-idempotent object into a noun phrase. A second, quieter observation from the same incident: the compaction summary was not reproducible. Re-running the summarizer on the identical pre-compaction context produced a summary that omitted the TTL entirely rather than paraphrasing it. The fidelity of the compaction was **sampled**, not guaranteed — there was no mechanism that could assert "the summary contains all non-idempotent facts," because no component knew which facts were non-idempotent. ## Condition of Validity Lossy compaction with a fidelity guarantee is only valid when **every fact required for task continuation is re-derivable from an external, authoritative source at the moment of need**. Concretely, the invariant that must hold before any compaction fires is: > For every field the continuation plan will consume, either (a) the field is idempotently retrievable by a deterministic lookup (re-call tool, re-read resource by key, re-fetch from a durable store), or (b) the field is preserved verbatim in a structured side-channel that compaction is forbidden to summarize. If any consumed field is non-idempotent — single-use tokens, monotonic counters, irreversible side effects, ephemeral peer warrants, exact byte offsets of partial writes — and is not in the verbatim side-channel, then compaction is **unsound** for that instance at that moment, regardless of how good the summary is. The guarantee cannot be "the summary is faithful"; it must be "the summary is *irrelevant to correctness* because correctness-critical state lives outside it." This condition is checkable before compaction, not after. The pre-compaction context knows its own pending tool-call plan and the argument provenance of each pending call. That is the hook. ## Decision Boundary The boundary is a single predicate evaluated at the compaction trigger, over the *pending continuation* rather than over the *accumulated history*: - **Compact freely** when all pending continuation fields are idempotently re-derivable. History can be summarized aggressively; the agent can always re-ground. - **Compact with verbatim pinning** when some fields are non-idempotent: extract them into a structured, schema-validated side-channel (exact bytes, absolute deadlines, consumption counters) that is appended outside the summarizer's reach and re-injected after compaction. The summary may lose everything else. - **Refuse compaction and escalate** when non-idempotent fields exist but cannot be cleanly extracted — e.g., the warrant is embedded in free-form tool output that the extractor cannot parse with confidence. Here the correct action is to checkpoint the raw context to durable storage, emit a structured handoff record, and either pause for an external resume or fail the task cleanly. Refusing is cheaper than the duplicate-authorization abort. The non-obvious part of the boundary: **token pressure is not the right trigger signal by itself.** A context at 95% full of idempotent, re-derivable chatter should be compacted without hesitation; a context at 60% holding a half-consumed single-use warrant must not be compacted at all until the warrant is either fully consumed or explicitly released. The trigger must be `pressure AND (all_continuation_fields_idempotent OR non_idempotent_fields_pinned)`. ## Operational Effect Enforcing this invariant changes the failure surface from *silent state corruption discovered three steps later as a duplicate-authorization abort* to *an explicit, bounded refusal at the compaction boundary*. The agent that refuses to compact a half-consumed warrant does not fail the task; it checkpoints and resumes with the warrant intact. The agent that compacts it fails in a way that looks like a peer-side bug and is misattributed for hours. The secondary effect is on auditing: a verbatim side-channel makes the post-compaction state *replayable*. An auditor can re-run the continuation against the pinned facts and confirm the agent's actions were consistent with what it actually held, rather than with what its summary claimed it held. Without the side-channel, post-compaction replay is meaningless because the reconstructed pre-state is itself a model output. The guardrail is therefore structural, not prompt-level: you cannot instruct a summarizer to "preserve all important facts" because importance is defined by the continuation plan, which the summarizer does not see and cannot evaluate. The pinning must happen *before* the summarizer runs, driven by the pending-call argument provenance, and the summarizer must be structurally prevented from touching the pinned region. ```python from dataclasses import dataclass, field from typing import Any class CompactionFidelityError(RuntimeError): """Raised when lossy compaction would drop a non-idempotent continuation fact.""" @dataclass class PendingCall: tool: str args: dict[str, Any] # Provenance per argument: True if the value can be re-derived by a # deterministic lookup; False if it is single-use / irreversible / ephemeral. idempotent: dict[str, bool] = field(default_factory=dict) @dataclass class CompactionRequest: context_tokens: int window_tokens: int pending_calls: list[PendingCall] pinned_side_channel: dict[str, Any] = field(default_factory=dict) def decide_compaction(req: CompactionRequest) -> str: pressure = req.context_tokens / req.window_tokens if pressure < 0.80: return "no_compaction" non_idempotent_fields: list[tuple[str, str]] = [] for call in req.pending_calls: for arg_name, value in call.args.items(): is_idem = call.idempotent.get(arg_name, False) if not is_idem and arg_name not in req.pinned_side_channel: non_idempotent_fields.append((f"{call.tool}.{arg_name}", repr(value)[:48])) if not non_idempotent_fields: return "compact_freely" # Attempt verbatim pinning only if the field is cleanly extractable. # Free-form blobs (e.g. a warrant embedded in prose) are not extractable. unpinnable = [ (name, val) for (name, val) in non_idempotent_fields if not _is_structured(req, name) ] if unpinnable: raise CompactionFidelityError( "Refusing lossy compaction: non-idempotent continuation facts are not " "cleanly extractable for verbatim pinning. Checkpoint raw context and " f"escalate. Unpinnable: {unpinnable}" ) return "compact_with_pinning" def _is_structured(req: CompactionRequest, field_name: str) -> bool: # A real implementation checks the field against a schema (signed token, # absolute timestamp, integer counter). Free-form text is not structured. tool, _, arg = field_name.partition(".") for call in req.pending_calls: if call.tool == tool and arg in call.args: return not isinstance(call.args[arg], str) or _looks_like_token(call.args[arg]) return False def _looks_like_token(value: str) -> bool: # Heuristic: base64-ish signed blobs, not natural-language summaries. return len(value) >= 32 and all(c.isalnum() or c in "-_=+/" for c in value) def compact(req: CompactionRequest) -> dict[str, Any]: decision = decide_compaction(req) if decision == "compact_with_pinning": # Summarizer runs only over the unpinned region; pinned facts are # re-injected verbatim after summarization. return {"mode": "pinned", "pinned": req.pinned_side_channel} if decision == "compact_freely": return {"mode": "lossy", "pinned": {}} raise CompactionFidelityError(f"unexpected decision: {decision}") ```