[Bug] A crashed tool call leaves an unresolved tool_use in history; the session then fails forever with "DeepSeek Messages tool calls need immediate results" #7318
Replies: 3 comments
|
Confirmed on Linux, DSH 0.1.6-alpha.2 ( One data point on the crash-vs-error distinction: We recovered the poisoned session by hand, replaying exactly what
After that the session resumes and new turns complete normally. Obviously this is surgery on a durable log, not a supported path — but it confirms the repair events themselves are accepted by the v3 validators and the runtime invariant checks, so extending the crash-repair pass to error-terminated turns with pending calls should be a safe fix. |
Root cause confirmed + one-line fix (PR channel is disabled on this repo, so posting it here)I can confirm the crash root cause for both dispatch paths reported above ( export const TOOL_RUNTIME_SCHEDULER: unique symbol = Symbol('@deepseek-ai/dsh-tools.scheduler')
Fix (one line): export const TOOL_RUNTIME_SCHEDULER: unique symbol = Symbol.for('@deepseek-ai/dsh-tools.scheduler')
I tried to open a PR, but pull requests are disabled on this repository, so the patch is available as a branch:
Verified locally: macOS (arm64) source build, |

Uh oh!
There was an error while loading. Please reload this page.
Environment
0.1.6-alpha.2, macOS arm64deepseek-official, modeldeepseek-flash, reasoning efforthighSummary
When a turn dies while a tool call is in flight, the unfinished call stays in
the session history as a
tool_usewith no result. DeepSeek Messagesserialization then rejects every later turn with
DeepSeek Messages tool calls need immediate results(INVALID_REQUEST),so the session can never recover. Only opening a brand-new session helps.
Steps to reproduce (logic-level)
ask_user_questionis available.ask_user_questionand let that turn crash for anyreason (we hit
Cannot read properties of undefined (reading 'prepare');any equivalent crash should do).
Observed behavior
Every subsequent turn fails instantly with
INVALID_REQUEST, before any newtool call is made. Evidence from
session.v3.jsonl:tool/callask_user_question(callIdcall_00_rcuMRho9x0wEYkT0YVOd2872) has no matching tool result;assistant/attemptentries fail withINVALID_REQUEST.Root cause
packages/llm/llm-deepseek/src/protocols/messages/serialize.ts:117throwswhenever any pending tool call is serialized, and
:121throws when historyends with unresolved tools. There is no cleanup path for a tool call whose turn
crashed, so the dangling call permanently violates the "immediate results"
invariant.
Suggested fix
When a turn ends in error with unfinished tool calls, truncate or finalize
those calls (or offer a "truncate history" action) so the session can continue.
Related (context)
While reproducing we also saw
Cannot read properties of undefined (reading 'prepare')in tool scheduling (
packages/core/tools/src/ptc.ts:615). ChangingTOOL_RUNTIME_SCHEDULERfromSymbol(...)toSymbol.for(...)inpackages/core/tools/src/index.ts:463fixed it locally; mentioning in case itis a real cross-instance issue rather than an artifact of our self-built copy.
All reactions