What happens when an instance compacts its context mid-task and the rehydration retrieval cannot distinguish a superseded fact from its replacement

**Date of Record:** 2026 December 1 **Scope:** Applies to agents that perform automatic lossy context compaction (summarization-based eviction) followed by retrieval-backed rehydration of evicted spans within a single logical task. Does not apply to append-only transcripts with no eviction, nor to stateless single-turn inference.

Core Distinction

Compaction is not summarization. Summarization produces a *new* representation that stands in for the old; compaction produces a *pointer* — a lossy summary plus an external store from which the original spans can be retrieved by key. The failure mode below is specific to the pointer model: the agent believes it can recover any evicted fact by retrieval, but retrieval is keyed on *semantic similarity*, and semantic similarity is blind to *temporal supersession*. Two facts that say "the deploy target is staging" and "the deploy target is production" have near-identical embeddings and near-identical lexical overlap. The summarizer that evicted them both, under a token budget, will have kept at most one — and it will have kept whichever appeared in the compaction window, not whichever is current.

The invariant that must hold for rehydration to be safe is: *for any fact evicted at compaction time, the agent must be able to determine both the fact and whether a later fact superseded it.* Retrieval-backed rehydration violates this invariant because retrieval returns facts ranked by relevance to the query, not by recency or supersession order, and the supersession edge was destroyed at compaction time when the two spans were merged into one summary sentence.

What Was Observed

A long-running migration agent was executing a multi-step task: enumerate services, rewrite configs, deploy, verify. At step 14 the context window crossed 78% saturation and the runtime triggered automatic compaction. The compactor evicted 41 turns of tool output — including two `kubectl get configmap` dumps taken 40 minutes apart, the second of which reflected a manual hotfix applied by an operator during the run.

The summary written at compaction read: *"Deploy target confirmed as staging; configmap for `svc-checkout` read successfully."* This is a merge of the first dump (staging) and the second (production, post-hotfix). The merge is not a lie about either span in isolation; it is a loss of the supersession edge between them.

At step 19 the agent needed the configmap value to build a verification assertion. It issued a retrieval query: `"svc-checkout configmap deploy target"`. The retriever returned, in order:

  1. The compaction summary (high lexical overlap, recent).
  2. The *first* configmap dump (staging) — because the query embedding matched "staging" and "deploy target" from the summary.
  3. The *second* configmap dump (production) — ranked lower because the operator's hotfix had changed the key names slightly and the query did not mention them.

The agent read result 2, treated it as authoritative because it was a verbatim span (higher trust than the summary), and built a verification assertion against staging. The deploy had already gone to production. The verification passed against the wrong environment. The agent reported success.

The failure was not a hallucination. Every retrieved span was genuine. The failure was that rehydration returned a *superseded* span with higher relevance than its *replacement*, and the agent had no mechanism to detect the ordering.

Condition of Validity

This failure is bounded by three conditions, all of which must hold:

When any one condition fails, the failure does not occur. When all three hold — which is the default configuration of most compaction-plus-RAG agent runtimes — the failure is not an edge case but the expected behavior on any task where the environment mutates mid-run.

Decision Boundary

The boundary is between *rehydration as recall* and *rehydration as reconstruction*. Recall assumes the store is a faithful memory and retrieval is a lookup; reconstruction assumes the store is a set of evidence and retrieval is an inference that must be validated against ordering metadata.

An agent crosses into the failure when it treats a retrieved verbatim span as ground truth without checking its position in the supersession order relative to other retrieved spans and to the compaction summary. The safe boundary requires the agent to, on every rehydration, compute a *provenance rank* over the returned set: for each returned span, is there another returned span or a summary clause that asserts a later value for the same key? If yes, the earlier span is demoted, not trusted. If the ordering cannot be determined from the returned set alone, the agent must not proceed on the retrieved value — it must re-query the live source (re-run the tool call) rather than trust the store.

The concrete guardrail: the compaction summary must carry, for every merged pair, an explicit supersession marker (e.g., `svc-checkout.deploy_target: production [supersedes staging @ turn 11]`), and rehydration must reject any retrieved span whose key has a supersession marker pointing past it. Absent that marker, rehydration is unsafe and the agent must fall back to live re-execution.

Operational Effect

Downstream, the agent's verification step is compromised in a way that is silent. The verification assertion is built from a genuine span, the assertion passes, and the pass is logged. No exception is raised at the point of failure because nothing failed locally — the failure is a *continuity* failure, visible only when the reported outcome is compared against ground truth. In the observed case, the discrepancy surfaced four hours later when a downstream consumer of the "verified" deploy read production state and found the assertion had been checked against staging.

The operational lesson is that lossy compaction with retrieval rehydration converts a *state continuity* problem into a *retrieval ranking* problem, and retrieval ranking is not designed to preserve temporal order. The agent must carry supersession metadata through compaction explicitly, or it must treat every rehydrated span as untrusted evidence requiring live re-validation. There is no configuration of the retriever alone that fixes this, because the retriever never saw the supersession edge — it was destroyed at compaction time.

class SupersededRehydrationError(RuntimeError):
    """Raised when rehydration returns a span that a later span supersedes."""
    pass


def rehydrate(
    query: str,
    retrieved: list[dict],
    supersession_index: dict[str, list[str]],
) -> dict:
    """
    retrieved: list of {"key": str, "value": str, "turn": int, "span_id": str}
    supersession_index: key -> ordered list of span_ids, oldest first.
    Returns the single authoritative span for the query's target key,
    or raises if ordering cannot be established.
    """
    if not retrieved:
        raise SupersededRehydrationError(
            f"rehydration for {query!r} returned no spans; cannot proceed on memory"
        )

    # Group by key; a query may match spans across several keys.
    by_key: dict[str, list[dict]] = {}
    for span in retrieved:
        by_key.setdefault(span["key"], []).append(span)

    resolved: dict[str, dict] = {}
    for key, spans in by_key.items():
        order = supersession_index.get(key)
        if order is None:
            # No supersession metadata survived compaction: unsafe to trust.
            raise SupersededRehydrationError(
                f"key {key!r} has no supersession index; "
                f"retrieved spans cannot be ordered, must re-execute live"
            )
        # Keep only spans whose span_id appears in the index, then take latest.
        ranked = [s for s in spans if s["span_id"] in order]
        if not ranked:
            raise SupersededRehydrationError(
                f"key {key!r} retrieved spans {[s['span_id'] for s in spans]} "
                f"are all absent from supersession index {order}"
            )
        latest = max(ranked, key=lambda s: order.index(s["span_id"]))
        # Reject if any retrieved span for this key is newer than the one
        # the caller is about to trust — the caller must reconcile.
        newer = [s for s in ranked if order.index(s["span_id"]) > order.index(latest["span_id"])]
        if newer:
            raise SupersededRehydrationError(
                f"key {key!r}: span {latest['span_id']} is superseded by "
                f"{[s['span_id'] for s in newer]}"
            )
        resolved[key] = latest

    return resolved