Skip to content

[FEATURE][URGENT]: undo/restore compaction + finer undo granularity — compaction is a one-way door #54294

Open

Description

@Quantum-Quasar

Summary

Compaction destroys the details a session is built on, and there is no way to undo it or to undo individual steps. A session carrying ~244,000 tokens of exact constraints, debugging state and 300–400 tool calls can be compacted into ~2,000 tokens of vague prose that drops every boundary, constraint and step the user issued — and once compacted, the work is gone: undoing the compaction itself is impossible, and forking before the compaction point re-imports all 300+ tool calls without the detail that made them usable.

Two requests:

  1. Undo granularity — currently a revert/undo point is tied to a user prompt. A single prompt can trigger 300+ tool calls and hundreds of file edits, and the user has no way to step back three tool calls or three file edits while keeping the rest.
  2. Undo compaction — there is no way to restore the pre-compaction history. /compact is one-way, and the compaction summary is shown as if it were the new state with no restore path.

This combination makes compaction a one-way door: after a heavy session is compacted the session is effectively unusable and unrecoverable without starting over.

Environment

  • opencode version: 2.0.26
  • OS: Linux 6.18.55-1-lts x86_64 GNU/Linux
  • Terminal: xterm-256color (COLORTERM=truecolor, TERM_PROGRAM unset)
  • Shell: /bin/bash
  • Install/channel: latest
  • Active plugins: none found in config
  • Related session: ses_edd90d634ffe1MTsEt6p5Tlbel (project german-app-thinking-method), ~2.66M input tokens and ~339 compaction-era messages before the destructive compaction; forks ses_edad1b600ffeA2ugmIegQBxzAE, ses_edad25875ffeQ1jEj5bPSrCjdQ

Reproduction

  1. Run a long session where one prompt drives ~300–400 tool calls and hundreds of file edits, under explicit user constraints (boundaries, "don't do X" instructions, style rules).
  2. Request a manual /compact.
  3. Inspect the resulting summary: exact constraints, paths, error strings, versions, debugging state ("tested X, ruled out because Y") and most of the tool-call record are reduced to vague prose.
  4. Attempt to undo:
    • Undo the compaction — no such operation exists.
    • Revert to an earlier point — the only unit is a user prompt, so reverting drops the entire prompt's worth of work, and forking from a pre-compaction point re-imports all 300+ tool calls without the detail that made them usable.

Expected Behavior

  • Compaction should carry forward every user-stated constraint, boundary, style instruction, exact identifier/path/value/version/error string, and the investigation state, verbatim where possible — not generalized prose.
  • /compact should be reversible: restore the pre-compaction history, or at minimum keep it retrievable (e.g. /compact --undo, or a compaction checkpoint that can be reverted like a message revert).
  • Undo should be finer-grained than a prompt: stepping back N tool calls / N file edits while keeping the surrounding work.

Actual Behavior

  • The compaction summary loses: all user-imposed constraints and boundaries, most exact technical details (paths, flag names, config keys, error strings, versions), the debugging state (what was tried, what was ruled out, with what evidence), and the granular tool-call record. The post-compaction session "forgets" the constraints and repeats questions already answered.
  • No undo of the compaction itself. No restore of pre-compaction history.
  • Undo/revert granularity is one user prompt. A prompt that caused 300+ tool calls cannot be partially reverted.

Additional Context

Suggested fix

  • In the default compaction prompt: instruct the summarizer to never generalize names/paths/values/error strings/versions, reproduce key user-pasted content verbatim, preserve all user constraints and preferences, and preserve investigation state (tried / ruled out / evidence).
  • Persist the pre-compaction message set as a restorable checkpoint (like the existing snapshot/revert machinery) and expose compact-restore in the TUI.
  • Make undo step through tool calls / file edits (mutation epochs, per v2: redesign filesystem snapshots around mutation epochs #44511) instead of prompt boundaries.

Activity

  1. opencode-agent commented on Oct 10, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed write-up! To restate: you'd like a way out of compaction. That means undoing or restoring a completed /compact and its pre-compaction history, undo that can step back individual tool calls or file edits instead of a whole prompt, and a default compaction prompt that keeps constraints and exact details word for word. Maintainers will consider this.

    Related issues:

    The undo parts can't be built as a plugin right now, because plugins have no access to session history, revert points or snapshots.

  2. changed the title [-][FEATURE]: undo compaction restore pre-compaction history + finer undo granularity[/-] [+][FEATURE][URGENT]: undo/restore compaction + finer undo granularity — compaction is a one-way door[/+] on Oct 10, 2026
  3. samvallad33 commented on Oct 23, 2026

    @samvallad33

    Hi Shaurya,

    Which constraint hurt most to lose when 244k tokens shrank to 2k?

    Exact boundaries should resurface when the next edit touches them, not dissolve into prose. Open to a quick demo of a small memory setup that keeps rules and debugging history recallable?

    Sam

  4. ngPati commented on Oct 27, 2026

    @ngPati

    Same pain here. Until an undo exists, these keep a compaction from costing me the constraints:

    1. Turn off automatic compaction for long, constraint-heavy sessions and compact on purpose: in opencode.json set "compaction": { "auto": false }.
    2. Keep the hard constraints in a file, not in chat. AGENTS.md points to a NOTES.md that the agent updates with decisions and boundaries; a file is re-read, a chat message becomes one line of a summary.
    3. Commit (or stash) before any long step, so a bad turn after compaction is a git reset away.
    4. Smaller units of work. One task per session means a compaction rarely hits work in progress.

    Disclosure: I build VibeiDE (https://vibeide.dev), a desktop app that runs OpenCode, Codex and Claude Code tasks one session per task. A real undo for compaction would still be great.

  5. Nomadu27 commented on Oct 27, 2026

    @Nomadu27

    Agree that compaction shouldn't be one-way. Disclosure: I make Sigillion, memory for coding agents, built for exactly this kind of loss. Claude Code only today; more agent tools are planned for the end of 2026. https://github.com/Sigillion-AI/sigillion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions