Skip to content

fix(snapshot): make /redo targeted to only restore files from reverted turn#15611

Open
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Br1an67:fix/issue-15391-redo-targeted
Open

fix(snapshot): make /redo targeted to only restore files from reverted turn#15611
Br1an67 wants to merge 1 commit intoanomalyco:devfrom
Br1an67:fix/issue-15391-redo-targeted

Conversation

@Br1an67
Copy link
Copy Markdown

@Br1an67 Br1an67 commented Mar 1, 2026

Issue for this PR

Closes #15391

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

/redo (unrevert) was using checkout-index -a -f which writes every tracked file from the snapshot tree, updating mtimes on all files — even those untouched by the reverted turn. This triggers editor reload prompts and confuses file watchers.

The fix stores the file list collected from patches during /undo into session.revert.files, then passes it to restore() during /redo. When a file list is present, restore() does per-file git checkout <hash> -- <file> (the same pattern revert() already uses) with the ls-tree fallback for files that were created and need deletion. When no file list is available (backward compat), it falls back to the existing blanket restore.

Three files changed:

  • session/index.ts — added optional files field to the revert schema
  • session/revert.ts — collect unique file paths from patches, pass them through unrevert
  • snapshot/index.tsrestore() accepts optional file list for targeted checkout

How did you verify your code works?

Read through the existing revert() function to confirm the targeted checkout pattern is identical. The new restore() path mirrors revert() exactly — same git flags, same ls-tree fallback, same fs.unlink cleanup.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…erted turn

/redo used checkout-index -a -f which writes every file from the
snapshot, updating modification timestamps on unchanged files and
triggering editor reload prompts.

Store the file list from patches during /undo, pass it through to
/redo, and use per-file checkout (same pattern as revert) when a file
list is available. Falls back to blanket restore for backward
compatibility.
@NamedIdentity
Copy link
Copy Markdown

NamedIdentity commented Mar 8, 2026

I've tested this code and confirm it appeared to fix the bug I encountered and created the Issue for in a limited new test session. However, when I went into an older session and used redo, the bug persisted and changed all files in project to todays date.

@NamedIdentity
Copy link
Copy Markdown

Did some further testing. Code is fine, but testing environment was the problem.

Tested this fix locally. Works as expected in new sessions — /undo then /redo correctly preserves file timestamps on untouched files.

One edge case worth noting: if /undo was performed on older code (before this fix), the revert record stored in the session won't have the files field. When /redo runs with the new code, it hits the backward-compat fallback and does the old blanket checkout-index -a -f, reproducing the original bug. This is by design — the fix requires both /undo and /redo to run on the new code. Once the old revert is cleared (by redoing and undoing again with the new code), subsequent /redo operations work correctly.

Not a bug — just a one-time edge case for sessions with pre-fix revert state.

@Br1an67
Copy link
Copy Markdown
Author

Br1an67 commented Mar 10, 2026

Hi — just a gentle bump on this. Happy to make any changes if needed!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(snapshot): /redo touches all files unnecessarily, destroying date modified metadata and triggering editor reload prompts

2 participants