opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Unrevert from subdirectory overwrites files in other directories with stale versions

Open ryanwyler opened this issue 4 days ago • 1 comments

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 "[email protected]" && 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

ryanwyler avatar Jan 11 '26 10:01 ryanwyler