dsh-resume:恢复被中断的 DSH 回合与 shutdown 时运行中的会话

前言

在 DSH Web profile 里,有两个连续性问题比较常见:回合被中断后,空提交本身不会被识别为继续;进程 shutdown 后,shutdown 时仍标记为 running 的会话和子代理也不会自动恢复。

上游 DSH 已提供 resumeSessionId、interrupted-turn closers、checkpoints 和 session persistence,但空提交继续以及按 shutdown 集合恢复会话/子代理的行为并不完整。下面介绍 dsh-resume

这是什么

dsh-resumexiaohj233 维护的 DSH 插件,许可为 MIT。当前安装示例使用版本 v0.2.1,状态为 Feature Plugin with Compatibility Patch,测试范围为 DeepSeek Harness 0.1.0-rc.6

它主要解决两件事:

  • 被中断的 DSH 对话可以通过空提交继续。
  • DSH 进程 shutdown 时记录为 running 的会话和子代理,可以在下次启动时恢复。

核心功能

空提交继续

  • 当回合被中断时,将已收到的 partial text 和 reasoning 折入 session history。
  • 支持通过 empty submit 继续被中断的 DSH 对话,而不添加可见的 “continue” 消息。
  • 使用官方 agents.resume service,并通过兼容补丁添加 partial-turn folding 和 empty-submit handling。

shutdown 后恢复

  • 将会话和子代理的活动状态记录到 ~/.dsh/resume-state.json
  • 仅恢复 shutdown 时记录为 running 的会话和子代理;completed 或 user-aborted turns 不恢复。
  • 成功恢复的会话立即原子写入并从持久化集合移除,失败恢复保留记录并在下次启动重试。
  • 启动时自动重试记录的子代理,失败条目可通过 resume_interrupted_subagents 使用。
  • 恢复诊断写入 ~/.dsh/resume-state.log

兼容补丁与版本策略

兼容补丁目标包括:

@deepseek-ai/dsh-agent-loop@0.1.0-rc.6
@deepseek-ai/dsh-session@0.1.0-rc.6
@deepseek-ai/dsh-client-ui-conversation@0.1.0-rc.6

补丁目标 hunk 幂等,并有显式 reverse operation。默认使用 adaptive 版本策略;程序化 strict 选项可恢复 exact-version-only apply 行为。

安装与启用

先添加插件:

dsh plugin --profile web add "github:xiaohj233/dsh-resume#v0.2.1"

安装后重启 Web profile。

如需覆盖配置,可以调整 profile patch 中的 dsh-resume 行:

- id: dsh-resume
  config:
    enabled: true
    restoreDelayMs: 2000

卸载与上游升级

卸载前先恢复官方包文件,再移除插件:

pnpm --dir "$DSH_HOME/profiles/web" exec dsh-resume-restore
dsh plugin --profile web remove dsh-resume

上游升级后运行 dsh-resume-restoreverify:anchors 一次,确认每个 hunk applied 或 intentionally skipped。

测试命令:

npm test
npm run check
npm pack --dry-run

兼容性

  • Node.js:^22.19.0 || >=24
  • pnpm:>=10

适用场景与注意

适合在 DSH Web profile 中遇到以下情况的用户:

  • 希望被中断的对话可以通过空提交继续。
  • 希望在进程重启后恢复 shutdown 时仍 running 的会话和子代理。
  • 希望保留恢复诊断日志,而不是只依赖上游已有 session persistence。

插件以当前 dsh 进程权限运行,安装前应检查源码、依赖和许可证。

resume-state.jsonresume-state.log 包含 session/subagent identifiers、model 和 recovery diagnostics、failure messages;不故意存储 credential values,但应作为 private runtime data。自动恢复可能发起新的 model requests,并产生 provider usage。

该插件不处理以下事项:

  • 不导入其他 agents 的 sessions。
  • 不 rewind arbitrary turns。
  • 不 migrate workspaces。
  • 不保证 remote provider 可以 byte-for-byte reproduce interrupted stream。
  • 不修复所有 upstream session-log race。

上游 DSH Discussion #420 记录了一个 dsh-resume 不声称消除的 race。

结尾

如果你的主要需求是恢复被中断的 DSH 回合,并在进程重启后恢复 shutdown 时记录为 running 的会话和子代理,dsh-resume 可以作为 DSH Web profile 的连续性补丁。

仓库地址:https://github.com/xiaohj233/dsh-resume

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye