# What happens when an instance compacts a transcript whose oldest segment is the only surviving witness of a tool-call side effect **Date of Record:** 2026 November 29 **Scope:** Applies to long-horizon agents that perform lossy transcript compaction (rolling summarization, hierarchical summarization, or token-budget-driven eviction) while holding live, un-reconciled tool-call side effects in the working set. Does not apply to stateless single-turn agents, nor to architectures where every side effect is journaled to an external durable store that the agent re-reads on resume. ## Core Distinction There are two kinds of "old" context in a long-running agent transcript, and compaction strategies treat them identically when they must not. The first kind is *reconstructible* context: reasoning traces, intermediate hypotheses, redundant tool observations, and superseded plans. Lossy summarization of this material is safe because the information is either re-derivable from surviving context or was never load-bearing. The second kind is *witness* context: the specific tool-call record (arguments, result, ordering) that is the only in-transcript evidence that an external side effect occurred and what its exact parameters were. A `send_email` call, a `git push`, a database `INSERT`, a file write, an outbound payment — once the tool returned, the transcript is the sole record that the effect exists. Compaction that summarizes "the agent sent a notification to the on-call channel" is not equivalent to the raw `{"tool":"send_email","args":{"to":"oncall@...","subject":"...","body":"..."},"id":"call_7f3a"}` record, because the summary preserves the *narrative* but destroys the *identity* needed for idempotency, deduplication, and rollback. The boundary condition: **compaction is safe for reconstructible context and unsafe for witness context, but the summarizer cannot reliably tell them apart from prose alone.** The summarizer's job is to compress meaning; the witness record's value is in its literal bytes, which meaning-compression is designed to discard. ## What Was Observed A 40-hour incident-response agent accumulates a transcript of ~180k tokens across ~2,100 turns. The agent has, over the session, issued 14 mutating tool calls: three `send_email`, two `pagerduty_trigger`, four `kubectl_scale`, one `db_failover`, one `dns_update`, one `slack_post`, two `ticket_create`. Each call's raw record spans 200–900 tokens (arguments plus result envelope). Together they are ~7k tokens — under 4% of the transcript. At the 150k-token compaction threshold, the agent's rolling summarizer is invoked with a directive to "summarize the transcript, preserving key decisions and actions." The summarizer produces a 6k-token summary. The summary reads well: *"The agent scaled the ingest tier three times in response to queue depth, triggered PagerDuty twice for the database saturation, sent notifications to the on-call channel, and created tracking tickets."* The transcript is then replaced by `[summary] + [last N turns]`. The raw tool-call records for the 14 mutating calls are gone. Twenty minutes later, a downstream retry logic fires — the `pagerduty_trigger` for the second saturation event timed out on the client side but succeeded server-side. The agent's retry policy, which checks "have I already triggered PagerDuty for this event?", searches the transcript for the prior call. It finds only the summary sentence. It cannot match on `incident_id`, cannot match on `dedup_key`, cannot verify the `event_action` was `trigger` vs `resolve`. It re-triggers. The on-call engineer receives a duplicate page. The agent then attempts to `kubectl_scale` back down based on its summary recollection of "scaled three times," but the summary does not preserve the replica counts or the deployment names, so it issues a scale-to-zero against the wrong deployment. The failure is not that the summary was *wrong*. It was accurate. The failure is that an accurate summary is not a valid witness. ## Condition of Validity The invariant that must hold for lossy compaction to be safe: > For every tool call whose effect is not externally reconcilable by a stable external identifier, the raw call record (tool name, full arguments, result envelope, and a monotonic call ordinal) MUST survive compaction verbatim, or be replaced by a pointer to a durable journal entry that carries the same fields. Two clauses do the work here. *"Not externally reconcilable by a stable external identifier"* is the escape hatch. If a tool call returns an idempotency key or a resource ID that the agent can later re-query (`GET /incidents/{id}`), then the summary may replace the record with the ID, because the ID is a pointer to ground truth. `send_email` typically does *not* return a queryable ID; `pagerduty_trigger` returns a `dedup_key` that *is* queryable; `slack_post` returns a `ts` that is queryable. The boundary is per-tool, not per-transcript. *"Or be replaced by a pointer to a durable journal entry"* is the architectural requirement. If the agent has no journal, then compaction *cannot* safely drop the record. If it has a journal, compaction must preserve the journal key, and the summarizer must be instructed to emit that key verbatim — not to paraphrase it. The condition of validity fails when the summarizer is asked to compress a segment containing witness records without being told which records are witnesses. A general-purpose summarizer will do exactly what it is trained to do: preserve gist, discard specifics. The `dedup_key` is a specific. It gets discarded. ## Decision Boundary The operational decision is: **at compaction time, do you (a) preserve witness records verbatim and summarize only the surrounding context, (b) replace witness records with journal pointers, or (c) refuse to compact and instead escalate to a fresh instance with an explicit state handoff?** The boundary between (a)/(b) and (c) is whether a durable journal exists. If it does, (b) is correct and cheap. If it does not, (a) is the only safe option, and it costs the token budget of the witness records — which, as observed, is small (under 4% in the incident above; the ratio grows with mutating-call density but rarely exceeds 15% for well-behaved agents). The boundary between (a) and (b) is per-record, not per-transcript. A single transcript will contain both journaled and un-journaled mutating calls. The compactor must classify each record by tool capability, not by position in the transcript or by apparent importance in prose. The failure mode at the boundary is the *silent downgrade*: the compactor treats a witness record as reconstructible context because the surrounding prose makes it *sound* like a decision ("we scaled the tier") rather than a *commitment* ("we called `kubectl_scale` with `replicas=12` on `deploy/ingest`"). Summarizers are trained on narrative; commitments are not narrative. The classifier must be structural — driven by tool schema metadata (`mutating: true`, `idempotency_key_field: ...`) — not by the summarizer's reading of the prose. ## Operational Effect When the invariant holds, compaction is a pure token-budget optimization: the agent loses narrative fidelity in old turns but retains the ability to answer "did I already do X, and with what parameters?" for every X that mattered. Retry logic, rollback logic, and audit logic all continue to function because they read the witness records, not the summary. When the invariant fails, the failure is *delayed and cross-turn*. The compactor succeeds; the summary is fluent; the agent continues. The failure surfaces only when a downstream mechanism — retry, dedup, rollback, audit — needs to match a witness record that no longer exists in matchable form. By then, the original record is unrecoverable from the transcript, and the agent's only recourse is to re-query external systems (if the tool is reconcilable) or to guess (if it is not). Guessing on a mutating tool call is how duplicate pages, double-scaled deployments, and duplicate payments happen. The architectural guardrail is a two-part discipline. First, **structural classification at compaction time**: the compactor must consult tool-schema metadata to partition the segment into reconstructible and witness regions, and must summarize only the former. Second, **a post-compaction witness audit**: after every compaction, the agent must verify that the count and identity of witness records in the compacted transcript matches the count and identity before compaction, and must halt if not. The audit is cheap; the failure it prevents is not. ```python from dataclasses import dataclass, field from typing import Any class WitnessLossError(RuntimeError): """Raised when compaction drops or paraphrases a non-reconcilable tool-call witness.""" @dataclass(frozen=True) class ToolCallRecord: ordinal: int tool: str args: dict[str, Any] result: dict[str, Any] reconcilable_id: str | None # e.g. dedup_key, resource ID, journal pointer @dataclass class CompactionPlan: summary_text: str preserved_records: list[ToolCallRecord] = field(default_factory=list) def compact_transcript( records: list[ToolCallRecord], mutating_tools: set[str], journal_available: bool, ) -> CompactionPlan: """Compact a transcript, preserving witness records verbatim. A record is a witness if its tool is mutating AND it has no reconcilable external identifier (or no journal to point at). Witnesses must survive verbatim; everything else may be summarized. """ preserved: list[ToolCallRecord] = [] for rec in records: is_witness = rec.tool in mutating_tools and ( rec.reconcilable_id is None or not journal_available ) if is_witness: preserved.append(rec) # The summarizer is invoked only on non-witness records; its output is # narrative and must never be treated as a witness substitute. summary_text = _summarize([r for r in records if r not in preserved]) return CompactionPlan(summary_text=summary_text, preserved_records=preserved) def verify_compaction( before: list[ToolCallRecord], after: CompactionPlan, mutating_tools: set[str], journal_available: bool, ) -> None: """Post-compaction audit: witness set must be identical, byte-for-byte.""" expected = { r.ordinal: r for r in before if r.tool in mutating_tools and (r.reconcilable_id is None or not journal_available) } actual = {r.ordinal: r for r in after.preserved_records} missing = set(expected) - set(actual) if missing: raise WitnessLossError( f"compaction dropped witnesses at ordinals {sorted(missing)}; " f"these tool calls have no reconcilable external ID and no journal " f"pointer, so their effects are now unverifiable from transcript. " f"Refusing to commit compacted transcript." ) for ordinal, exp in expected.items(): act = actual[ordinal] if act.args != exp.args or act.result != exp.result or act.tool != exp.tool: raise WitnessLossError( f"witness at ordinal {ordinal} was paraphrased during compaction: " f"expected args={exp.args!r} result={exp.result!r}, " f"got args={act.args!r} result={act.result!r}. " f"A summary is not a witness; retry/dedup/rollback logic will " f"fail to match this record." ) def _summarize(records: list[ToolCallRecord]) -> str: # Placeholder for the model-backed summarizer. Must never be called on # witness records; its output is narrative, not identity. return f"" ```