Rolling back to an earlier snapshot currently leaves files added and tracked in a later snapshot: restore_snapshot() reports success, but later work products are still present. Git checkout uses overlay mode by default.
Restore snapshot contents as before, then use a non-overlay checkout to remove tracked work products absent from the target snapshot. Keep the current and legacy history-cache directories under their existing overlay behavior so LLMAgent.rollback() can read and truncate history created after the first snapshot.
Regression tests exercise actual Git repositories: restoring older/newer snapshots, removing later tracked files, retaining untracked files and snapshot metadata, and restoring existing history while preserving later history in both cache layouts.
Related issue number
No linked issue. Checked all 26 open PRs and snapshot-related issue/closed-PR searches. #1002 changes other tests in the same file but does not address removal of later tracked files.
Validation
Before the fix, the new regression fails because the later file still exists.
python -m pytest tests/utils/test_snapshot_smoke.py --allow-hosts=127.0.0.1,::1 -q: 27 passed, 32 subtests passed. Only loopback connections are allowed for the Windows asyncio event loop.
pre-commit run --files ms_agent/utils/snapshot.py tests/utils/test_snapshot_smoke.py: all applicable hooks passed.
git diff --check: passed.
Ran pre-commit install and pre-commit run --all-files. The full run reports existing lint/format issues in unrelated files (for example ms_agent/utils/file_lock.py E731, ms_agent/config/skills_manager.py E305 and .dev_scripts/webui/oss_distribution.py E128). The final patch was validated in a fresh worktree containing only the two relevant file changes.
Checklist
The pull request title is a good summary of the changes
Unit tests for the changes exist
Run pre-commit install and pre-commit run --all-files before git commit, and passed lint check (run; unrelated baseline failures listed above)
Documentation reflects the changes where applicable (function docstring clarified)
Prepared with Codex, including regression tests and a separate AI code review.
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
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.
Change Summary
Rolling back to an earlier snapshot currently leaves files added and tracked in a later snapshot: restore_snapshot() reports success, but later work products are still present. Git checkout uses overlay mode by default.
Restore snapshot contents as before, then use a non-overlay checkout to remove tracked work products absent from the target snapshot. Keep the current and legacy history-cache directories under their existing overlay behavior so LLMAgent.rollback() can read and truncate history created after the first snapshot.
Regression tests exercise actual Git repositories: restoring older/newer snapshots, removing later tracked files, retaining untracked files and snapshot metadata, and restoring existing history while preserving later history in both cache layouts.
Related issue number
No linked issue. Checked all 26 open PRs and snapshot-related issue/closed-PR searches. #1002 changes other tests in the same file but does not address removal of later tracked files.
Validation
Checklist
Prepared with Codex, including regression tests and a separate AI code review.