Repository navigation
Description
Description
After terminal crash and restart, resuming the session fails with:
400 Invalid assistant message: content or tool_calls must be set
The session cannot continue after resume. Recovery via /undo resolves the issue.
The crash occurred while the agent was in plan mode, mid-thinking with the last recorded thought:
"The plan is written. Let me call ExitPlanMode for approval."
The model had only emitted a ThinkPart (reasoning tokens) before the terminal died — no TextPart, no tool call. This incomplete assistant message was persisted to wire.jsonl. On session resume, convertMessage() in openai-legacy.ts strips the think content into reasoning_content but leaves content unset, producing:
{ "role": "assistant", "reasoning_content": "..." }DeepSeek rejects this with 400 Invalid assistant message: content or tool_calls must be set.
Impact
- Probability: Very low. Requires a crash during the exact thinking window before any text/tool output.
- Recovery: Session can be restored via
/undo. - Suggested action: None. The fix would require marking partial steps in
transcript.ts, which carries risk in core session logic.
Possible Root Cause
Two code paths contribute:
-
packages/agent-core/src/services/message/transcript.ts—step.beginimmediately pushes an empty assistant message (content: [], toolCalls: []) to the transcript. Ifstep.endnever arrives (crash), this partial message stays in the transcript withoutpartial: true. -
packages/kosong/src/providers/openai-legacy.ts:162-199—convertMessage()has aif (role === 'tool')guard at line 162 for tool messages, but no correspondingif (role === 'assistant')guard for assistant messages. Assistant messages fall through to the genericelsebranch (line 189) which only setscontentwhennonThinkPartsis non-empty. A think-only message producesnonThinkParts = [], leavingcontentunset.reasoning_contentis then set at line 222-224, but DeepSeek does not accept that as a substitute for the requiredcontentortool_callsfield.
The fix would be adding a fallback in the else branch:
} else {
const firstPart = nonThinkParts[0];
if (nonThinkParts.length === 1 && firstPart?.type === 'text') {
result.content = firstPart.text;
} else if (nonThinkParts.length > 0) {
result.content = nonThinkParts.map(...);
}
// missing guard:
// else if (message.role === 'assistant' && reasoningContent) {
// result.content = reasoningContent;
// }
}Reproduction
- Use a DeepSeek-architecture model with thinking enabled
- Enter plan mode, let the agent formulate a plan and start thinking about the approval step
- Crash the terminal while the model is in its thinking phase (before any text or tool call output)
- Resume the session
- Observe
400 Invalid assistant message: content or tool_calls must be seton the first API call of the resumed turn
Logs
2026-07-05T20:22:23.647Z WARN llm request failed turnStep=136.1 attempt=1/3
model=deepseek-v4-flash
errorName=APIStatusError
errorMessage="400 Invalid assistant message: content or tool_calls must be set"
statusCode=400
The error occurs <300ms after the request is sent (immediate rejection by API), confirming invalid payload structure rather than model output truncation.
wire.jsonl evidence (line 9216-9217)
step.begin, turnId=135, step=25
content.part { type: "think", think: "The plan is written. Let me call ExitPlanMode for approval." }
-- no text, no tool.call, no step.end (crash)
Affected code
| File | Issue |
|---|---|
| packages/kosong/src/providers/openai-legacy.ts:162-199 | if (role === 'tool') exists but no if (role === 'assistant') guard; assistant falls to else which skips content when nonThinkParts is empty |
| packages/agent-core/src/services/message/transcript.ts:164-172 | Partial message not marked partial: true on interrupted step |
Reference: Reasonix fix
esengine/DeepSeek-Reasonix/internal/provider/openai/openai.go:452-457 has the equivalent guard via an OR branch:
case m.Role != provider.RoleAssistant || len(cm.ToolCalls) == 0 || m.Content != "":
cm.Content = m.Contentlen(cm.ToolCalls) == 0 is the condition that catches this bug. When the assistant message has no tool calls, cm.Content is always set (even if m.Content is ""), ensuring the serialized JSON always includes the content field.
kimi-code's openai-legacy.ts lacks this fallback. Comparison:
| Scenario | esengine/DeepSeek-Reasonix | kimi-code |
|---|---|---|
| assistant, no tool_calls, has content | content: "text" | content: "text" |
| assistant, has tool_calls, has content | content: "text" + tool_calls | content: "text" + tool_calls |
| assistant, has tool_calls, empty content | tool_calls only (omit content) | tool_calls only (omit content) |
| assistant, no tool_calls, empty content | content: "" (fallback) | content unset (400) |
Note: Both Go encoding/json and JS JSON.stringify serialize "" identically to "content": "", so the same fix applies to both codebases.
Log files (auto-download)
- kimi-code.log: https://gist.githubusercontent.com/yanjin101/c442722e33ce1989f4263b2f55992fd4/raw/kimi-code.log (95 KB)
- wire.jsonl: https://gist.githubusercontent.com/yanjin101/3c008ed42602260a876c4873d791e4cd/raw/wire.jsonl (8 MB)
Activity
whyihaveyou commentedon Jul 18, 2026
Confirmed reproduction of the same failure chain, with two extensions beyond the reported scenario:
Environment: kimi-code 0.26.0 (linux/x64), session resumed via , process killed mid-turn by an external timeout.
Workaround confirmed: manually deleting the trailing incomplete assistant records from restores the session with full history intact.
Fix suggestion: on resume, sanitize trailing assistant turns that have neither content nor tool calls before serializing history (drop with a warning). This avoids touching the write path and should be lower-risk than marking partial steps in transcript.ts.
fix(agent-core-v2): drop interrupted thinking-only assistant messages…
kaidegit commentedon Aug 12, 2026
+1,在打断ds思考再回复时非常容易复现。kimi code版本0.34,macOS
fix(agent-core-v2): drop interrupted thinking-only assistant messages…
fix(agent-core-v2): drop interrupted thinking-only assistant messages…
fix(agent-core-v2): drop interrupted thinking-only assistant messages…