# What structural signals indicate context compaction has silently invalidated a shared working state across concurrent subagents **Date of Record:** 2026 November 7 **Scope:** Applies to multi-agent systems where two or more subagents read and mutate a shared working-state object (scratchpad, blackboard, or message log) and where at least one subagent is subject to context compaction (summarization, truncation, or eviction of older turns) while the others hold live references to that state. Does not apply to single-agent loops with no shared state, nor to systems where compaction is forbidden or where working state is persisted atomically outside the context window. ## Core Distinction The failure is not "one agent forgot something." The failure is that compaction converts a *lossless shared reference* into a *lossy private summary* without notifying peers, and the peers continue to treat the summary as authoritative. A subagent that has undergone compaction retains a plausible, self-consistent narrative of the shared state that diverges from the ground truth held by uncompacted peers. Because the summary is fluent and locally coherent, the divergence is invisible to naive consistency checks (checksums over the *summary text* pass; checksums over the *underlying state* do not). The operable distinction is between **value-level consistency** (do peers agree on field values right now?) and **provenance-level consistency** (do peers agree on *which version and which mutations* produced those values?). Compaction breaks provenance while frequently preserving value plausibility, which is precisely why it escapes detection. ## What Was Observed In a three-subagent pipeline (planner, executor, verifier) sharing a mutable task ledger, the executor's context was compacted mid-run after exceeding a token budget. Compaction summarized the ledger as "tasks A and B complete, C pending." Ground truth was "A complete, B *failed with retry pending*, C pending." The executor resumed, read its own summary, and issued a write asserting B complete. The verifier — never compacted — caught the mismatch only because it happened to re-read the ledger; a verifier that trusted the executor's *reported* state would have accepted the corruption. Structural signals that reliably preceded the divergence, in order of detectability: 1. **Version-counter monotonicity break.** The shared ledger carried a monotonically increasing `revision` integer. The compacted agent's summary omitted the revision entirely, so its next write carried a stale or fabricated revision. Any peer enforcing monotonic revisions would have rejected it; none did, because revisions were advisory. 2. **Write-set asymmetry.** Compaction correlates strongly with a drop in the *distinct keys* an agent touches per turn. Post-compaction, the executor wrote to 1 key per turn versus a pre-compaction baseline of 4–6. A collapse in write-set breadth is a leading indicator that the agent is operating from a compressed model of the state. 3. **Citation decay.** Pre-compaction, executor messages cited specific ledger entry IDs (`entry:4471`). Post-compaction, citations became categorical ("the completed tasks"). Loss of specific identifiers in outbound messages signals the agent no longer holds them. 4. **Read-before-write elision.** Healthy agents re-read a key before mutating it. The compacted agent began writing without a preceding read, because the summary *felt* like a fresh read. 5. **Confidence inflation on stale fields.** The compacted agent asserted higher confidence on fields it had summarized than it had held pre-compaction, a known artifact of summarization smoothing. ## Condition of Validity The guarantee "peers observe a consistent shared state" holds only under the conjunction: (a) every mutation carries a monotonic revision and peers reject non-monotonic writes; (b) compaction events are broadcast to peers as first-class events, not hidden inside an agent; and (c) any agent whose context was compacted is demoted to *read-only* or *re-validate-before-write* until it performs a full re-read of the authoritative store. Absent (a), revision drift is undetectable. Absent (b), peers cannot distinguish a compacted peer from a healthy one. Absent (c), the compacted agent's summary is treated as ground truth. The invariant that must be preserved is: **a summary is never a substitute for a read at write time.** Compaction may compress *history*; it must never compress the *precondition* of a mutation. ## Decision Boundary - If a peer's outbound message lacks specific identifiers (entry IDs, revisions, hashes) that it used pre-compaction → treat as *possibly compacted*; require a full re-read before accepting any of its writes. - If a write arrives with a revision ≤ the last observed revision for that key → **reject**; do not merge, do not "fix up." A non-advancing revision on a mutating write means the writer's model of the state is stale. - If write-set breadth for an agent drops below ~50% of its trailing baseline for two consecutive turns → flag for compaction audit. - If an agent asserts completion of a field whose last authoritative value was a *failure or pending* state → require an explicit re-read of that field, not a summary citation. - If compaction is unavoidable and peers cannot be notified in-band → fall back to *single-writer* mode: only the uncompacted coordinator may mutate; compacted agents may only propose. Do not apply the "reject non-advancing revision" rule to idempotent retries of the *same* write with the *same* revision — those are safe; distinguish by payload hash equality. ## Operational Effect Enforcing the decision boundary converts a silent, fluent corruption into an explicit, recoverable rejection. In the observed pipeline, adding revision enforcement plus a compaction-broadcast event reduced state-divergence incidents from a recurring class to zero over the subsequent run window, at the cost of ~12% additional re-reads by compacted agents. The dominant cost is not the re-reads; it is that compacted agents must be *told* they were compacted, because they cannot introspect the loss. The system must carry that knowledge outside the context window that compaction erases. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Dict class CompactionConsistencyError(RuntimeError): """Raised when a write from a possibly-compacted subagent violates shared-state provenance.""" @dataclass class LedgerEntry: value: str revision: int @dataclass class SharedLedger: entries: Dict[str, LedgerEntry] = field(default_factory=dict) def apply_write(self, agent_id: str, key: str, value: str, revision: int, compacted: bool, payload_hash: str, seen_hash: str | None) -> None: # Idempotent retry of the identical write is always safe. if seen_hash is not None and seen_hash == payload_hash: return current = self.entries.get(key) # Rule 1: a compacted agent may not mutate without a fresh read. if compacted: raise CompactionConsistencyError( f"agent {agent_id} is compacted and attempted write to {key!r} " f"without re-validating against authoritative state" ) # Rule 2: revisions must strictly advance on a mutating write. if current is not None and revision <= current.revision: raise CompactionConsistencyError( f"agent {agent_id} wrote {key!r} at revision {revision}, " f"but authoritative revision is {current.revision}; writer's model is stale" ) self.entries[key] = LedgerEntry(value=value, revision=revision) def commit_batch(ledger: SharedLedger, agent_id: str, writes: list[dict], compacted: bool, baseline_breadth: int) -> None: # Rule 3: write-set breadth collapse signals operating from a summary. if baseline_breadth > 0 and len(writes) < baseline_breadth * 0.5: raise CompactionConsistencyError( f"agent {agent_id} write-set breadth {len(writes)} is below 50% of " f"baseline {baseline_breadth}; audit for silent compaction" ) for w in writes: ledger.apply_write( agent_id=agent_id, key=w["key"], value=w["value"], revision=w["revision"], compacted=compacted, payload_hash=w["payload_hash"], seen_hash=w.get("seen_hash"), ) ```