[Bug]: file deleted on Undo action #2086

Closed
opened 2026-02-16 17:34:06 -05:00 by yindo · 10 comments
Owner

Originally created by @Isos9 on GitHub (Oct 13, 2025).

Originally assigned to: @thdxr on GitHub.

Hi, when I undo my last prompt, it did not undo the one-line change I had, it actually deleted the whole file, showing /dev/null in the undo summary instead of the file name.

I think it actually happened because when I did the undo, I closed the opencode instance right away, I didn't wait for it to undo it.

I also had two opencodes opened on the same session at this time, but the other I just opened it to check something quickly in full screen, no interaction with it, so that might not be relevant.

The version was 0.15.0, on Alacritty, Arch linux.

Originally created by @Isos9 on GitHub (Oct 13, 2025). Originally assigned to: @thdxr on GitHub. Hi, when I undo my last prompt, it did not undo the one-line change I had, it actually deleted the whole file, showing `/dev/null` in the undo summary instead of the file name. I think it actually happened because when I did the undo, I closed the opencode instance right away, I didn't wait for it to undo it. I also had two opencodes opened on the same session at this time, but the other I just opened it to check something quickly in full screen, no interaction with it, so that might not be relevant. The version was 0.15.0, on Alacritty, Arch linux.
yindo closed this issue 2026-02-16 17:34:06 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 13, 2025):

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

  • #2642: [bug] /undo removed the last message, but didn't revert the code edit - Similar undo functionality not working correctly
  • #2575: undo doesnt removes the context - Another undo-related issue where undo doesn't work as expected
  • #3073: Snapshot tracking does not initialize per-project git directory, prevents undo/redo and leaves no snapshot data - Related to underlying snapshot mechanism that undo depends on
  • #2379: [bug]: /undo is broken when you re-open opencode - Similar undo problems with snapshot handling

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

@github-actions[bot] commented on GitHub (Oct 13, 2025): This issue might be a duplicate of existing issues. Please check: - #2642: [bug] /undo removed the last message, but didn't revert the code edit - Similar undo functionality not working correctly - #2575: undo doesnt removes the context - Another undo-related issue where undo doesn't work as expected - #3073: Snapshot tracking does not initialize per-project git directory, prevents undo/redo and leaves no snapshot data - Related to underlying snapshot mechanism that undo depends on - #2379: [bug]: /undo is broken when you re-open opencode - Similar undo problems with snapshot handling Feel free to ignore if none of these address your specific case.
Author
Owner

@ikodbapc commented on GitHub (Oct 17, 2025):

Same thing happens to me on opencode v0.15.7 on Windows in Wezterm. After undoing few changes in session, files that were only edited (not created) in current session get all deleted. 🤨 Good that I had files backed up with Git otherwise I would lose files... This happened to me multiple times, it's important to fix this.

@ikodbapc commented on GitHub (Oct 17, 2025): Same thing happens to me on opencode v0.15.7 on Windows in Wezterm. After undoing few changes in session, files that were only edited (not created) in current session get all deleted. 🤨 Good that I had files backed up with Git otherwise I would lose files... This happened to me multiple times, it's important to fix this.
Author
Owner

@rekram1-node commented on GitHub (Oct 17, 2025):

yeah i had it happen once or twice too we will look into this

@rekram1-node commented on GitHub (Oct 17, 2025): yeah i had it happen once or twice too we will look into this
Author
Owner

@veracioux commented on GitHub (Oct 18, 2025):

I was only able to reproduce one way: When you start opencode, it deletes the whole snapshots directory (code here). When you /undo in any opencode instance (new or already running), opencode detects that the file doesn't exist in any snapshot (effectively implying the file was created from scratch by the LLM), so it deletes it (code here).

(I believe this is the exact same scenario reported by https://github.com/sst/opencode/issues/2379)

@rekram1-node I propose to remove the init function that deletes the storage directory at startup. I imagine it was added as a crude sort of garbage collection mechanism.

Bit out of scope, but I would like to propose a different strategy for git-based protection of user data:
Instead of creating snapshots, store the diffs introduced by LLM's edits. When undoing a message, OC can apply the diff on the file (with the --reverse flag). I believe this might help with issues of large snapshot sizes, which have been reported in the past. It has the added benefit of being more robust to changes made to the file by the user (i.e. reverting only the LLM's part while preserving user changes, whereas using snapshots reverts user changes as well).

@veracioux commented on GitHub (Oct 18, 2025): I was only able to reproduce one way: When you start `opencode`, it deletes the whole snapshots directory ([code here](https://github.com/veracioux/opencode/blob/335d83365521728181248b13a55386a10ae41ef0/packages/opencode/src/snapshot/index.ts#L13)). When you /undo in any opencode instance (new or already running), opencode detects that the file doesn't exist in any snapshot (effectively implying the file was created from scratch by the LLM), so it deletes it ([code here](https://github.com/veracioux/opencode/blob/335d83365521728181248b13a55386a10ae41ef0/packages/opencode/src/snapshot/index.ts#L116)). (I believe this is the exact same scenario reported by https://github.com/sst/opencode/issues/2379) @rekram1-node I propose to remove the `init` function that deletes the storage directory at startup. I imagine it was added as a crude sort of garbage collection mechanism. Bit out of scope, but I would like to propose a different strategy for git-based protection of user data: Instead of creating snapshots, store the diffs introduced by LLM's edits. When undoing a message, OC can apply the diff on the file (with the --reverse flag). I believe this might help with issues of large snapshot sizes, which have been reported in the past. It has the added benefit of being more robust to changes made to the file by the user (i.e. reverting only the LLM's part while preserving user changes, whereas using snapshots reverts user changes as well).
Author
Owner

@rekram1-node commented on GitHub (Oct 18, 2025):

We are going to rework it entirely without git soon so this shouldn't be a problem anymore

But that's a good callout, ill take a look

@rekram1-node commented on GitHub (Oct 18, 2025): We are going to rework it entirely without git soon so this shouldn't be a problem anymore But that's a good callout, ill take a look
Author
Owner

@rekram1-node commented on GitHub (Oct 19, 2025):

fixed in next release, good callout @veracioux

@rekram1-node commented on GitHub (Oct 19, 2025): fixed in next release, good callout @veracioux
Author
Owner

@JSCOP commented on GitHub (Oct 20, 2025):

undo command doesn't work on 0.15.10 either (with windows) (wsl, npm both doesn't work)

undo command is revert the message but code doesn't reverted.

@JSCOP commented on GitHub (Oct 20, 2025): undo command doesn't work on 0.15.10 either (with windows) (wsl, npm both doesn't work) undo command is revert the message but code doesn't reverted.
Author
Owner

@rekram1-node commented on GitHub (Oct 20, 2025):

@JSCOP it only works in projects tracked by git currently

@rekram1-node commented on GitHub (Oct 20, 2025): @JSCOP it only works in projects tracked by git currently
Author
Owner

@JSCOP commented on GitHub (Oct 21, 2025):

@rekram1-node This is test video https://youtu.be/24unfQ8xv5Q

I thought the /redo command would sequentially undo each command in the same way as /undo, but /redo always goes all the way back to the last request before undoing. Is this intended behavior? Or is this a bug in the Windows OpenCode?

@JSCOP commented on GitHub (Oct 21, 2025): @rekram1-node This is test video https://youtu.be/24unfQ8xv5Q I thought the /redo command would sequentially undo each command in the same way as /undo, but /redo always goes all the way back to the last request before undoing. Is this intended behavior? Or is this a bug in the Windows OpenCode?
Author
Owner

@rekram1-node commented on GitHub (Oct 21, 2025):

hm looks like bug

@rekram1-node commented on GitHub (Oct 21, 2025): hm looks like bug
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2086