You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using deepseek-v4-flash-free model, the upstream DeepSeek API occasionally returns malformed tool_calls objects in the response. Opencodex validates these strictly and rejects the entire response with "upstream response contained invalid tool calls".
This has caused 43+ failures today (2026-08-11) alone, disrupting conversations.
Root Cause
In src/adapters/openai-chat.ts (lines ~1144-1160), the validation does:
DeepSeek sometimes returns tool_call entries with missing id, name, or arguments fields, or non-string values for these fields. The current code rejects the entire response when any single tool call is malformed, instead of skipping just that entry.
Reproduction
Use deepseek-v4-flash-free with a reasoning effort of high/xhigh/max. The error occurs intermittently (not every request).
Proposed Fix
Skip malformed tool calls with a warning log instead of rejecting the whole response:
for(constrawToolCallofrawToolCalls){if(!isRecord(rawToolCall)||!isRecord(rawToolCall.function)){console.warn("[opencodex] skipping malformed tool call (not a record):",JSON.stringify(rawToolCall));continue;}constid=rawToolCall.id;constname=rawToolCall.function.name;constargs=rawToolCall.function.arguments;if(typeofid!=="string"||typeofname!=="string"||typeofargs!=="string"){console.warn("[opencodex] skipping malformed tool call (invalid field types): id=",typeofid,"name=",typeofname,"args=",typeofargs);continue;}events.push({type: "tool_call_start", id, name });events.push({type: "tool_call_delta",arguments: args});events.push({type: "tool_call_end"});}
Also keep the !Array.isArray(rawToolCalls) check as-is since that indicates a fundamentally broken response structure.
Impact
Reduces errors from ~43/day to near-zero for this model
Malformed entries are skipped rather than crashing the conversation
Existing behavior for well-formed responses is unchanged
Thanks for taking the time to submit this issue. It was closed automatically because it was not opened with a recognized issue template (Bug report, Feature request, Documentation, or Provider compatibility). Freeform and API-opened issues cannot skip this check.
This looks like a bug report but it does not use the Bug report template headings (for example Description/Log entry instead of Summary).
Please edit the issue to add:
Use the Bug report template, or edit this issue to include: Client or integration, Summary, Reproduction, Version, and Operating system.
Retitling with [Bug]: and applying the bug label alone is not enough without those section headings filled in.
Activity
github-actions commentedon Aug 11, 2026
Issue closed: use an issue template
Thanks for taking the time to submit this issue. It was closed automatically because it was not opened with a recognized issue template (Bug report, Feature request, Documentation, or Provider compatibility). Freeform and API-opened issues cannot skip this check.
Please edit the issue to add:
[Bug]:and applying thebuglabel alone is not enough without those section headings filled in.See the Contributing guide for details.
Once the report passes the automated checks, it will be reopened automatically unless a maintainer has changed its state.