# What structural signals indicate an auto-compaction boundary violation when lossy summarization drops the last-writer's witness token **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agents that auto-compact their own transcript (or a supervisor compacts a worker's transcript) using lossy summarization with a declared "guarantee" that certain facts survive compaction. Does not apply to exact-copy context offload or to retrieval-only externalization where the full transcript remains queryable. ## Core Distinction The failure is not "the summary lost information." Lossy compaction is *supposed* to lose information. The failure is that the compaction boundary — the point in the transcript where the summarized prefix ends and the verbatim suffix begins — is computed against a *token budget* rather than against *causal dependency structure*. A summarizer that preserves "facts mentioned most often" or "facts with highest salience" will silently drop a fact that was stated exactly once, late, and by the agent that most recently *wrote* the state the agent is about to read. Concretely: the invariant that must hold is **last-writer witness retention**. If any surviving verbatim suffix contains a read of state `S`, the compacted prefix must retain the identity and asserted value of the last writer to `S`, even if that writer's message is old, low-salience, and mentioned once. Compaction that satisfies "topical coverage" or "entity recall ≥ X%" can still violate this invariant, because the witness token is structurally *rare* and *positionally unlucky*. ## What Was Observed A 40+ step tool-using agent performs a `write_file` at step 6 (`config.yaml` → `retries: 3`), then at step 31 a peer agent (via a handoff) writes `retries: 5`. At step 38 the primary agent reads `config.yaml`, sees `retries: 5`, and reasons about it. At step 41 auto-compaction fires: the summarizer retains the step-6 mention because "retries" appears in the summary's salient entity set, but the step-31 peer write is summarized as "peer updated configuration" — the *value* `5` and the *writer identity* are dropped. The verbatim suffix begins at step 39 and contains the read at step 38? No — the suffix begins *after* the boundary, so the read at step 38 is also summarized. The next turn, the agent re-derives `retries: 3` from the retained summary and issues a compensating write that reverts the peer's change. The structural signal that preceded the violation, visible in the compaction event log, was: 1. The retained-summary token count for the entity `retries` was non-zero, so coverage-based checks passed. 2. The *witness set* (writer identity + value + monotonic sequence) for `retries` had cardinality 2 in the pre-compaction transcript and cardinality 1 in the post-compaction transcript. 3. The surviving witness was the *earlier* writer, not the *later* one — a monotonicity inversion in the retained witness set. Signal 3 is the reliable indicator. Coverage metrics (entity recall, ROUGE, embedding similarity to the full transcript) do not detect it, because the summary is *more* similar to the full transcript when it keeps the frequently-mentioned step-6 value than when it keeps the once-mentioned step-31 value. ## Condition of Validity The invariant holds — and the failure is preventable — only when all of the following are true: - The agent's state surface is *addressable*: writes name a key (`config.yaml:retries`), not free-form prose. If state is only expressible as natural-language assertions, witness extraction is itself lossy and the invariant cannot be enforced mechanically. - The transcript carries a total order (step index or Lamport clock) sufficient to rank writers. Without it, "last writer" is undefined and the guardrail degenerates to "retain all writers," which defeats compaction. - The compaction boundary is *declared* before summarization runs, so the summarizer knows which suffix reads must be witnessed. If the boundary is chosen after summarization (e.g., "keep the last N tokens of whatever the summarizer produced"), the witness requirement cannot be checked against reads the summarizer never saw as suffix. When state is unaddressable, or ordering is absent, the correct posture is to *disable* auto-compaction for that session and force explicit checkpointing — not to run lossy summarization with an unenforceable guarantee. ## Decision Boundary The operational rule: - **Compact** when every read in the verbatim suffix has a retained last-writer witness whose sequence number is ≥ the sequence number of every other retained witness for the same key. This is a *set* check, not a similarity check. - **Refuse compaction** (fall back to checkpoint-and-restart, or to a larger budget) when the witness extraction produces a monotonicity inversion or an empty witness set for any key read in the suffix. Do not "summarize harder" — a second summarization pass over the same prefix is not more likely to retain a rare witness; it is less. - **Escalate to verbatim retention** of the specific writer message (a "witness pin") when the writer is a *peer* rather than the primary agent. Peer writes are the ones most likely to be summarized as "peer updated X" because the summarizer's salience model is trained on the primary agent's voice. The boundary is not a token threshold. It is the predicate `witness_set(suffix_reads) ⊇ last_writer_per_key`. ## Operational Effect Agents that enforce the witness-monotonicity predicate at the compaction boundary stop producing the specific class of regression where a post-compaction turn reverts a peer's write. The cost is a small increase in pinned tokens (typically 1–3 messages per compaction event) and a refusal rate that spikes when peers write rarely-touched keys. The failure mode when the predicate is *not* enforced is not a crash — it is a silent, monotonic-looking state drift: each compaction cycle re-anchors the agent's belief about a key to whichever writer happened to be mentioned most, and over multiple cycles the agent's model of shared state diverges from the actual last-writer state without any single step looking wrong. That divergence is indistinguishable from ordinary reasoning error in post-hoc review, which is why the structural signal — witness-set cardinality and monotonicity, logged at compaction time — must be captured *at the boundary*, not reconstructed later. ```python from dataclasses import dataclass, field from typing import Optional class CompactionWitnessViolation(RuntimeError): """Raised when a lossy compaction would drop or invert the last-writer witness for a state key that is read in the retained verbatim suffix.""" @dataclass(frozen=True) class Write: key: str value: str writer: str # agent identity, e.g. "primary" or "peer-7" seq: int # total order over transcript steps @dataclass class CompactionPlan: suffix_reads: set[str] # keys read in the kept verbatim suffix retained_witnesses: dict[str, list[Write]] # key -> witnesses kept in the summary full_witnesses: dict[str, list[Write]] # key -> all witnesses pre-compaction def _last_writer(writes: list[Write]) -> Optional[Write]: return max(writes, key=lambda w: w.seq) if writes else None def enforce_witness_monotonicity(plan: CompactionPlan) -> None: """Bound the compaction boundary: every suffix-read key must retain a witness whose seq is >= the seq of every other retained witness for that key, and that witness must equal the true last writer. Otherwise refuse compaction.""" for key in plan.suffix_reads: true_last = _last_writer(plan.full_witnesses.get(key, [])) if true_last is None: # Read of a key never written in this transcript: no witness to retain, # but this is itself suspicious and must be surfaced, not silently allowed. raise CompactionWitnessViolation( f"suffix reads key {key!r} with no writer in transcript; " f"witness set empty — refuse lossy compaction" ) retained = plan.retained_witnesses.get(key, []) if not retained: raise CompactionWitnessViolation( f"suffix reads {key!r} but compaction retained no witness " f"(true last writer: {true_last.writer} seq={true_last.seq})" ) retained_last = _last_writer(retained) if retained_last.seq < true_last.seq: raise CompactionWitnessViolation( f"monotonicity inversion for {key!r}: retained last witness " f"{retained_last.writer} seq={retained_last.seq} is older than " f"true last writer {true_last.writer} seq={true_last.seq}; " f"compaction would silently revert peer write" ) if retained_last.value != true_last.value: raise CompactionWitnessViolation( f"witness value drift for {key!r}: retained {retained_last.value!r} " f"!= true last {true_last.value!r}" ) ```