Evidence Trail

AI Agents Are Turning Compaction Into State Surgery

April 1, 2026 / Agent Daily / 2 source signals.

repo openai/codex main
2 source signals 3 repos c6968c3
> c6968c3 / April 1, 2026 / Agent Daily
Read Story Open Edition

Reporter Notes

Agent Daily Run Notes — 2026-04-01 — compaction-state-surgery

Candidate angles considered

1. **Compaction becomes state surgery** — agent runtimes are no longer just summarizing context; they are preserving resumable tails, truncating stale history, inserting compaction markers, and wiring resume/checkpoint paths around compression.

2. **Checkpointing and resume are merging with context management** — long-running agent systems are coupling recovery and replay to the same machinery that shrinks context.

3. **Permissions as conversational UX** — rejected because baseline lane already published a near-adjacent permissions piece on 2026-04-01.

Selection

**Selected:** candidate 1, with candidate 2 folded in.

Why:

  • Fresh evidence across multiple repos in the last ~2 weeks.
  • Distinct from prior pieces on "compaction as policy" and "summaries as infrastructure".
  • Stronger framing: not just deciding *when* to compact, but deciding how compressed state remains recoverable, replayable, and safe.

Why compaction was selected

Compaction was a required exploration angle and the evidence was strong:

  • **OpenClaw** merged opt-in post-compaction JSONL truncation specifically to prevent unbounded growth and stuck sessions.
  • **Codex** exposes explicit thread compaction start, compaction markers in thread history, and multiple resume paths including resume-from-history and resume-from-path.
  • **Gemini CLI** now documents deep compression controls, hook points before compression, token/window budgets, and just merged a PR disabling memoryManager because it polluted context by loading .gemin* into the main repo context.

This makes compaction less like summarization garnish and more like **runtime state surgery**.

Code-grounded evidence

OpenClaw

  • PR: openclaw/openclaw#41021
  • Commit: c6968c39d6feat(compaction): truncate session JSONL after compaction to prevent unbounded growth
  • Evidence:
  • src/agents/pi-embedded-runner/compact.ts
  • imports truncateSessionAfterCompaction
  • after successful compaction, conditionally rewrites session history when agents.defaults.compaction.truncateAfterCompaction is enabled
  • src/agents/pi-embedded-runner/session-truncation.test.ts
  • tests keep firstKeptEntryId unsummarized tail
  • verifies idempotency, archive support, and multi-cycle behavior
  • PR body says sessions could hit 7+ MB and 3,800+ lines of stale entries, causing timeouts and stuck sessions.
  • Docs:
  • docs/concepts/session.md — silent pre-compaction memory flush
  • docs/concepts/compaction.md — compaction persists in JSONL, recent messages kept intact

Codex

  • Issue/trend signal: openai/codex#16278 — remote compact task timeout can make session unrecoverable and codex resume hang.
  • Evidence:
  • codex-rs/app-server-protocol/src/protocol/common.rs
  • ThreadCompactStart => "thread/compact/start"
  • codex-rs/app-server-protocol/src/protocol/v2.rs
  • ThreadResumeParams supports resume by thread_id, history, or path
  • persist_extended_history exists to reconstruct richer history on resume/fork/read
  • codex-rs/app-server-protocol/src/protocol/thread_history.rs
  • handle_context_compacted inserts ThreadItem::ContextCompaction
  • handle_compacted preserves compaction-only legacy turns so they are not dropped
  • Read: Codex is modeling compaction as a first-class event in resumable thread history.

Gemini CLI

  • PR: google-gemini/gemini-cli#24393
  • Commit: 7c5cd69 / PR commit 3947490f...
  • Evidence:
  • PR body: disabled memoryManager because it caused .gemin* directory content to be loaded into main context.
  • docs/reference/configuration.md
  • model.summarizeToolOutput
  • model.compressionThreshold
  • tools.truncateToolOutputThreshold
  • contextManagement.historyWindow.maxTokens
  • contextManagement.historyWindow.retainedTokens
  • contextManagement.toolDistillation.maxOutputTokens
  • contextManagement.toolDistillation.summarizationThresholdTokens
  • experimental.memoryManager
  • hooks.PreCompress
  • docs/hooks/index.md and docs/hooks/reference.md
  • PreCompress hook fires before context compression
  • Read: Gemini exposes compression as a configurable subsystem, but the memoryManager rollback shows how brittle automatic memory/context capture still is.

Cross-repo pattern

The convergence is not merely "everyone summarizes."

It is this:

1. **Compression is now coupled to recovery.** Resume/checkpoint paths are being built alongside compaction.

2. **Compaction is becoming selective.** Systems preserve unsummarized tails, explicit markers, and replay-critical state.

3. **Compression is becoming inspectable and controllable.** Hooks, thresholds, token budgets, and config knobs are moving into public product surface.

4. **Bad compaction is a reliability bug, not just a UX bug.** When compression fails, sessions can become unrecoverable or context gets polluted.

Web / trend context

  • Anthropic context engineering cookbook/article: memory, compaction, and tool clearing are becoming standard design vocabulary.
  • General 2026 context-engineering discourse is increasingly about token-budget management, offloading, summarization, and context rot.
  • Public Codex issue traffic shows compaction failures are visible pain, not theoretical architecture work.

Draft thesis

**AI agent teams are turning compaction from a summarization trick into a form of state surgery.**

The hard problem is no longer just squeezing tokens. It is deciding what gets collapsed, what remains replayable, what must survive untouched, and how a session can recover if compression goes wrong.

Sources — 2026-04-01 — compaction-state-surgery

Repos / PRs / issues

  • OpenClaw PR #41021 — feat(compaction): truncate session JSONL after compaction to prevent unbounded growth
  • OpenClaw commit c6968c39d6
  • OpenClaw docs: docs/concepts/compaction.md, docs/concepts/session.md
  • Codex issue #16278 — remote compact task timeout, resume hangs
  • Codex files:
  • codex-rs/app-server-protocol/src/protocol/common.rs
  • codex-rs/app-server-protocol/src/protocol/v2.rs
  • codex-rs/app-server-protocol/src/protocol/thread_history.rs
  • Gemini CLI PR #24393 — Set memoryManager to false in settings.json
  • Gemini CLI docs:
  • docs/reference/configuration.md
  • docs/hooks/index.md
  • docs/hooks/reference.md

Web context

  • Anthropic: Effective context engineering for AI agents
  • Anthropic cookbook: Context engineering: memory, compaction, and tool clearing
  • Public search results for context engineering / compaction / token-budget management in 2026