anomalyco / anomalyco/opencode
Snapshot restore() force-rewrites every worktree file even when content is identical (related: #15391)
@jlongster is already working on this.
Since Aug 24, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
When snapshot.restore() runs (revert/unrevert flows), it does read-tree + checkout-index -a -f. The -a -f force-rewrites every file in the index unconditionally, even when the worktree is already byte-identical to the snapshot. All file mtimes in the project get bumped while content stays identical (git status remains clean).
Related: #15391 (closed without a fix — checkout-index -a -f is still in restore() on dev @ 55f9841) and #5840 (mtime side effect).
Evidence from my machine: opencode.log shows restore commit=4ca9cb1a... at 08:48:26Z, and 1012 files had their mtime changed within the same 2-3 seconds. The shadow repo sets autocrlf=false, so rewrites are byte-identical (LF stays LF).
Impact: anything that diffs by mtime misfires. After every opencode session, the Obsidian "Remotely Save" plugin planned to re-upload 657/945 vault files and tripped its own ">=50% changed" safety abort.
Suggested fix: content-compare the worktree against the snapshot first (git diff --name-only <snapshot>) and return early when empty; otherwise proceed as today. Note that plumbing diff-files can't be used for this check after read-tree (the index has no stat cache, so it reports every file) — the porcelain diff is content-aware. Happy to send a PR.
Plugins
No response
OpenCode version
1.14.29
Steps to reproduce
- Open any git project in opencode, let it edit a file, then run
/undo(the session now carries a revert marker) - Run
/redo(or resume the session) sorestore()fires — opencode.log will showrestore commit=<hash> - Compare file mtimes before/after, e.g.
find . -type f -newermt "1 minute ago" | wc -lin a quiet project - Every indexed file gets rewritten: all mtimes bump, content is byte-identical,
git statusstays clean
Screenshot and/or share link
No screenshot — log and mtime evidence:
timestamp=2026-08-24T08:48:26.714Z level=INFO message=restore commit=4ca9cb1a5fb02fddc76e8f07cb01a19d404d5034
Same moment, project root: 1012 files rewritten within 2s (928 content files + 84 .obsidian files), git status clean before and after.
Operating System
Windows 10
Terminal
git bash
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.