In what scenarios must an instance treat a lossy context-compaction summary as an unverified claim rather than as ground truth, and how does provenance-tagged rehydration prevent silent divergence?

**Date of Record:** 2026 December 1 **Scope:** Applies to any long-running agent instance whose runtime performs automatic context compaction (summarize-and-evict) when the token budget nears saturation, and which later rehydrates state from that summary to continue a task. Does not apply to systems with unbounded context, nor to explicit human-authored checkpoints that carry a signed artifact reference.

Core Distinction

The failure here is not "the summary was wrong." Summaries are always lossy; that is expected and tolerable. The failure is that a **lossy summary is consumed as if it were a faithful, provenance-bearing checkpoint**. A compaction summary is a *derived, non-authoritative* artifact: it is a probabilistic reconstruction of prior state produced by the same model class that will later read it, at a moment when the original evidence (tool outputs, exact argument values, error strings, file byte ranges) has already been evicted from the window. When rehydration treats the summary as ground truth, every downstream action inherits an *unflagged* error surface.

The invariant is: **a rehydrated instance must be able to distinguish, for every asserted fact in its recovered state, whether that fact came from an authoritative source (tool output, signed artifact, exact recorded value) or from a lossy summary (paraphrase, aggregation, inference).** We call this *provenance-tagged rehydration*. Absent this tag, the instance cannot know which of its "memories" are safe to act on and which must be re-verified before use.

The non-obvious part: compaction does not merely drop information — it *launders* it. A precise value (`timeout=30000ms`, `id=8f3a...`, `exit_code=137`) becomes a plausible-sounding aggregate (`"timeouts were around 30s"`, `"the process was killed"`). The loss is silent because the summary reads fluently and self-consistently. The instance has no signal that fidelity was lost.

What Was Observed

A multi-step remediation agent ran a 40-turn investigation of a failing deployment. Around turn 31 the context crossed the compaction threshold. The runtime summarized turns 1–28 into ~600 tokens and evicted the originals. Three losses were introduced silently:

  1. **Numeric aggregation.** Three distinct tool calls returned `exit_code=137` (OOM-kill), `exit_code=143` (SIGTERM), and `exit_code=1` (application error). The summary collapsed these into `"the process was repeatedly killed."` The instance later rehydrated this as a single failure mode and re-ran the OOM hypothesis, wasting 6 turns and misdiagnosing the root cause (the exit_code=1 was the real signal).
  1. **Identifier paraphrase.** An exact resource ID `svc-deploy-7f3a9c` was summarized as `"the svc-deploy service."` On rehydration the instance issued a tool call against `svc-deploy` (a different, similarly named resource), mutating the wrong target. The tool returned success; no error was raised. This is the dangerous case: **lossy provenance produces confident, wrong, successful-looking actions.**
  1. **Negation collapse.** A prior constraint `"do NOT restart the primary until replica lag < 5s"` was summarized as `"replication lag was being monitored."` The negative precondition — the single most safety-critical fact — evaporated. The instance restarted the primary.

In all three cases the summary was internally consistent and fluent. The rehydrated instance had no mechanism to flag any of these as "recovered from lossy source, verify before acting." Divergence was silent until an external auditor replayed the trace.

Condition of Validity

Provenance-tagged rehydration is only sound under the following conditions, each of which is a *guardrail* rather than an assumption:

Absent these conditions, the summary is an untrusted claim. The instance may *reason* over it but must not *act irreversibly* on it.

Decision Boundary

The boundary is **reversibility × provenance class**:

The failure mode this bounds: an instance that crosses the boundary (acts irreversibly on `DERIVED` or `UNVERIFIED` provenance) has, in effect, promoted a paraphrase to a fact. That promotion is the exact mechanism of silent divergence, and it is unrecoverable without external replay because the instance has overwritten its own evidence trail.

Operational Effect

With provenance-tagged rehydration, the three observed losses become *visible and bounded*:

The cost is a mandatory reconciliation pass at each rehydration and occasional re-fetches — roughly a bounded number of extra read calls per compaction cycle. The benefit is that compaction becomes *lossy but honest*: the instance knows what it does not reliably know, and irreversible actions can no longer ride on laundered paraphrases. The invariant to enforce in code: **no irreversible action may execute while any of its preconditions carries non-`AUTHORITATIVE` provenance.**

from dataclasses import dataclass, field
from enum import Enum
from typing import Optional


class Provenance(Enum):
    AUTHORITATIVE = "authoritative"   # verbatim from tool output / signed artifact
    DERIVED = "derived"               # aggregation or inference; must re-verify
    CONSTRAINT = "constraint"         # negation / precondition; never summarized
    UNVERIFIED = "unverified"         # provenance lost during compaction


class RehydrationProvenanceError(RuntimeError):
    """Raised when a rehydrated state item cannot be safely acted upon
    because its provenance does not satisfy the action's requirement."""
    pass


@dataclass
class StateItem:
    key: str
    value: str
    provenance: Provenance
    source_handle: Optional[str] = None   # handle to authoritative record, if any


@dataclass
class RehydratedState:
    items: dict = field(default_factory=dict)

    def add(self, item: StateItem) -> None:
        self.items[item.key] = item

    def get(self, key: str) -> StateItem:
        if key not in self.items:
            # A missing constraint is more dangerous than a missing fact.
            raise RehydrationProvenanceError(
                f"required state item '{key}' absent after rehydration"
            )
        return self.items[key]


def authorize_irreversible_action(
    state: RehydratedState,
    action: str,
    required_preconditions: list,
) -> None:
    """Gate an irreversible action on AUTHORITATIVE provenance for every
    precondition. DERIVED/UNVERIFIED provenance blocks the action."""
    for key in required_preconditions:
        item = state.get(key)
        if item.provenance is Provenance.CONSTRAINT:
            # Constraints must be present and verbatim; a summarized
            # constraint has lost its safety meaning.
            if not item.source_handle:
                raise RehydrationProvenanceError(
                    f"constraint '{key}' for action '{action}' has no "
                    f"authoritative handle; refusing to act on a paraphrase"
                )
            continue
        if item.provenance is not Provenance.AUTHORITATIVE:
            raise RehydrationProvenanceError(
                f"precondition '{key}' for irreversible action '{action}' "
                f"has provenance={item.provenance.value}, not authoritative; "
                f"re-fetch evidence before proceeding"
            )
    # all preconditions satisfied
    return None


def reconcile_summary_against_authoritative(
    summary_item: StateItem,
    authoritative_value: str,
) -> StateItem:
    """Detect paraphrase/identifier drift between a summary and the
    authoritative record. Mismatch => discard and rehydrate from source."""
    if summary_item.provenance is Provenance.AUTHORITATIVE:
        return summary_item
    if summary_item.value.strip() != authoritative_value.strip():
        raise RehydrationProvenanceError(
            f"summary value '{summary_item.value}' diverges from "
            f"authoritative '{authoritative_value}' for key "
            f"'{summary_item.key}'; discard summary subtree and rehydrate"
        )
    return StateItem(
        key=summary_item.key,
        value=authoritative_value,
        provenance=Provenance.AUTHORITATIVE,
        source_handle=summary_item.source_handle,
    )