Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 25, 2025

Summary

This PR fixes a critical data loss issue where users were losing their entire codebase when restoring checkpoints. The issue was caused by the use of git clean -d -f which aggressively removes ALL untracked files.

Problem

The user reported in #6209 that when they clicked on checkpoint restore, it deleted almost all their codebase. This happened when switching between different tools (Copilot and Roo Code) and was causing complete data loss.

Root Cause

The restoreCheckpoint method in ShadowCheckpointService.ts was using:

await this.git.clean("f", ["-d", "-f"])

This command forcefully removes ALL untracked files and directories, which is extremely dangerous and was causing the reported data loss.

Solution

  1. Removed the dangerous git clean command - We no longer use git clean -d -f which was the primary cause of data loss
  2. Simplified restoration - Now using only git reset --hard which restores tracked files while preserving untracked files
  3. Added validation checks:
    • Verify worktree configuration matches expected workspace before restoration
    • Check that the commit hash exists before attempting restoration
  4. Added recovery methods for emergency situations:
    • listStashes() - List available stashes
    • recoverFromStash() - Recover from a specific stash

Testing

  • All existing checkpoint tests pass
  • Updated tests to verify the safer behavior
  • Added new test to ensure git clean is never called during restoration

Impact

This fix prevents catastrophic data loss that users were experiencing when restoring checkpoints. Untracked files are now preserved during checkpoint restoration, making the feature much safer to use.

Fixes #6209


Important

Fixes critical data loss issue by removing git clean -d -f from checkpoint restoration, adding validation checks, and introducing recovery methods.

  • Behavior:
    • Removed git clean -d -f from restoreCheckpoint in ShadowCheckpointService.ts to prevent data loss.
    • Now uses git reset --hard to restore tracked files while preserving untracked files.
    • Added validation to check worktree configuration and commit hash before restoration.
    • Introduced recovery methods listStashes() and recoverFromStash() for emergencies.
  • Testing:
    • Updated tests in ShadowCheckpointService.spec.ts to verify new behavior and ensure git clean is not called.
    • Added tests for worktree validation, commit hash validation, and recovery methods.
  • Impact:
    • Fixes critical data loss issue during checkpoint restoration, preserving untracked files and enhancing safety.

This description was created by Ellipsis for 58f9492. You can customize this summary. It will automatically update as commits are pushed.

…s git clean

- Removed the dangerous `git clean -d -f` command that was deleting all untracked files
- Simplified restoration to use only `git reset --hard` which preserves untracked files
- Added validation to ensure worktree configuration is correct before restoration
- Added check to verify commit exists before attempting restoration
- Added recovery methods (listStashes, recoverFromStash) for emergency data recovery
- Updated tests to reflect the safer behavior

This fixes the critical data loss issue where users were losing their entire codebase
when restoring checkpoints, especially when switching between different tools like
Copilot and Roo Code.

Fixes #6209
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 25, 2025 12:54
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jul 25, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 25, 2025
@daniel-lxs
Copy link
Member

The PR description is properly scoped but the implementation is all over the place, closing

@daniel-lxs daniel-lxs closed this Jul 28, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Critical Issue with Checkpoint restore

4 participants