- Home
- Plugins
- Sessions & Messages
- dsh-session-repair
dsh-session-repair
regularsyr7/dsh-session-repair
Diagnose and safely repair a corrupted DSH session log: raw zstd/JSONL validation, tool-call ID repair, a single-slot pre-repair backup with rollback, and an audit trail.
Install
dsh plugin --profile web add github:regularsyr7/dsh-session-repairREADME
@rainybox/dsh-session-repair
Diagnose and safely repair a corrupted DSH session log. A DSH session log is a zstd-compressed
JSONL file (session.v4.jsonl.zstd): one header line plus one event per line. Truncated writes,
half lines, duplicated headers, broken seq numbering and mismatched tool-call IDs all make the
replay drop events — a tool call then hangs on "running" forever.
This plugin exposes one host-side tool, session_repair, with three actions:
diagnose (read-only, default), repair (backup, rewrite, re-verify) and restore (roll back
from the single-slot backup).
Install
Install from npm, or straight from source:
npm i @rainybox/dsh-session-repair
# or from source:
git clone https://github.com/RegularsYr7/dsh-session-repair.git
cd dsh-session-repair
dsh plugin --profile desktop add link:$PWD
or add "@rainybox/dsh-session-repair": "link:/absolute/path/to/dsh-session-repair" to the dependencies of
~/.dsh/profiles/desktop/package.json (keep link:, not file: — file: is copied into a
frozen snapshot and later edits stop taking effect), add @rainybox/dsh-session-repair to dsh.profile.bundles,
then pnpm install and restart DSH. Client modules are only scanned when the registry is
constructed, so a new dsh.client declaration never appears on a hot reload.
Requires DSH >=0.2.2-rc.1 <0.3.0-0 and Node >=22.12.0.
TL;DR
session_repair { session_id }— diagnose only, never writes.session_repair { session_id, action: "repair" }— writes<id>.pre-repair.jsonl.zstdfirst, renames atomically, re-verifies immediately; keeps the backup if verification fails.session_repair { session_id, action: "restore" }— writes the backup back and re-diagnoses.- Every run appends one line to
$DSH_HOME/backups/session-repair/audit.jsonlwithsha256Before/sha256After, the issue list and the repair counters.
The full behaviour reference (issue codes, repair rules, backup layout) follows in Chinese.
@rainybox/dsh-session-repair
诊断并安全修复损坏的 DSH 会话历史。对应本地开发版 @rainybox/dsh-session-repair v0.1.0 声明的四项能力:raw zstd/JSONL 校验、tool-call ID 修复、单槽 pre-repair 备份与恢复、审计记录,并把它做成 harness 侧可调用的工具 session_repair。
会话日志长什么样
~/.dsh/sessions/--<cwd slug>--/session-<uuid>/session.v4.jsonl.zstd —— zstd 压缩的 JSONL:
- 首行 header:
{"type":"session","version":4,"id":"session-…","createdAt":<ms>,"cwd":"…"} - 其余每行一个事件,带
type/seq/time/data - 工具调用是
tool/call(data.callId),结果是tool/result(data.message.toolCallId,另有一份data.message.source.callId),三方必须一致
真实日志里 callId 落在 data.message.toolCallId,不是顶层 data.toolCallId;两种写法都兼容。
工具:session_repair
参数 session_id(必填,session-<uuid v4>)+ action:
| action | 行为 |
|---|---|
diagnose(默认) | 只读:解压、逐行解析、报告问题清单,不碰磁盘 |
repair | 先落单槽备份 → 重写日志 → 立即复验;复验失败保留备份并提示回滚 |
restore | 把单槽备份整份写回,并重新诊断 |
诊断覆盖:bad_json_line(截断/半行/非对象)、header_missing、header_version、header_id_mismatch、header_cwd、seq_missing、seq_discontinuity、toolcall_missing_id、toolcall_duplicate_id、toolcall_unanswered、toolresult_missing_id、toolresult_orphan、callid_source_mismatch。
修复动作:丢弃不可解析行(行号与解析错误记入审计)、补/改 header、seq 从 0 严格重编号、缺失 callId 发 call_repaired_000N、重复 callId 加 _dupN、缺 id 的结果按 turn/step 回填到尚未被回答的 call(避免两条结果挂同一 call)、message.source.callId 对齐、结果指向不存在的 callId 时改挂正确 call 并把原 id 留在 data.orphanCallId(计入 repairs.orphanResultsRerouted)、彻底找不到的可挂目标才标 data.orphan 并编号 call_orphan_000N。
repairs 计数器:seqRenumbered / headerWritten / callIdsIssued / callIdsDeduped / resultsRelinked / sourceCallIdsFixed / orphanResultsMarked / orphanResultsRerouted / droppedMalformed。
为什么孤立结果要改挂而不是留着:
tool/result指不到tool/call时,回放器会跳过这条结果, 界面上那次工具调用就永远停在"运行中"。真实损坏里 call 侧被截断、id 被改写都会造成这种孤立。
备份与审计
- 单槽备份(每次覆盖):
$DSH_HOME/backups/session-repair/<sessionId>.pre-repair.jsonl.zstd - 审计追加:
$DSH_HOME/backups/session-repair/audit.jsonl—— 每次修复一行,含sha256Before/sha256After/bytesBefore/bytesAfter/ 问题清单 / 改动计数 / 复验结果(restore 也记一行) - 写入方式:同目录临时文件 →
rename原子替换,沿用原文件权限位
用法
# 在 DSH 里(装上并在 profile 里注册后)
session_repair session_id=session-9abd676b-0275-4ec9-912c-9988f08dc1e2
session_repair session_id=session-9abd676b-… action=repair
session_repair session_id=session-9abd676b-… action=restore
本地加载验证(不启动 GUI):
cd dsh-plugins/_verify
node harness.mjs ../dsh-session-repair --call session_repair '{"session_id":"<id>"}'
DSH_HOME=/tmp/dsh-repair-test node harness.mjs ../dsh-session-repair --call session_repair '{"action":"repair","session_id":"<id>"}'
装载
package.json 的 dsh.bundle.patch 指向 cordis.patch.yml:
- insert:
- id: '@rainybox/dsh-session-repair'
name: '@rainybox/dsh-session-repair'
把包名加进 ~/.dsh/profiles/desktop/package.json 的 dsh.profile.bundles,重启 DSH 生效。
安全边界
默认 diagnose 只读;写盘只发生在 repair / restore,且 repair 必先备份、写后必复验,复验失败不改二次。备份只保留一槽(与本地开发版语义一致),需要长期保留请自己复制出去。
Related plugins
billion-context
ranxianglei/billion-context
dsh-web-ui (dsh-chat-recovery)
zhu1090093659/dsh-web-ui
dsh-synapse
liangmianya/dsh-synapse
EduWork (dsh-message-edit)
ecnu/eduwork