Leeminjing/dsh-messages-sanitizer

Plugin插件 Native原生 ⭐ 4 MIT Sessions & Context会话与上下文

DeepSeek 防护插件:自动修复消息数组中的无效 tool_calls/tool 消息配对,防止 400 INVALID_REQUEST 会话崩溃。

Project Overview项目介绍

This is a native plugin built exclusively for DeepSeek Harness, designed to resolve persistent session freezes caused by invalid message arrays after unexpected tool call crashes. When an unexpected tool scheduling crash leaves orphan unpaired tool_calls in the session history, every subsequent API request will return a 400 INVALID_REQUEST error, locking the entire session and preventing any further conversation. The plugin automatically sanitizes and corrects the messages array to bring it into compliance with OpenAI's tool call protocol requirements, allowing the conversation to resume normally right after the crash.

The plugin uses a four-layer defense system to handle invalid messages across different unexpected crash scenarios: auto-resume, pre-request prevention, error healing, and fallback sanitization. It complements the official source code fix released by the DeepSeek Harness team, working as an additional safety net that does not require modifying DSH source code to operate correctly. It automatically fixes messages at runtime, can rescue older already corrupted sessions, and lets users continue their work without waiting for a new official DSH release to fix the issue.

Installation is done via a single DSH CLI command, and the plugin activates automatically after restarting DSH, with a simple configuration toggle to enable or disable it. It is a zero-build pure ESM module that loads directly via the cordis loader, uses core dependencies already included in the DSH runtime, and requires no extra dependency installation from users. After modifying the plugin code, you only need to restart DSH to apply changes, and it ships with 40 test cases to ensure functional stability across different common use cases.

这是一个专为 DeepSeek Harness 开发的原生插件,专门解决工具调度崩溃后消息数组不合法导致的会话卡死问题。当工具调度发生异常崩溃后,会话历史会留下未配对的孤儿 tool_calls,之后每一轮请求都会触发 API 返回 400 INVALID_REQUEST 错误,导致整个会话卡死无法继续。本插件会自动矫正消息数组,让它符合 OpenAI 协议规范,恢复对话正常运行。

插件通过四层防御机制保障会话正常:自动续跑、前置预防、错误治愈、兜底矫正,针对不同场景的非法消息进行处理。它和 DeepSeek Harness 官方的源码修复互补,不需要修改 DSH 源码,就能在运行时自动修复消息,旧的已崩溃会话也能被救回,用户不需要等待 DSH 发版就能继续使用。

安装可以通过 DSH 命令行一键完成,安装后重启 DSH 即可生效,支持通过配置开关启用或停用插件。插件是零构建的纯 ESM 模块,直接由 cordis 加载器加载,依赖 DSH 运行时自带的核心包,不需要额外安装依赖,修改代码后仅需重启 DSH 就能生效,还自带 40 个测试用例保证功能稳定。

Pre-install check安装前体检Compatibility · Security兼容性 · 安全性 1 warning1 项注意
  • Only 4 stars - very few users, little community feedback星标只有 4,几乎没人在用,遇到问题缺少社区反馈
DSH walks through these 9 checksDSH 会逐条核对这 9 项

Compatibility兼容性

  • DSH, Node, OS and profile requirementsDSH 版本 / Node 版本 / 操作系统 / profile 是否满足要求
  • External dependencies and runtimes (Electron / Python / Docker, ...)外部依赖与运行时(Electron / Python / Docker 等)是否齐备
  • Conflicts with installed plugins: command names, skill / tool names, ports, duplicate MCP registration与已装插件是否冲突:命令名、skill / tool 重名、端口占用、重复 MCP 注册

Security安全性

  • Repo matches the facts registered here; archived or abandoned?仓库是否与页面登记一致,是否归档或长期停更
  • Safety of preinstall / install / postinstall and install.sh / setup.ps1preinstall / install / postinstall 与 install.sh、setup.ps1 是否安全
  • curl|bash, download-then-execute, obfuscation, unrelated domains → stop immediatelycurl|bash、下载即执行、混淆代码、无关域名 → 立刻停止
  • Typosquatting or unmaintained packages among the new dependencies新增依赖里有没有 typosquatting 或无人维护的包
  • Requested permissions vs. what the feature actually needs申请了哪些权限、是否超出功能所需(filesystem / network / shell / clipboard)
  • Any sudo / admin requirement, plus uninstall and rollback是否要求 sudo / 管理员权限,以及卸载与回滚方式

Anything uncertain must be marked unknown with a note on how to confirm it. This site's signal screen is a static snapshot, not a security audit.拿不准的必须标「未知」并说明要我怎么确认。本站的信号筛查是静态快照,不能替代安全审计。

Or use CLI install (for developers)或使用命令行安装(适合开发者)

CLI Install命令行安装

dsh plugin --profile web add github:Leeminjing/dsh-messages-sanitizer

把 Leeminjing/dsh-messages-sanitizer 加入你的 DSH 配置(web profile)即可启用。

READMEREADME

dsh-messages-sanitizer

English


⚠️ 已退役 —— dsh ≥ 0.2.0 已在运行时根治本插件要补的问题

本插件的存在前提是:工具调度崩溃会在会话里留下孤儿 tool_calls,导致之后每一轮都被 400 INVALID_REQUEST 拒绝。这个前提在 dsh 0.2.0 已不成立:

  • @deepseek-ai/dsh-agent-loop 在 step 抛错时用 ToolCallRecovery 为所有未应答的调用 合成并追加 tool/result 事件(带 TOOL_NOT_STARTED / TOOL_OUTCOME_UNKNOWN 错误码);
  • 会话恢复时 interruptedTurnClosers() 会把修复写进持久日志;
  • deriveMessages() 自身就会丢弃空 content 的 assistant 消息。

而且插件的主路径在 0.2.0 上无法实现:agent/pre-step 返回的每条消息都被循环以 session.append("user/message", …) 落盘,而会话校验强制该事件的消息 role 必须是 user——注入 tool 角色的合成结果会直接抛错。其余分层所依赖的 Session#events、 surfaceOp.{start,end}、tool-result 内容块在 0.2.0 也均已移除或改名。

结论:不要安装本插件。直接用 dsh ≥ 0.2.0。 本仓库已归档,仅作历史记录保留; npm 包已标记 deprecated。0.1.1 只对仍停留在 dsh 0.1.x 的用户有意义。


🔧 你在 DeepSeek Harness 里创建 / 加载插件,对话崩了吗?本插件专治这个。

开发或加载本地插件时,一次工具调度崩溃(Cannot read properties of undefined (reading 'prepare'))就会在会话里留下孤儿 tool_calls,之后每一轮都被 400 INVALID_REQUEST 拒绝、重试无效、会话卡死。本插件自动把 messages 数组修回 合法,让对话继续,不再卡死。

💥 Before                                ✅ After (安装本插件后)
插件崩溃                                  插件崩溃
   ↓                                        ↓
留下孤儿 tool_calls                       messages 自动修复
   ↓                                        ↓
400 INVALID_REQUEST 死循环                对话继续
   ↓
对话卡死

DeepSeek Harness 消息数组自动矫正插件:防止一切因 messages 数组不合法导致的聊天崩溃。

背景:你遇到的那个崩溃

OpenAI 兼容协议要求工具调用成对出现,且 tool 消息必须紧邻其 assistant tool_calls 消息(中间不能插入任何 user / assistant 消息):

assistant  { content: ..., tool_calls: [{ id: "call_A", ... }] }
tool       { tool_call_id: "call_A", ... }   ← 必须紧跟覆盖每个 id

当一次工具调度在「记录 assistant tool_calls / tool/call 之后、产出 tool 结果之前」 崩溃时(例如 ctx.tools[symbol].prepare 抛 Cannot read properties of undefined), 会话日志会留下一个没有 tool 消息响应的孤儿 tool_calls。下一轮请求把历史拼成:

[..., assistant{tool_calls:[write]}, user{...}]        ← 非法

API 直接返回 400 INVALID_REQUEST,且重试时历史原封不动,反复被拒,会话卡死。 如果崩溃后还有多次失败重试,日志里还会留下多条重复的 user 消息横在孤儿 assistant 与注入点之间,让"补插 tool 消息"也无法满足紧邻约束。

背景(与 DSH 官方讨论对照)

同类故障在 DeepSeek Harness 官方仓库也已被跟踪: Discussion #4843「残缺或孤立的 tool_calls 记录导致 DeepSeek 接口返回 400」 描述了「会话历史中存在无配对 result、或 id/name/arguments 残缺的 tool_calls 时,chat-completions 接口返回 400」, 并从 harness 源码层(agent-loop 剥离、llm-deepseek 合成 fallback id、compaction 的 tool-pairing 按 callId 而非计数) 给出根因修复 patch。

Showing the opening section of the README — the full document lives in the repository以上为 README 开头摘要,完整文档在仓库内 · View the full README on GitHub →在 GitHub 查看完整 README →

← 上一个 Prev dsh-tray 下一个 Next DeepSeek-Harness-Desktop →