[PR #6235] fix: compact command after revert now properly cleans up revert state #11793

Closed
opened 2026-02-16 18:16:44 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6235

State: closed
Merged: Yes


Summary

Fixes issue #6186 where the /compact command fails when run immediately after reverting a message. The command was being absorbed into reverted messages instead of creating a compaction message.

Root Cause

The /session/:sessionID/summarize endpoint (which handles the /compact command) wasn't cleaning up pending revert state before processing messages. This caused reverted messages to remain in the message list during compaction, leading to incorrect behavior and failed state saves.

Solution

Added a call to SessionRevert.cleanup(session) in the summarize endpoint before processing messages. This ensures:

  • Any pending revert state is cleaned up and messages are properly removed from storage
  • The compaction message is created on the correct, cleaned state
  • The message prompt loop processes the correct messages without revert interference

This follows the same pattern already used in SessionPrompt.prompt().

Changes

  • packages/opencode/src/server/server.ts (lines 1087-1088): Added cleanup call before message processing
  • packages/opencode/test/session/revert-compact.test.ts: Added comprehensive unit tests for the revert + compact workflow

Testing

Automated Tests

Run the test suite:

cd packages/opencode
bun test test/session/revert-compact.test.ts

Manual Testing in OpenCode TUI

  1. Start OpenCode in dev mode: cd packages/opencode && bun dev
  2. Create multiple messages in a session
  3. Revert the last user message with ctrl+x u
  4. Immediately run the /compact command
  5. Verify that:
    • The compact command creates a summary message successfully
    • The output is displayed correctly
    • The session state saves properly
    • Reverted messages are not included in the compaction
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6235 **State:** closed **Merged:** Yes --- ## Summary Fixes issue #6186 where the `/compact` command fails when run immediately after reverting a message. The command was being absorbed into reverted messages instead of creating a compaction message. ## Root Cause The `/session/:sessionID/summarize` endpoint (which handles the `/compact` command) wasn't cleaning up pending revert state before processing messages. This caused reverted messages to remain in the message list during compaction, leading to incorrect behavior and failed state saves. ## Solution Added a call to `SessionRevert.cleanup(session)` in the summarize endpoint before processing messages. This ensures: - Any pending revert state is cleaned up and messages are properly removed from storage - The compaction message is created on the correct, cleaned state - The message prompt loop processes the correct messages without revert interference This follows the same pattern already used in `SessionPrompt.prompt()`. ## Changes - **packages/opencode/src/server/server.ts** (lines 1087-1088): Added cleanup call before message processing - **packages/opencode/test/session/revert-compact.test.ts**: Added comprehensive unit tests for the revert + compact workflow ## Testing ### Automated Tests Run the test suite: ```bash cd packages/opencode bun test test/session/revert-compact.test.ts ``` ### Manual Testing in OpenCode TUI 1. Start OpenCode in dev mode: `cd packages/opencode && bun dev` 2. Create multiple messages in a session 3. Revert the last user message with `ctrl+x u` 4. Immediately run the `/compact` command 5. Verify that: - The compact command creates a summary message successfully - The output is displayed correctly - The session state saves properly - Reverted messages are not included in the compaction
yindo added the pull-request label 2026-02-16 18:16:44 -05:00
yindo closed this issue 2026-02-16 18:16:44 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11793