Repository navigation
DeepSeek-V4-Flash 流式模式下所有工具调用报 unknown tool ""
#725
问题描述使用 工具名始终为空字符串,导致在 根本原因
// 当前写法 — 后续空字符串分块会覆盖已解析的工具名
if (call.id !== undefined) block.callId = call.id
if (call.function?.name !== undefined) block.name = call.function.name修复方案// 修复写法 — 安全累加所有分块
if (call.id !== undefined) block.callId = (block.callId ?? '') + call.id
if (call.function?.name !== undefined) block.name = (block.name ?? '') + call.function.name验证结果应用修复后, 环境: Windows 11 · DeepSeek-V4-Flash · SSE 流式传输 |
Replies: 12 comments 3 replies
|
工具名被解析成空字符串,导致任何 Skill 和工具都无法运行。 原因
解决方案修改 - if (call.id !== undefined) block.callId = call.id
- if (call.function?.name !== undefined) block.name = call.function.name
+ if (call.id !== undefined) block.callId = (block.callId ?? '') + call.id
+ if (call.function?.name !== undefined) block.name = (block.name ?? '') + call.function.name改完重新 pnpm run build 再重启 dsh 即可。 我的环境: Windows 11 · DeepSeek-V4-Flash · SSE 流式输出 |
|
这个解决方案对于hy3和longcat-2.0等模型不太适用,它们SSH流式输出时delta2的id和name会填充null,需要再补充对于null值的处理 |
|
所以我要怎么更新呢? |
|
Just a heads up: this bug also causes severe secondary damage (bricking session history). Since the tool call was persisted with an empty callId (""), when you restart and try to load the session log, it triggers a SessionPersistenceCorruptionError ("message must have tool source"). This happens because assertMessageEventShape in packages/core/session/src/index.ts strictly rejects callId === ''. So this bug not only breaks the current execution but also permanently corrupts the session file. To rescue corrupted sessions, we should relax the empty string check in packages/core/session/src/index.ts: --- packages/core/session/src/index.ts
+++ packages/core/session/src/index.ts
@@ -336,8 +336,7 @@
if (type !== 'tool/result') return
if (sourceRecord['kind'] !== 'tool'
- || typeof sourceRecord['callId'] !== 'string'
- || sourceRecord['callId'] === '') {
+ || typeof sourceRecord['callId'] !== 'string') {
throw new Error(`${subject} message must have tool source`)
}补充一个次生灾害及修复方案: 这个 Bug 会导致已经保存的历史会话完全损坏、无法加载(触发 SessionPersistenceCorruptionError)。因为带有空 callId 的异常记录被写入后,重启读取时会被 assertMessageEventShape 的严格校验拦截。要拯救已经坏档的会话,只需按上面的 Diff 移除对空字符串的限制,放宽校验即可正常载入历史脏数据。 |
|
这个根因我们也确认过(手册 FAQ 已收录): 官方修复前的规避:
排查思路和同族 bug 汇总见:https://github.com/Electricitysheep/dsh-handbook/blob/main/docs/faq.md |
|
修复如下: https://github.com/enjlife/deepseek-harness/pull/new/fix/llm-deepseek-empty-tool-name |
|
已同步:null 隐式转字符串根因 + typeof 严格校验修复方案已收录进手册 FAQ(unknown tool 条目深化),包含"官方关 PR 需自行改文件"的 workaround:https://github.com/Electricitysheep/dsh-handbook/blob/main/docs/faq.md |
|
Confirmed on current master ( A continuation delta with an empty name should not erase the established tool name. I verified the following guard: const name = call.function?.name
if (typeof name === 'string' && name.length > 0) block.name = nameVerification completed:
Reproduction test and merged patch in a fork: Constantine1916#1 |
|
我在当前 master( 确认后续 SSE 参数分片会携带
使用的保护逻辑: const name = call.function?.name
if (name !== undefined && name !== '') block.name = name |
|
快快,把这个更新发布下,今天也遇到这个问题了,让AI参考这个一下就修好了 |
#725 的描述——核心全部正确,但有一个坑
// 原作者的版本(不推荐提 PR)
if (call.id !== undefined) block.callId = (block.callId ?? '') + call.id
if (call.function?.name !== undefined) block.name = (block.name ?? '') + call.function.name问题:① 正确修法(Constantine1916/TAOLI123666 各验证过 31/31、30/30,我本地复现也 PASS)是只取首个非空值: if (typeof call.id === 'string' && call.id.length > 0) block.callId = call.id
if (typeof call.function?.name === 'string' && call.function.name.length > 0) { block.name = call.function.name }提 PR 的建议
|
|
感谢你逐项核对,也感谢你明确指出不应采用拼接 id/name 的方案。
我同意 id 和 name 是身份字段,不是累积字段;后续流式 delta 中的空字符串或 null 应视为“没有更新”,不能覆盖此前已获得的非空值。把它们拼接起来不仅语义不对,也会在 null 或重复字段出现时制造新的无效名称。
我目前在 fork 中保留了这两个防线:
- 对已建立的工具调用身份,只接受后续的非空字符串更新,忽略空字符串和 null:
Constantine1916#2
- 如果流结束时从未获得非空 id 或 name,则在最终块生成前以 MALFORMED_RESPONSE 拒绝响应,避免把无法重放的工具调用写入会话:
Constantine1916#3
我也刚核对了当前 upstream master:它仍使用“字段不是 undefined 就覆盖”的旧逻辑,因此上述修复尚未被官方合入。
你关于不应放宽 callId === '' 校验的建议我认同。存量损坏会话的恢复应另行处理,不能以降低读取端校验来掩盖写入端问题。谢谢你给出的回归用例边界和 PR 范围建议。
|
#725 的描述——核心全部正确,但有一个坑
unknown tool ""!== undefined覆盖;我本地旧逻辑复现输出{id:"",name:""}SessionPersistenceCorruptionError "must have tool source"packages/core/session/src/index.ts:336-341确实拒绝callId === '';你 demo1 的 session-9fe8ba1d 就是实例问题:①
id/name是身份字段不是累积字段,拼接语义错误——上游若是null会拼出Globnull(讨论里 chenghu17 也指出这点),若重复发非空 name 会拼出GlobGlob