Expand description
Workspace snapshots — pre/post-turn safety net.
Each turn the engine takes a pre-turn:<seq> snapshot of the user’s
workspace into a side git repo at
~/.deepseek/snapshots/<project_hash>/<worktree_hash>/.git, then a
matching post-turn:<seq> snapshot when the turn finishes. Users
can roll back via /restore N (slash command) or, when the model
recognises an “undo my last edit” intent, the revert_turn tool.
§Why a side repo?
- The user’s own
.gitis never touched.--git-dirand--work-treeare always set together when we shell out to git; that single invariant is what keeps snapshots and the user’s repo completely independent. - Workspaces without git still get snapshots.
git’s own deduplication (object packfiles) keeps the disk footprint tractable — typical 100 MB workspace × 12 turns ≈ 1.2 GB uncompressed but git’s content-addressed storage usually brings that down 10-30×. We mitigate further with:- 7-day default retention (
session_managerprunes at session start viaprune::prune_older_than). gc.auto = 0on the side repo (we don’t want background gcs firing mid-turn) plus an explicitgit gc --prune=nowafter prune.
- 7-day default retention (
§Failure model
Pre/post-turn snapshot calls are non-fatal. If git is missing,
the disk is full, or the workspace is on a read-only filesystem, the
turn proceeds and the engine logs a warning. The snapshot is a
safety net, not a correctness gate.
Modules§
- paths
- Path resolution for the per-workspace snapshot side-repos.
- prune
- Boot-time snapshot pruning.
- repo
- Side-git repository wrapper for workspace snapshots.
- size
- Workspace byte-size estimation before side-git snapshot init.
Structs§
- Snapshot
- A single snapshot record (one row in
git log). - Snapshot
Id - Identifier for a snapshot — currently the underlying git commit SHA.
- Snapshot
Repo - Wrapper around the per-workspace side-git repo.
Constants§
- DEFAULT_
MAX_ AGE - Default snapshot retention window: 7 days.
- DEFAULT_
SNAPSHOT_ MAX_ WORKSPACE_ GB - Default cap when
[snapshots] max_workspace_gbis unset (matches upstream v0.8.32).
Functions§
- estimate_
workspace_ bytes - Sum file sizes under
workspace, honoring gitignore + skip-dir rules. Stops early oncelimit_byteswould be exceeded (passNonefor full scan). - prune_
older_ than - Prune snapshots older than
max_agefor the given workspace. - snapshot_
dir_ for - Compute the snapshot directory for a given workspace path.
- snapshot_
git_ dir - Resolve the
.gitdirectory inside the snapshot dir. - workspace_
exceeds_ size_ limit - Returns
truewhen the workspace tree exceedsmax_gb( gibibyte-style GB:max_gb * 1024^3bytes).