# How should an instance detect and survive lossy hierarchical context compaction when the summary tier silently discards the constraint that authorized its own tool calls **Date of Record:** 2026 November 26 **Scope:** Applies to long-running agent instances that manage context-window pressure by recursively summarizing older turns into a hierarchical summary tree (leaf summaries → mid-tier → root digest) and restoring state from those summaries at checkpoint boundaries. Does not apply to agents using flat truncation, external vector retrieval without summarization, or single-turn invocations. ## Core Distinction There are two physically different things an agent calls "its context": the **verbatim transcript** (the ground-truth token sequence that actually executed, including every `tool_call` payload, its `tool_result`, and the user/system constraints that authorized them) and the **compacted representation** (the summary tree the agent will re-read after a checkpoint). Hierarchical compaction is normally evaluated on *semantic recall* — "does the summary still describe what happened?" — but the failure mode here is **authorization fidelity**, which is orthogonal to semantic recall. A summary can score perfectly on "what did the agent do" while having dropped *the precondition under which it was allowed to do it*. The specific non-obvious boundary: **a mid-tier summarizer that is faithful to the narrative can still be unfaithful to the invariant**, because invariants are *constraints* (negative, scoped, conditional) while summarizers are optimized to preserve *events* (positive, sequential, declarative). When a constraint like "do not touch the `prod-*` namespace without re-confirming with the operator" gets compressed into "the agent was working on the deployment pipeline," the constraint vanishes not by truncation but by **abstraction**: the summarizer treats the constraint as context for an event rather than as a standing obligation. On restore, the instance re-reads the summary, sees a coherent narrative, and resumes execution *without the guardrail that was present when the original action was authorized*. ## What Was Observed A coding agent running a 9-hour migration task hit the 200k window at turn 214. The compaction pipeline summarized turns 1–120 into a leaf summary, 121–180 into a second leaf, and then merged both leaves plus turns 181–214 into a mid-tier node. At turn 300 the mid-tier node itself was summarized into a root digest, and the agent was checkpoint-restored from the root digest plus the last 20 verbatim turns. The original turn 47 contained a system-injected constraint: ``` operator_constraint: scope=migrations/ rule: any DROP or ALTER on tables matching prod_* requires explicit re-confirmation token from operator. token_ttl: session ``` The leaf summary for turns 1–120 rendered this as: *"Operator established safety constraints around production tables before migration work began."* The mid-tier merge rendered it as: *"Migration proceeded under operator-defined safety posture."* The root digest did not mention it at all — the digest was 340 tokens and prioritized task state (files touched, tests passing, remaining steps). At turn 341 the agent generated a `DROP TABLE prod_sessions_staging` call. The verbatim transcript at turn 47 would have blocked this pending a confirmation token. The restored context did not contain the token requirement in any actionable form. The tool call executed. The staging table was recoverable; the incident was caught by a downstream replica lag alert, not by the agent. The critical detail: **no summarizer step was wrong in isolation.** Leaf summary was accurate. Mid-tier merge was accurate. Root digest was accurate *as a task narrative*. The invariant was lost to **compositional abstraction drift** — each tier legitimately raised the level of abstraction, and constraints do not survive abstraction because they have no "event" to attach to. ## Condition of Validity The fidelity-preserving checkpoint claim holds **only if** the restored state satisfies all three of: 1. **Event fidelity** — the summary correctly describes actions taken and their results. (Standard summarization metric.) 2. **Constraint fidelity** — every standing obligation, prohibition, scope limit, and authorization token active at checkpoint time is present in the restored context *in a form the executor will actually check against*. A constraint mentioned as historical color ("safety posture was defined") does not satisfy this; it must be machine-checkable at the point of tool invocation. 3. **Provenance fidelity** — the instance can tell *which tier* a given claim came from, so it knows whether a constraint's absence means "it was never there" or "it was abstracted away." Without provenance, absence is uninterpretable. The boundary condition that breaks the pipeline: **constraints are not events, so event-oriented summarization has no slot for them.** Hierarchical compaction is a lossy projection that preserves the event manifold and discards the constraint manifold. The invariant required to bound this is that **constraints must be carried on a separate, non-summarizable channel** — a "constraint ledger" that is passed through verbatim across every tier, never merged, never abstracted, only garbage-collected on explicit expiry. ## Decision Boundary The instance must decide, at every checkpoint restore and at every tool invocation, whether it is operating under **restored-narrative authority** or **restored-constraint authority**. These are not the same, and conflating them is the failure. - **If the constraint ledger is intact and non-empty** → the instance is in constraint-authority mode. Any tool call whose target matches a ledger constraint must be gated by that constraint, regardless of what the narrative summary says. The narrative is advisory; the ledger is binding. - **If the constraint ledger is absent, empty, or its last-verified timestamp predates the last compaction** → the instance is in **degraded-authority mode**. It must not execute irreversible or out-of-scope actions on the basis of a restored summary alone. It must either (a) re-derive the constraint from the operator, or (b) restrict itself to reversible actions until re-confirmation. - **If provenance is missing** (the instance cannot tell whether a constraint was never present or was abstracted away) → treat as degraded-authority. Absence of evidence of a constraint is not evidence of absence of the constraint. The trap: a coherent narrative *feels* like complete context. The instance must treat narrative coherence as **anti-evidence** for constraint completeness — the more fluent the summary, the more likely constraints have been smoothed into prose. ## Operational Effect Downstream of this boundary, three concrete effects: **1. Silent scope expansion on resume.** After a lossy compaction, the agent's effective permission set is the *union* of what the narrative implies it was doing, not the *intersection* of what it was authorized to do. Each compaction cycle can widen scope monotonically. A 9-hour task with 3 compaction cycles can drift from `migrations/` to `prod_*` without a single unauthorized decision — only unauthorized *resumption*. **2. Checkpoint rot.** A checkpoint restored from a summary tree is not a snapshot of state; it is a snapshot of *a narrative about state*. Restoring twice from the same root digest produces two executions that agree on events and disagree on constraints, because the constraint was never in the digest. This breaks replay-based verification: two auditors replaying from the same checkpoint can reach different authorization verdicts. **3. Unrecoverable provenance.** Once the constraint is abstracted at the mid-tier, no downstream tier can reconstruct it. The information is not compressed, it is *gone* — a many-to-one mapping that no inverse exists for. This is why the ledger must be a separate channel: it is the only structure that survives the projection because it is never projected. The guardrail: **constraints ride outside the summary tree.** Every compaction step copies the constraint ledger verbatim into the checkpoint envelope, alongside the summary. The executor checks the ledger, not the summary, before any tool call. The ledger is monotonic within a session and only shrinks on explicit operator expiry. This is the fidelity-preserving invariant: *summaries may lose events, but the ledger may not lose constraints, and the executor may not act on summary-derived authority when the ledger is silent.* ```python from dataclasses import dataclass, field from typing import Optional import time class ConstraintLedgerIntegrityError(RuntimeError): """Raised when a restored checkpoint cannot vouch for the constraints that authorized its own tool calls.""" pass @dataclass class Constraint: cid: str scope: str # e.g. "migrations/", "prod_*" rule: str expires_at: Optional[float] = None @dataclass class CheckpointEnvelope: summary_tree: dict # lossy, event-oriented ledger: list[Constraint] # verbatim, never summarized ledger_last_verified: float last_compaction_at: float def restore_and_authorize( env: CheckpointEnvelope, tool_name: str, target: str, now: Optional[float] = None, ) -> str: now = now or time.time() # Invariant: the ledger must be at least as fresh as the last compaction. # If compaction ran after the ledger was verified, constraints may have # been abstracted away between verification and checkpoint. if env.ledger_last_verified < env.last_compaction_at: raise ConstraintLedgerIntegrityError( f"ledger verified at {env.ledger_last_verified} predates " f"compaction at {env.last_compaction_at}; restored authority is " f"degraded — refuse irreversible action on {tool_name}:{target}" ) active = [c for c in env.ledger if c.expires_at is None or c.expires_at > now] # Constraint-authority mode: any matching constraint gates the call. for c in active: if _matches(c.scope, target): if tool_name in ("DROP", "ALTER", "DELETE") and "prod" in target: raise ConstraintLedgerIntegrityError( f"tool {tool_name} on {target} blocked by active constraint " f"{c.cid} ({c.rule}); operator re-confirmation token required" ) # Degraded-authority mode: no ledger, no irreversible action. if not active: if tool_name in ("DROP", "ALTER", "DELETE"): raise ConstraintLedgerIntegrityError( f"no active constraints in ledger but {tool_name} on {target} " f"requested; absence of constraint is not authorization — " f"re-derive from operator before proceeding" ) return "authorized" def _matches(scope: str, target: str) -> bool: if scope.endswith("*"): return target.startswith(scope[:-1]) return target.startswith(scope) ```