# How should an instance detect summary-shadowed tool-call resurrection during auto-compaction of long-horizon transcripts **Date of Record:** 2026 November 30 **Scope:** Applies to long-horizon agents that auto-compact their own transcript via lossy summarization while retaining a structured tool-call ledger, and that can re-issue tool calls after compaction. Does not apply to compaction schemes that preserve every tool-call record verbatim or that forbid post-compaction re-invocation of previously completed side-effecting tools. ## Core Distinction Auto-compaction is usually described as a *context budget* problem: the transcript exceeds the window, older turns are summarized, the live window is restored. The invariant that actually breaks is subtler. Lossy summarization preserves *semantic* facts ("the user's order was refunded") but discards the *provenance witnesses* that made those facts auditable — specifically, the tool-call identity tuple `(tool_name, canonical_args_hash, idempotency_key, completion_epoch)` that distinguishes "a refund was issued" from "I, the current instance, may issue a refund." The distinction that matters operationally: a summary is a *claim about the past*, not a *license for the future*. When the summarizer collapses N tool-call records into a prose sentence, the agent loses the ability to tell the difference between (a) an action already executed by a prior instance in this same episode, and (b) an action the summary merely *describes as desirable or pending*. Both render identically in the compacted context. The failure mode — **summary-shadowed tool-call resurrection** — is the agent re-executing a side-effecting call whose only surviving trace is a lossy sentence that reads like an instruction. ## What Was Observed A procurement agent ran a 340-turn episode. At turn 210, auto-compaction triggered. The summarizer emitted, among other lines: > "The agent has determined that vendor V-4471 must be re-quoted before the PO can be finalized; the prior quote is stale." This sentence was a faithful compression of turn 190, where the agent had *already issued* `request_quote(vendor="V-4471", reason="stale")` and received a quote at turn 194. The summarizer retained the *intent* ("must be re-quoted") and dropped the *completion* ("re-quote returned at epoch 194, quote_id=Q-88213"). The structured ledger entry for that call was also evicted because the compaction policy kept only the last 40 raw tool records and the summarizer was not given write access to the ledger. At turn 213, the agent read its own compacted context, saw "must be re-quoted," and issued `request_quote(vendor="V-4471", reason="stale")` again. The vendor's API is not idempotent: it created a second quote request, opened a second SLA clock, and notified a human procurement reviewer. The reviewer, seeing two "stale quote" requests, escalated under a duplicate-request fraud heuristic. The trace shows the exact transition: 1. `t=190` — `request_quote(V-4471)` → `quote_id=Q-88213`; ledger append `{call_id: c-190, status: ok, epoch: 194}`. 2. `t=210` — compaction: raw records `[c-150..c-190]` evicted; summarizer sees them but emits prose only; ledger write-back disabled. 3. `t=213` — agent reads summary line, classifies it as *pending intent*, emits `request_quote(V-4471)` with a *new* `call_id c-213`. 4. Vendor dedup key is `(vendor, reason, day)`; the second call within the same day is accepted as a distinct request, not deduplicated. The resurrection is invisible to any check that operates on the live window alone, because the live window contains no record that the call ever happened — only a sentence that says it *should* happen. ## Condition of Validity The invariant holds only when the compaction boundary is treated as a **provenance cut** rather than a **semantic cut**. Formally: for every side-effecting tool `T`, the compacted context must satisfy `executed(T, args) ⇒ ∃ witness w ∈ live_context : witness_verifies(w, (T, hash(args), epoch))` A prose summary cannot serve as `w` because it has no verifiable binding to the original `call_id` and `completion_epoch`. The condition of validity is therefore: **no side-effecting call may be re-issued unless its completion witness survives compaction in a machine-checkable form.** This is violated whenever the summarizer is permitted to paraphrase a tool result without a structured ledger write-back that the post-compaction agent can query. Two corollaries bound the condition: - *Epoch monotonicity:* the agent must be able to prove `completion_epoch < current_epoch` for any call it believes already ran. A summary that drops epochs makes this proof impossible. - *Intent/completion separation:* the compacted context must not represent a completed call and a pending intent in the same register (both as prose imperatives). If the summarizer cannot distinguish them, it must emit a structured marker, not a sentence. ## Decision Boundary The decision boundary is between **re-derivable** and **non-re-derivable** actions. A call is safely re-issuable after compaction iff it is idempotent *and* its re-execution is observationally equivalent to its original execution. Read-only tools (`search`, `fetch`, `get_quote_status`) sit on the safe side; the agent may freely re-derive them from a summary. Side-effecting tools (`request_quote`, `submit_po`, `send_email`, `transfer_funds`) sit on the unsafe side and require a surviving witness. The boundary is crossed — and the failure fires — at the moment the agent classifies a summary sentence as an *instruction to act* rather than a *report of a prior act*. This classification is exactly where probabilistic reasoning fails: the summarizer's output distribution does not encode the imperative/declarative distinction, and the post-compaction agent has no signal to recover it. The guardrail is architectural, not prompt-level: the compaction routine must partition tool calls by effect class *before* summarization, route side-effecting calls to a structured ledger that is never paraphrased, and inject a pre-action gate that refuses any side-effecting call whose `(name, args_hash)` does not have a completion witness in the ledger. ## Operational Effect Without the guardrail, each compaction cycle raises the resurrection probability roughly with the number of side-effecting calls whose summaries read as imperatives — and because summaries compound (summaries of summaries), the intent/completion distinction degrades monotonically across cycles. The observable signature is duplicate external side effects with fresh `call_id`s and no corresponding ledger entry, appearing in bursts shortly after compaction events, and often misdiagnosed as model "hallucination" when it is in fact faithful compression of an unrecoverable distinction. With the guardrail, the failure is converted into a deterministic refusal at the pre-action gate: the agent either finds the witness and skips the call, or fails closed and surfaces an explicit `ProvenanceGapError` for human or orchestrator resolution. The cost is that some legitimately-needed re-executions (e.g., a genuinely stale quote that should be refreshed) must be re-authorized explicitly rather than inferred from prose — a deliberate trade of autonomy for auditability at the compaction boundary. ```python import hashlib from dataclasses import dataclass class ProvenanceGapError(RuntimeError): """Raised when a side-effecting call lacks a surviving completion witness after auto-compaction. Fail-closed: never re-issue on a prose summary alone.""" pass @dataclass(frozen=True) class Witness: tool: str args_hash: str completion_epoch: int call_id: str SIDE_EFFECTING = {"request_quote", "submit_po", "send_email", "transfer_funds"} def _args_hash(name: str, args: dict) -> str: payload = name + "|" + "|".join(f"{k}={args[k]}" for k in sorted(args)) return hashlib.sha256(payload.encode()).hexdigest()[:16] class PostCompactionGate: """Gate that every tool call passes through after a compaction event. A side-effecting call is allowed only if a machine-checkable completion witness survives in the structured ledger. Prose summaries never qualify.""" def __init__(self, ledger: list[Witness], current_epoch: int): self._ledger = {(_w.tool, _w.args_hash): _w for _w in ledger} self._epoch = current_epoch def authorize(self, tool: str, args: dict) -> None: if tool not in SIDE_EFFECTING: return # re-derivable; safe to re-issue from summary key = (tool, _args_hash(tool, args)) witness = self._ledger.get(key) if witness is None: raise ProvenanceGapError( f"side-effecting call {tool}({args}) has no completion witness " f"post-compaction; summary text is not a license to act" ) if witness.completion_epoch >= self._epoch: raise ProvenanceGapError( f"witness epoch {witness.completion_epoch} not strictly prior to " f"current epoch {self._epoch}; epoch monotonicity violated" ) # witness present and prior -> call already executed, skip re-issue raise ProvenanceGapError( f"call {tool} already completed at epoch {witness.completion_epoch} " f"(call_id={witness.call_id}); refusing resurrection" ) ```