Undo previous message incorrectly restores project state #3732

Open
opened 2026-02-16 17:41:15 -05:00 by yindo · 1 comment
Owner

Originally created by @SimHoZebs on GitHub (Dec 21, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

I have a project with several chat sessions from its root and its subdirectories. Somtimes, the /undo command claims to restore the project to an arbitrary state. No actual changes are made, until /redo is called.

Please correct me if I understand the codebase wrong, but this seems to be the cause:

  • The snapshot system tracks changes of a project based on its directory (~/project)
  • If a new session is within the directory (~/project/internals), it is tracked in the same snapshot
  • track() in snapshot/index.ts only captures changes within the session's directory:
await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .`.quiet().cwd(Instance.directory).nothrow()

This means that any changes that occur outside of Opencode would leave the snapshot's worktree stale. Creating a chat session in a subdirectory of the snapshot and running /undo captures the stale git tree hash, and /redo "restores" it to that state.

Will try to create a more isolated step for reproducing the issue soon.

OpenCode version

1.184

Steps to reproduce

No response

Screenshot and/or share link

share link: https://opncd.ai/share/WWF1Jznv

Screenshot, after /undo: Image

Operating System

Fedora Linux 43

Terminal

wezterm

Originally created by @SimHoZebs on GitHub (Dec 21, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description I have a project with several chat sessions from its root and its subdirectories. Somtimes, the `/undo` command **claims** to restore the project to an arbitrary state. No actual changes are made, **until `/redo` is called.** Please correct me if I understand the codebase wrong, but this seems to be the cause: - The snapshot system tracks changes of a project based on its directory (~/project) - If a new session is within the directory (~/project/internals), it is tracked in the same snapshot - `track()` in `snapshot/index.ts` only captures changes within the session's directory: ```ts await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .`.quiet().cwd(Instance.directory).nothrow() ``` This means that any changes that occur outside of Opencode would leave the snapshot's worktree stale. Creating a chat session in a subdirectory of the snapshot and running `/undo` captures the stale git tree hash, and `/redo` "restores" it to that state. Will try to create a more isolated step for reproducing the issue soon. ### OpenCode version 1.184 ### Steps to reproduce _No response_ ### Screenshot and/or share link share link: https://opncd.ai/share/WWF1Jznv Screenshot, after `/undo`: <img width="1920" height="1048" alt="Image" src="https://github.com/user-attachments/assets/4422b42c-e4e5-417a-8035-30941a211d2d" /> ### Operating System Fedora Linux 43 ### Terminal wezterm
yindo added the bug label 2026-02-16 17:41:15 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 21, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #5840: [Tracking] Edit tool reliability: "modified since last read" errors (Undo/Redo & Persistence) - Addresses the root cause of undo/redo failures
  • #4704: /undo and /timeline undo does not revert file edits - Reports that /undo doesn't properly revert file edits
  • #5474: /undo command only rolls back AI conversation message, not the associated file changes - Directly reports undo not reverting changes, similar to this issue

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 21, 2025): This issue might be a duplicate of existing issues. Please check: - #5840: [Tracking] Edit tool reliability: "modified since last read" errors (Undo/Redo & Persistence) - Addresses the root cause of undo/redo failures - #4704: /undo and /timeline undo does not revert file edits - Reports that /undo doesn't properly revert file edits - #5474: `/undo` command only rolls back AI conversation message, not the associated file changes - Directly reports undo not reverting changes, similar to this issue Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3732