产生了大量的快照(1.2TB .deepseek/snapshots)
Description
我部署了最新版本的DeepSeek TUI,用了两天出现了大量莫名其妙的阻塞,我没有查到阻塞原因,但是只有很少的指令可以被执行,昨天发现磁盘空间满了,查询了磁盘空间占用情况发现1.2T /Users/tycul/.deepseek/snapshots 。目前没有找到产生大量快照的原因。
Steps to reproduce
Expected behavior
Actual behavior
Environment
- OS:
- DeepSeek CLI version:
- Model:
- Shell:
Logs or screenshots
Root cause analysis
The 1.2TB in ~/.deepseek/snapshots/ comes from a combination of three factors:
1. Two snapshots per turn, default on
engine.rs:898 and 1125 call pre_turn_snapshot() and post_turn_snapshot() on every turn. Each one creates a full git commit of the workspace in the side repo at ~/.deepseek/snapshots/<project_hash>/<worktree_hash>/.git. In a long-running session (2 days without restart), this can generate thousands of snapshots.
2. Pruning only runs at startup
prune_workspace_snapshots() is called once at boot (main.rs:3975), nowhere during a running session. If deepseek-tui stays open for days, no snapshots are ever cleaned up.
3. Snapshot size depends on workspace
The builtin excludes (BUILTIN_EXCLUDES in snapshot/repo.rs:53) cover node_modules/, target/, dist/, __pycache__/, *.pyc, *.o, *.so and many other common patterns, but any large generated files or build artifacts outside those paths will bloat each snapshot commit. Git object deduplication helps (typical 10-30x reduction) but cannot compensate when the workspace itself is large and hundreds of snapshots have been taken.
Suggested fixes (in priority order)
- Add a retention count limit — keep only the last N snapshots (e.g. 50) regardless of age. This caps worst-case disk usage.
- Prune mid-session — trigger pruning periodically (e.g. every 50 turns) instead of only at startup.
- Expand builtin excludes — more patterns are already being added, but users can also add their own via
.gitignorein the workspace.
Recovering disk space without losing the ability to take future snapshots
Instead of deleting the entire snapshots directory, run git gc per side-repo:
for repo in "$HOME"/.deepseek/snapshots/*/*/.git; do
if [ -d "$repo" ]; then
echo "Cleaning $repo"
git --git-dir="$repo" reflog expire --expire=now --all
git --git-dir="$repo" gc --prune=now --aggressive
fi
done
This reclaims the disk space while keeping the side-repo structure intact so snapshots continue working for future turns.
Update for v0.8.27.
v0.8.24 added a snapshot cap (default 500 MB total, retain count limit, and post-turn pruning instead of just startup-only) so the unbounded-growth angle from your report is fixed for new sessions. @gordonlu had a great root-cause writeup (thanks!) — most of those suggestions did land:
- ✅ Retention count limit
- ✅ Mid-session pruning (no longer startup-only)
- ✅ Builtin excludes were expanded again in v0.8.25 / v0.8.26
To reclaim the existing 1.2 TB without losing snapshot capability, the GC loop @gordonlu posted is the right approach (run it once, then v0.8.27+ keeps growth bounded going forward).
Could you confirm two things on your latest version (≥ v0.8.26)?
du -sh ~/.deepseek/snapshots— is the directory still growing past ~500 MB?- Are you on iCloud Drive / network FS for
~/.deepseek/? (Some users on synced filesystems hit different growth patterns we'd want to track separately.)
If snapshot size is back under control with v0.8.26+, I'll close this. If you're still seeing growth past 500 MB, please paste the du output and we'll reopen for a follow-up.
(Pinging here for awareness — no action needed if it's fine.)
Code review 发现两个可能相关的根因:
- checkpoint JSON 解析错误静默返回 Null (
crates/state/src/lib.rs:566,587):
let state = serde_json::from_str(&state_json).unwrap_or(Value::Null);
如果 checkpoint 文件损坏,调用方收到 Value::Null 且无任何提示,可能触发无止境的重试写入。
- ShellManager.cleanup() 从未执行 (
shell.rs:1348) — 后台进程快照无清理机制,累积在内存和磁盘上。
两者结合可能解释了 .deepseek/snapshots 目录异常膨胀到 1.2TB 的行为。建议检查损坏的 checkpoint 文件和未清理的 shell 进程快照。