Skip to content

Snapshot restore() force-rewrites every worktree file even when content is identical (related: #15391) #44724

Closed

Description

@LeonX86

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

  1. Open any git project in opencode, let it edit a file, then run /undo (the session now carries a revert marker)
  2. Run /redo (or resume the session) so restore() fires — opencode.log will show restore commit=<hash>
  3. Compare file mtimes before/after, e.g. find . -type f -newermt "1 minute ago" | wc -l in a quiet project
  4. Every indexed file gets rewritten: all mtimes bump, content is byte-identical, git status stays 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

Activity

  1. neriousy commented on Oct 19, 2026

    @neriousy
    Member

    V2 undo/redo restores only the files affected by the reverted messages, rather than force-rewriting the entire worktree, so unrelated files keep their modification times. To get v2: npm i -g @opencode/cli@latest or curl -fsSL https://opencode.ai/v2/install | bash (desktop: update the app). If you still see this on v2, please open a new issue with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions