fix(snapshot): scope restore and diff to the session directory - #6
Open
ryangamerdev wants to merge 1 commit into
Open
fix(snapshot): scope restore and diff to the session directory#6ryangamerdev wants to merge 1 commit into
ryangamerdev wants to merge 1 commit into
Conversation
The snapshot index is shared across a whole project (git worktree), but a snapshot taken from a subdirectory only updates that subdirectory's entries via `add()` (scoped with `cwd: state.directory`). `restore()` used `checkout-index -a -f`, which writes every entry in the shared index across the entire worktree - so reverting/unreverting a session started in a subdirectory could overwrite a sibling directory's current file with a stale index blob, silently destroying unrelated edits. `diff()` had the matching scope gap: it ran `-- .` from `cwd: state.worktree`, reporting changes for unrelated directories. Scope both to the session directory: - restore() lists the snapshot's files under the session-directory prefix (`ls-tree -r`) and checks out only those, instead of `checkout-index -a`. - diff() runs from `cwd: state.directory` so `-- .` is relative to the session directory, consistent with add()/patch()/diffFull().
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 anomalyco#39513
Type of change
What does this PR do?
Fixes a data-loss bug: reverting or unreverting a session started in a subdirectory can silently overwrite an unrelated edit in a sibling directory.
The snapshot index is shared across the whole project (git worktree), but a snapshot taken from a subdirectory only updates that subdirectory's entries —
add()runsls-files ... -- .scoped withcwd: state.directory.restore(), however, rancheckout-index -a -f, which writes every entry in the shared index across the entire worktree. So a sibling directory's file that was captured in the index at an earlier (stale) revision, then edited on disk afterward, gets clobbered back to the stale blob on revert — destroying current work the session never touched.diff()had the matching scope gap (it ran-- .fromcwd: state.worktree, reporting changes for unrelated directories).The fix scopes both to the session directory:
restore()lists the snapshot's files under the session-directory prefix (ls-tree -r --name-only <snapshot> -- <prefix>/) and checks out only those paths, instead ofcheckout-index -a.diff()runs fromcwd: state.directoryso its-- .path spec is relative to the session directory, consistent withadd(),patch(), anddiffFull().This is an urgent, minimal interim fix for live data loss. It is intentionally small and does not attempt the broader snapshot rework being discussed in anomalyco#44511 (mutation epochs) — whose own acceptance criteria include "reverting one session cannot silently overwrite changes attributed to another actor." This PR delivers that guarantee for the subdirectory case today, while that design is still in discussion.
How did you verify your code works?
bun typecheckpasses across all packages, rebased on currentdev.frontend/andbackend/, snapshot taken fromfrontend/(seeds the shared index withbackendat its original revision), thenbackendedited on disk. Before the fix,restore()'scheckout-index -a -foverwrites the currentbackendfile with the stale index blob. After the fix, restore lists only files under thefrontend/prefix and leavesbackend's current edit untouched, restoring onlyfrontend/.Checklist