dsh-session-recovery
August 18, 2026 Β· View on GitHub
dsh-session-recovery
Recover deleted/corrupted DeepSeek Harness sessions & memory from raw disk
English Β· δΈζ
π After
rm -rf ~/.dshor file corruption, dsh conversation logs (session.jsonl.zstd) and memory (memory.db) can usually be recovered straight from the raw block device β this repo is a battle-tested manual plus the scripts that made it work.
β¨ Features
| π§ Memory recovery | Locate memory.db by its SQLite format 3 header, dump the window, rescue rows via SQLite's official .recover (skips corrupt pages, keeps readable data). |
| π¬ Session recovery | Scan disk for zstd frame magic 0xFD2FB528, cluster frames by disk offset, split sessions at turn resets, rebuild official-format session.jsonl.zstd. |
| π§ Automatic repair | Renumber seq contiguously, deep-fix sourceEventSeqs/messageSeqs, normalize surfaceOp β the rebuilt log passes DSH's validation. |
| π Resume repair | Rebuilt sessions can fail at resume (invalid persisted inbox splice, Messages with role 'tool' must be a response to tool_calls) β repair-session.js (or the /session-repair web command) replays DSH's inbox/surface/wire rules and fixes the file. |
| π‘οΈ Safe by design | Scripts only read the block device and write to a directory you choose; the original disk is never modified. |
π Quick Start
# 1. Stop everything that writes to disk (systemd services, dsh itself)
systemctl stop dsh-web
# 2. Recover memory (SQLite)
node scripts/recover-memory.js /dev/<dev> /tmp/recovered/
# 3. Scan disk for session frames
node scripts/scan-zstd.js /dev/<dev> > /tmp/session-events.jsonl
# 4. Split mixed events into per-session files
node scripts/split-sessions.js /tmp/session-events.jsonl 2026-08-16T07:05:06Z
# 5. Rebuild a session file (official format)
node scripts/rebuild-session.js \
--input /tmp/sess-A.jsonl \
--id session-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
--created-at 1786705157736 \
--cwd /path/to/workspace \
--out-dir ~/.dsh/sessions/--workspace-encoded--/
# 6. Before resuming: verify/repair the rebuilt session (fixes inbox splice
# skew, duplicate/orphaned tool results, dangling tool calls)
node scripts/repair-session.js \
~/.dsh/sessions/--workspace-encoded--/<session-id>/session.jsonl.zstd --dry-run
node scripts/repair-session.js \
~/.dsh/sessions/--workspace-encoded--/<session-id>/session.jsonl.zstd
# β writes session.jsonl.zstd.repaired (+ .bak-<ts>); review, then replace:
cp ~/.dsh/sessions/--workspace-encoded--/<session-id>/session.jsonl.zstd.repaired \
~/.dsh/sessions/--workspace-encoded--/<session-id>/session.jsonl.zstd
π Full step-by-step manual (Chinese, with every DSH validation rule and error you may hit): RECOVERY.md
π¦ Install as a dsh plugin
Note: primarily a recovery toolkit (scripts + manual); it also installs as a dsh plugin that adds the
/session-repaircommand to the web UI.
From a directory containing this repo (local install, no publish needed):
dsh plugin --profile web add file:/path/to/dsh-session-recovery
systemctl restart dsh-web
Then type in any session in the web UI:
/session-repair --dry-run # analyze the current session (writes nothing)
/session-repair <session-id-or-path> # repair β writes .repaired + a backup
/session-repair --apply <id> # also replace the original file
By default only a new .repaired file plus a backup are written; --apply overwrites the original (refused for the live session hosting the command β run it from another session). Restart dsh-web after applying.
Requires Node 24+ (node:sqlite, node:zlib).
π Background
DeepSeek Harness stores its data under ~/.dsh:
~/.dsh/
βββ sessions/<workspace-encoded>/<session-id>/session.jsonl.zstd # conversation log
βββ memory/memory.db # dsh-mneme memory
βββ storages/workspace.json # workspace registry
The session log is a concatenated stream of zstd frames β one frame per JSONL line (source). That per-line framing is exactly what makes partial recovery possible: even if some frames are overwritten, the intact frames around them still decode independently.
ποΈ Repository Layout
βββ RECOVERY.md # Full recovery manual (Chinese, battle-tested)
βββ cordis.patch.yml # dsh plugin patch (registers /session-repair)
βββ docs/
β βββ awesome-entry.yml # Ready-to-submit Awesome DSH Plugin list entry
β βββ GITHUB-PUBLISH.md # Publish & PR checklist
βββ lib/
β βββ index.js # dsh plugin entry: /session-repair command
β βββ repair.js # Shared repair core (CLI + plugin)
βββ scripts/
β βββ scan-zstd.js # Disk scan: find & cluster zstd session frames
β βββ split-sessions.js # Split mixed recovered events into per-session files
β βββ rebuild-session.js # Rebuild official-format session.jsonl.zstd
β βββ repair-session.js # Fix rebuilt sessions that fail to resume
β βββ make-test-fixture.js # Generate damaged samples to test repair offline
β βββ recover-memory.js # Locate & rescue memory.db (SQLite .recover)
βββ package.json # dsh plugin manifest (dsh.bundle + main entry)
π Topics
dsh-plugin Β· dsh Β· deepseek-harness Β· session-recovery Β· data-recovery Β· zstd Β· sqlite