Unrevert from subdirectory overwrites files in other directories with stale versions #4719

Open
opened 2026-02-16 17:45:09 -05:00 by yindo · 2 comments
Owner

Originally created by @ryanwyler on GitHub (Jan 11, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

When running opencode from a subdirectory and clicking "undo revert", files in other directories are overwritten with stale versions (potentially weeks old).

Steps to Reproduce

  1. Create a project with multiple subdirectories:
mkdir -p /tmp/testproject/frontend /tmp/testproject/backend
cd /tmp/testproject
git init && git config user.email "test@test.com" && git config user.name "Test"
echo 'console.log("frontend")' > frontend/app.ts
echo 'println("backend ORIGINAL")' > backend/server.go
git add . && git commit -m "Initial"
  1. Run opencode from backend/, make a change, then exit:
cd /tmp/testproject/backend
opencode
# Ask it to modify server.go, then exit
  1. Update backend externally (simulates time passing):
echo 'println("backend CURRENT")' > backend/server.go
git add . && git commit -m "Update backend"
  1. Run opencode from frontend/, make a change, revert, then unrevert:
cd /tmp/testproject/frontend
opencode
# Ask it to modify app.ts
# Click "Revert" on the assistant's message
# Click "Undo Revert"
  1. Check if backend was corrupted:
cat /tmp/testproject/backend/server.go
# Shows "backend ORIGINAL" instead of "backend CURRENT"

Expected Behavior

Files in other directories should NOT be affected when running revert/unrevert from a subdirectory.

Actual Behavior

Files in other directories are overwritten with stale versions from the shared snapshot index.

Root Cause

  1. The snapshot index at ~/.local/share/opencode/snapshot/{project_id}/ is shared across all sessions in a project
  2. git add . from a subdirectory only updates that subdirectory's entries in the index
  3. restore() uses checkout-index -a which restores ALL files in the index, including stale entries from other directories
  4. diff() uses cwd(Instance.worktree) showing diffs for unrelated directories

Environment

  • OpenCode version: v1.1.13
  • OS: Linux
Originally created by @ryanwyler on GitHub (Jan 11, 2026). Originally assigned to: @rekram1-node on GitHub. ## Description When running opencode from a subdirectory and clicking "undo revert", files in other directories are overwritten with stale versions (potentially weeks old). ## Steps to Reproduce 1. Create a project with multiple subdirectories: ```bash mkdir -p /tmp/testproject/frontend /tmp/testproject/backend cd /tmp/testproject git init && git config user.email "test@test.com" && git config user.name "Test" echo 'console.log("frontend")' > frontend/app.ts echo 'println("backend ORIGINAL")' > backend/server.go git add . && git commit -m "Initial" ``` 2. Run opencode from `backend/`, make a change, then exit: ```bash cd /tmp/testproject/backend opencode # Ask it to modify server.go, then exit ``` 3. Update backend externally (simulates time passing): ```bash echo 'println("backend CURRENT")' > backend/server.go git add . && git commit -m "Update backend" ``` 4. Run opencode from `frontend/`, make a change, revert, then unrevert: ```bash cd /tmp/testproject/frontend opencode # Ask it to modify app.ts # Click "Revert" on the assistant's message # Click "Undo Revert" ``` 5. Check if backend was corrupted: ```bash cat /tmp/testproject/backend/server.go # Shows "backend ORIGINAL" instead of "backend CURRENT" ``` ## Expected Behavior Files in other directories should NOT be affected when running revert/unrevert from a subdirectory. ## Actual Behavior Files in other directories are overwritten with stale versions from the shared snapshot index. ## Root Cause 1. The snapshot index at `~/.local/share/opencode/snapshot/{project_id}/` is shared across all sessions in a project 2. `git add .` from a subdirectory only updates that subdirectory's entries in the index 3. `restore()` uses `checkout-index -a` which restores ALL files in the index, including stale entries from other directories 4. `diff()` uses `cwd(Instance.worktree)` showing diffs for unrelated directories ## Environment - OpenCode version: v1.1.13 - OS: Linux
Author
Owner

@github-actions[bot] commented on GitHub (Jan 11, 2026):

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

  • #7753: One OpenCode session's modified files appear in another session's Modified Files list in the same repo - shares the same root cause of shared snapshot index across sessions in a project
  • #5910: Undo previous message incorrectly restores project state - specifically mentions the snapshot system tracking changes at project level and subdirectories using the same snapshot, causing stale states to be captured
  • #4251: Concurrent sessions working on different repos interfere each other - relates to multiple sessions in a project interfering with each other's file states

All three issues appear to stem from the shared snapshot index at ~/.local/share/opencode/snapshot/{project_id}/ being used across sessions in different directories/subdirectories.

Feel free to ignore if your case is distinct from these.

@github-actions[bot] commented on GitHub (Jan 11, 2026): This issue might be a duplicate of existing issues. Please check: - #7753: One OpenCode session's modified files appear in another session's `Modified Files` list in the same repo - shares the same root cause of shared snapshot index across sessions in a project - #5910: Undo previous message incorrectly restores project state - specifically mentions the snapshot system tracking changes at project level and subdirectories using the same snapshot, causing stale states to be captured - #4251: Concurrent sessions working on different repos interfere each other - relates to multiple sessions in a project interfering with each other's file states All three issues appear to stem from the shared snapshot index at `~/.local/share/opencode/snapshot/{project_id}/` being used across sessions in different directories/subdirectories. Feel free to ignore if your case is distinct from these.
Author
Owner

@UPROOT01 commented on GitHub (Feb 16, 2026):

i had the same exact issue, luckily i had already committed because doing redo right after didnt actually bring back my files in the other directories. I only lost a few lines of code but it could've gone a lot worse...

@UPROOT01 commented on GitHub (Feb 16, 2026): i had the same exact issue, luckily i had already committed because doing redo right after didnt actually bring back my files in the other directories. I only lost a few lines of code but it could've gone a lot worse...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4719