Undo previous message incorrectly restores project state
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()insnapshot/index.tsonly 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:
Operating System
Fedora Linux 43
Terminal
wezterm