Repository navigation
fix(opencode): keep files on revert when snapshot is missing - #63475
Open
VISWA00723 wants to merge 1 commit into
Open
VISWA00723 wants to merge 1 commit into
VISWA00723 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #54577
Type of change
What does this PR do?
Snapshot trees created by
Snapshot.trackhave no git refs, soSnapshot.cleanup(git gc --prune=7.days) eventually prunes older trees (and moving a worktree creates a fresh snapshot store). When reverting a message whose snapshot tree is missing,git checkout <hash> -- <file>fails andsingle()inSnapshot.revertfalls back togit ls-tree <hash> -- <rel>. Previously it only kept the file whentree.code === 0 && tree.text.trim(), so a missing tree (tree.code !== 0with empty stdout) fell through toremove(op.file)and deleted every existing file touched in that turn.This change only deletes a file when
ls-treesucceeds (tree.code === 0) and returns empty output (proving the snapshot tree is readable and the file was absent). Whentree.code !== 0 || tree.text.trim(),Snapshot.revertkeeps the file on disk, logs a warning, and returns the kept paths soSessionRevert.revertcan publish aSession.Event.Errorlisting the files that could not be restored.How did you verify your code works?
packages/opencode/test/snapshot/snapshot.test.tsverifying that pruning the snapshot store (git gc --prune=now) beforesnapshot.revertkeeps both modified and newly added files on disk and returns their paths, while readable snapshots still delete newly added files and restore modified ones.packages/opencode/test/session/revert-compact.test.tsverifying thatSessionRevert.revertafter snapshot pruning preserves file contents on disk, updatessession.revert, and publishes theSession.Event.Errornaming the kept file.bun test --timeout 30000 test/session/revert-compact.test.ts test/snapshot/snapshot.test.tsinpackages/opencode(64 passed, 0 failed),bun oxlint, andbun turbo typecheck.Screenshots / recordings
Not a UI change.
Checklist