Skip to main content

Module snapshot

Module snapshot 

Source
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 .git is never touched. --git-dir and --work-tree are 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_manager prunes at session start via prune::prune_older_than).
    • gc.auto = 0 on the side repo (we don’t want background gcs firing mid-turn) plus an explicit git gc --prune=now after prune.

§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).
SnapshotId
Identifier for a snapshot — currently the underlying git commit SHA.
SnapshotRepo
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_gb is unset (matches upstream v0.8.32).

Functions§

estimate_workspace_bytes
Sum file sizes under workspace, honoring gitignore + skip-dir rules. Stops early once limit_bytes would be exceeded (pass None for full scan).
prune_older_than
Prune snapshots older than max_age for the given workspace.
snapshot_dir_for
Compute the snapshot directory for a given workspace path.
snapshot_git_dir
Resolve the .git directory inside the snapshot dir.
workspace_exceeds_size_limit
Returns true when the workspace tree exceeds max_gb ( gibibyte-style GB: max_gb * 1024^3 bytes).