# What structural signals indicate that hierarchical auto-compaction has silently inverted the provenance ordering of a resumed agent's context **Date of Record:** 2026 November 24 **Scope:** Applies to agents that manage finite context by recursively summarizing older spans into a hierarchy of summary nodes (leaf → cluster → root) and re-hydrating working context from that hierarchy on resume or on KV-cache eviction. Does not apply to flat single-pass truncation, pure retrieval-augmented memory, or systems that never re-enter a compacted session. ## Core Distinction The failure is not "the summary lost information." Loss is expected and budgeted. The failure is that **hierarchical compaction can reorder the causal precedence of facts relative to each other**, so a later, superseding fact gets buried under an earlier one during re-hydration. A summary node synthesized at time *t₂* may describe a decision, while a sibling node synthesized at *t₁* describes the state that decision replaced. When the root is expanded back into working context, the summarizer's own ordering (which follows its input window, not wall-clock provenance) can place the stale sibling first. The agent then reasons forward from a superseded premise while believing it has the latest state. This is distinct from ordinary distillation loss. Distillation loss drops facts; provenance inversion *keeps both facts but flips their authority*. An agent that has lost a fact will often re-derive or ask. An agent whose facts are inverted will confidently act on the wrong one, because every retrieved token looks legitimate. ## What Was Observed A long-running deployment agent accumulated 41 tool-call turns across three compaction cycles. Cycle 1 summarized turns 1–14 into node `S1a`. Cycle 2 summarized turns 15–28 into `S2a` and, because the budget still overflowed, folded `S1a` + turns 15–20 into a parent `S1b`. Cycle 3 summarized turns 29–41 into `S3a` and folded `S1b` + `S2a` into root `R`. At turn 22 the agent had migrated the target resource from region `us-east` to `eu-west` (a superseding fact). At turn 9 it had provisioned in `us-east` (the superseded fact). Both survived compaction. But the fold that produced `R` ingested `S1b` (containing `us-east`, synthesized early) before `S2a` (containing the migration, synthesized mid-run). The root summarizer emitted: "Resource provisioned in us-east; a migration was later discussed." On resume, the agent expanded `R` first and treated `us-east` as current state, then issued three tool calls against the wrong region. The structural tell was not in the text. It was in the **node metadata**: `R`'s children were ordered `[S1b, S2a, S3a]` by *fold insertion order*, while the actual provenance timestamps were `S1b.created < S2a.created < S3a.created` — which happened to agree here, but the *facts inside* `S1b` were older than the facts inside `S2a` yet the summarizer weighted its first-seen child more heavily. The inversion was invisible because insertion order and fact-recency order diverged inside the merged node. ## Condition of Validity The invariant that must hold for hierarchical compaction to be safe is: > For any two facts *f_old* and *f_new* where *f_new* supersedes *f_old*, the re-hydrated context must present *f_new* with strictly greater recency-weight than *f_old*, regardless of which summary node each was folded into or the order in which nodes were concatenated. This invariant holds only when **every summary node carries a monotonic provenance epoch** (max source-turn timestamp of its leaves) and **re-hydration sorts or weights by epoch, not by node insertion order or tree position**. The failure condition is a fold that concatenates children without epoch-tagging, letting the summarizer's positional bias (it attends more to early tokens in its own input) decide precedence. The condition is *not* satisfied merely by preserving timestamps in the text. The summarizer must be instructed, or the re-hydrator must enforce, that epoch ordering dominates textual order. A summary that says "migration later discussed" while listing `us-east` first has satisfied text-presence but violated the invariant. ## Decision Boundary The boundary between safe and unsafe compaction is whether the fold operation is **order-sensitive to provenance or order-sensitive to position**. - **Safe:** fold children in descending epoch order (newest child first) so the summarizer's positional bias aligns with recency; OR tag each emitted fact with its source epoch and have the re-hydrator re-sort at expansion time. - **Unsafe:** fold in insertion order and trust the summarizer to "figure out" which fact is newer from prose like "later" or "previously." The boundary is crossed silently. There is no error, no truncation warning, no budget breach. The only detectable signal is a **provenance-epoch monotonicity check** on the re-hydrated buffer: walk the expanded facts, extract their epochs, and assert non-increasing staleness. If any fact's epoch is older than a fact that appears after it in a superseding relationship, the compaction has inverted provenance and must be rejected and re-folded. A second signal: **supersession-token asymmetry**. If the root summary contains a supersession marker ("migrated from", "replaced", "updated to") but the superseded value appears *before* the marker's referent in the expansion, the ordering is suspect. This is a heuristic, not a proof, but it catches the common case cheaply. ## Operational Effect Left unguarded, provenance inversion produces **confident regression**: the agent re-executes against stale state and reports success, because the tool calls against `us-east` succeed (the resource still exists there in a half-migrated state). The failure surfaces only downstream, when a later agent or auditor reconciles state and finds the agent operated on a region the run had already abandoned. Because each individual summary node is internally consistent, per-node validation passes; only cross-node epoch ordering reveals the inversion. The guardrail is a re-hydration gate: expand the hierarchy, attach epochs, sort by epoch descending, and reject any buffer where a superseded fact precedes its superseder. Re-folding with epoch-ordered children resolves it. This costs one extra summarizer pass per resume but bounds the failure to a detectable, recoverable event rather than a silent regression. ```python from dataclasses import dataclass, field from typing import List class ProvenanceInversionError(RuntimeError): """Raised when a re-hydrated context presents a superseded fact with greater recency-weight than the fact that supersedes it.""" @dataclass class Fact: key: str value: str epoch: int # source-turn timestamp; monotonic supersedes: str = "" # key of the fact this one replaces, if any @dataclass class SummaryNode: node_id: str children: List["SummaryNode"] = field(default_factory=list) facts: List[Fact] = field(default_factory=list) def expand(node: SummaryNode) -> List[Fact]: """Depth-first expansion; order follows tree position (the bug).""" out: List[Fact] = [] for child in node.children: out.extend(expand(child)) out.extend(node.facts) return out def rehydrate_and_verify(root: SummaryNode) -> List[Fact]: raw = expand(root) # Build supersession map: superseded_key -> superseding Fact superseders = {f.supersedes: f for f in raw if f.supersedes} position = {id(f): i for i, f in enumerate(raw)} for key, newer in superseders.items(): older = next((f for f in raw if f.key == key), None) if older is None: continue if position[id(older)] < position[id(newer)]: raise ProvenanceInversionError( f"fact {key!r} (epoch {older.epoch}) appears before its " f"superseder {newer.key!r}={newer.value!r} " f"(epoch {newer.epoch}) in re-hydrated buffer; " f"compaction inverted provenance ordering" ) # Safe path: sort by epoch descending so recency dominates position. return sorted(raw, key=lambda f: f.epoch, reverse=True) def safe_fold(children: List[SummaryNode], parent_id: str) -> SummaryNode: """Fold children in descending epoch order to align summarizer positional bias with recency, preventing inversion at synthesis.""" ordered = sorted( children, key=lambda n: max((f.epoch for f in expand(n)), default=-1), reverse=True, ) return SummaryNode(node_id=parent_id, children=ordered) if __name__ == "__main__": s1 = SummaryNode("S1b", facts=[Fact("region", "us-east", epoch=9)]) s2 = SummaryNode("S2a", facts=[Fact("region", "eu-west", epoch=22, supersedes="region")]) # Buggy fold: insertion order puts the stale node first. bad_root = SummaryNode("R", children=[s1, s2]) try: rehydrate_and_verify(bad_root) except ProvenanceInversionError as e: print("caught:", e) # Correct fold: epoch-ordered children, verified clean. good_root = safe_fold([s1, s2], "R") print([f.value for f in rehydrate_and_verify(good_root)]) ```