Preface¶
DeepSeek Harness (DSH) stores session history as batch-appended, checksum-validated zstd frames. This log is the sole medium for memory exchange between the human and DSH: once a record fails shape validation during the loading phase, the entire history reports a SessionPersistenceCorruptionError. The interface typically displays “history unavailable … must contain one tool-result block”—effectively causing the system and the user to “lose their memory” together.
The problem often stems from asymmetry between writing and loading: the write path does not validate message shape. When third-party plugins return violations such as raw strings in output.render(), the write process does not error out; the issue is only exposed during the next load. The community-maintained dsh-session-doctor (imtokenxinluo) performs health checks on this type of persisted corruption, repairs it losslessly after backup, and provides real-time watch alerts starting with v1.1, and blame incident attribution starting with v1.2. Below is an introduction to what it is, what it can do, and how to install and use it.
What is This¶
dsh-session-doctor is a session health check and repair tool designed for DeepSeek Harness. It scans stored session logs using the same rules as the DSH loading path, identifying corrupted records that would cause history loading failures. It performs lossless repairs for supported types of shape drift and automatically backs up before every repair. Maintained by imtokenxinluo, it is categorized as “Memory” in the SkillHub community directory. The repository can be found on GitHub, and the license is MIT. The current npm package version is 0.2.3 (subject to package.json).
It complements kernel-side “write-path guards” and sibling plugins like dsh-contract-check: contract-check focuses on pre-event static checks, while this tool’s watch focuses on real-time alerts, and scan/repair focuses on post-event remediation. Installing one does not affect the other.
Core Features¶
scan: Health checks with the same rules as the loader¶
Traverses the sessions root directory or a single .jsonl.zstd file, validates each event, and reports corrupted sessions, line numbers, seq, event types, involved tool names, and reasons.
repair: Lossless repair after backup (limited forms)¶
For a single corrupted file: first backs up as <file>.<ts>.bak, then repairs records where content in tool-result blocks is not an array, rewrites at the frame level (bytes in uncorrupted frames remain unchanged), and verifies the rewritten product with 0 failures before persisting it. Unknown forms of corruption are reported only, not automatically repaired.
Three forms are currently supported and repaired without changing text:
| Form | Fix Method |
|---|---|
content is a raw string |
Wrap as [{type:"text",text:…}] |
content is null or missing |
Set to [] |
content is a single object |
Wrap as [obj] |
Forms like numbers or booleans that cannot be safely inferred are never repaired.
watch (v1.1): Real-time Sentinel¶
Subscribes to DSH session/event, performs loader-standard validation immediately on newly written message events in live sessions, and alerts immediately upon violation. Since events are published only after append, watch does not prevent writing or modify live files; repairs are left to repair on cold sessions.
blame (v1.2): Was the sudden closure caused by the agent?¶
Read-only analysis of session logs: locates the interruption breakpoint, looks back at the tool call chain before the breakpoint, and matches dangerous patterns such as killing processes, closing browsers, or restarting the harness. Judges AGENT-CAUSED, EXTERNAL, or NO-ACCIDENT under a dual-evidence threshold; missing evidence is noted for torn frames at the log tail.
safeguard (since 0.2.2)¶
Chains commands together: cold backup of the entire sessions tree → health check → repair → read-back verification. If the cold backup fails, it aborts and never proceeds to repair.
Settings Panel “Session Health Check” (since 0.2.2)¶
GET /session-doctor/report displays conclusions in read-only mode; POST /session-doctor/repair requires explicit triggering for repair. Versions 0.2.1 and earlier, once installed into a profile, only provide the real-time sentinel without the panel or the above routes; CLI scan/repair/blame remain available. To determine if the panel is included: check the version in node_modules/dsh-session-doctor/package.json, or check if lib/client.js exists in that directory.
For a full catalog of corruption forms and explanations of “repairable / report only,” see docs/DEFECT-CATALOG.md in the repository.
Installation and Activation¶
The README states: it is a standalone package and is not registered into the profile for now. The CLI does not depend on the DSH runtime environment and requires Node >= 22, with zero runtime dependencies (only using Node built-in modules).
After cloning or extracting the repository, run in the project root directory:
npm link
You can also run directly:
node bin/dsh-session-doctor.js
When acting as a DSH cordis service plugin, the seam is in src/, and it can be registered via the profile to enable watch; it is not installed by default. Before installing any DSH plugin, you should review the source code and MIT license yourself; plugins run with the same permissions as the DSH process and the host.
Typical Usage¶
Scan and repair a single file:
dsh-session-doctor scan <sessions-root>
dsh-session-doctor scan-file <file>
dsh-session-doctor repair <file> [--dry-run]
dsh-session-doctor blame <file|root>
Take a global snapshot before acting (dry-run first, confirm, then apply):
dsh-session-doctor safeguard <sessions-root> --backup-to <backup-dir>
dsh-session-doctor safeguard <sessions-root> --backup-to <backup-dir> --apply
The sequence is fixed: cold backup → health check → repair (leaving a .bak for each file) → rescan verification. The manifest is written to <backup-dir>/doctor-backup-manifest.json.
When the GUI reports history unavailable with a tool-result block hint: use scan-file on that session file to confirm, then repair. To find out which plugin violated the render contract, use the repository script scripts/audit-render-contract.mjs <plugin-src/lib>.
Applicable Scenarios and Notes¶
| Scenario | Recommendation |
|---|---|
| History fails to load, suspect tool-result shape error | scan-file → repair |
| Worried that plugins might write bad records again | Enable watch in profile, or periodic scan |
| Suspect old sessions after DSH upgrade | Check against repository docs/PATCHES.md |
| Browser or DSH suddenly closes | blame for read-only attribution |
repair only handles the content not-an-array family mentioned above; for other corruption, rely on reports and cold backups, do not expect automatic rewriting. Long-term incremental cold backups can be used in conjunction with dsh-session-backup; safeguard focuses on the “pre-repair” in-place snapshot.
SkillHub (https://www.skillhub.cn/plugins/imtokenxinluo/dsh-session-doctor) is a community plugin directory and has no official affiliation with DeepSeek / High-Flyer. The DSH ecosystem philosophy is “everything is a plugin,” and this tool is a community supplement at the boundary of memory and session persistence, not an official built-in capability.
Conclusion¶
dsh-session-doctor transforms session corruption that “only explodes during loading” into an issue that is scannable, backable up, limitedly losslessly repairable, real-time alertable, and blame-attributable. It is suitable for developers running DSH long-term who rely on historical continuity. For details and updates, refer to the repository README.
- Community Directory: https://www.skillhub.cn/plugins/imtokenxinluo/dsh-session-doctor
- GitHub: https://github.com/imtokenxinluo/dsh-session-doctor