fix(tools): make checkpoint restores consistent - #64966
Conversation
Remove files added after a full checkpoint restore and pin the target tree across retention pruning so rollback remains reliable after immediate garbage collection.
ce6ea97 to
b5014cb
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the reliability and correctness of checkpoint restores in CheckpointManager, specifically for full-directory restores. It ensures that restores clean up paths introduced after the target checkpoint and makes restores resilient to retention pruning and aggressive git gc that could otherwise invalidate the restore target mid-operation.
Changes:
- Pin the checkpoint’s target tree via a temporary ref before taking the pre-rollback snapshot, preventing retention pruning + GC from making the restore target unreachable.
- For full-directory restores, switch from
git checkout <commit> -- .togit read-tree --reset -u <tree>to also remove tracked paths added after the checkpoint. - Add regression tests for: removing added-after-checkpoint paths, preserving excluded files, and restoring successfully even when retention rewriting would otherwise invalidate the target.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tools/checkpoint_manager.py | Pins restore target tree across prune/GC and uses read-tree --reset -u for full restores to remove added tracked paths. |
| tests/tools/test_checkpoint_manager.py | Adds regression coverage for added-path removal, excluded-file preservation, and retention-rewrite resilience. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # complete tracked tree, including removing those added paths, | ||
| # without touching excluded files. | ||
| restore_args = ["read-tree", "--reset", "-u", restore_ref] | ||
| ok, stdout, err = _run_git( |
Competing with #64477 for the same checkpoint-restore data-safety fix. This PR also pins the target tree across pre-rollback retention pruning + |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Summary
PR #64966 makes checkpoint restores consistent: files added after a checkpoint are now removed on restore, and excluded files are properly preserved. Previously, added files would persist after restore, which could cause inconsistency.
Assessment
- Correctness: Two new test cases cover the behavior.
- Scope: Small focused change.
- Risk: Low. Test-backed fix for a consistency issue.
No concerns
Reviewed by Hermes Agent
|
Thanks for the focused checkpoint-safety fix. The premise remains present on current main: The patch pins the target tree before that snapshot, preserves the single-file checkout path, and changes only full restores to Automated hermes-sweeper review. |
Summary
Why
A full restore previously used
git checkout <commit> -- ., which restored paths present in the checkpoint but left files added afterward. Separately, creating the pre-rollback snapshot could exceedmax_snapshots; pruning then rewrote retained commits and rangc --prune=now, invalidating the requested target before restore.Test plan
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 uv run --isolated --python 3.12 --with pytest --with pyyaml pytest -q tests/tools/test_checkpoint_manager.py80 passed in 7.78sgit diff origin/main...HEAD --checkNotes
finally