-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Describe the bug
Describe the bug
When using "restore to checkpoint" (triggered by pressing Escape during an agent run and choosing to restore), the SnapshotManager.rollbackToSnapshot() method runs git clean -fd on the repository root. This permanently deletes all untracked files and directories in the repo — including large output files generated by external processes that the agent never touched.
In my case, this destroyed ~1GB+ of evaluation output data (.jsonl and .xlsx files) across multiple directories under output/ that were generated by a Python script the agent ran. The agent only read these files — it never created or modified them — yet they were all deleted by the checkpoint restore.
Root cause (from source analysis)
The rollback flow in rollbackToSnapshot() calls:
trr(gitRoot, gitCommit, gitBranch)→ runsgit checkout --force+git reset --hardqnr(gitRoot)→ runsgit clean -fd← this is the destructive operation
git clean -fd removes all untracked files and directories. The snapshot system only backs up files that the agent itself created/modified. Any files created by external processes (scripts, builds, test output, data pipelines) that happen to be untracked are silently and permanently deleted.
Affected version
0.0.417 (but the code is present in earlier versions too — at least 0.0.411+)
Steps to reproduce
- Have a git repo with untracked files/directories not in
.gitignore(e.g.,output/with large data files) - Start a Copilot CLI session in that repo
- Have the agent run a command that generates output files (e.g.,
uv run python script.pythat writes tooutput/) - Press Escape twice to cancel the agent mid-run
- Choose "Restore to this checkpoint" when prompted
- All untracked files/directories are now deleted — including the output files from step 3
Expected behavior
Checkpoint restore should not delete untracked files that the agent didn't create. Possible fixes:
- Only clean files the agent created: Track which files were created by agent tool calls and only remove those
- Skip
git cleanentirely: The snapshot already tracks and restores individual files — thegit cleanis a blunt hammer on top - Warn the user: At minimum, show "This will delete X untracked files (Y MB). Proceed?" before running
git clean -fd - Move to trash instead of delete: Use OS trash/recycle bin so files can be recovered
Additional context
- The
output/directory was not in.gitignore(user's mistake, now fixed), but even repos with proper.gitignorecould lose untracked files in directories that aren't ignored - The data loss is permanent —
git clean -fddoesn't use the recycle bin - This is especially dangerous for repos that generate large output artifacts (ML training, data pipelines, evaluation benchmarks)
- The
SESSION_CLEANUPfeature flag is set to"staff-or-experimental", suggesting this is still being refined
Affected version
0.0.417
Steps to reproduce the behavior
No response
Expected behavior
No response
Additional context
No response