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
{{ message }}
Repository navigation
Maka crashes with 'Operation failed' when OpenAI-compatible gateway streams tool_calls with non-zero index #1967
Maka crashes with "未知错误 / Operation failed" mid-stream whenever a custom OpenAI-compatible connection streams tool calls whose index is not contiguous from 0. Reproduces 100% with an OpenAI-compatible gateway that translates Anthropic streaming to OpenAI chat-completions format.
Environment
Maka desktop (Electron, com.maka.desktop)
Connection type: "自定义中转站(OpenAI Chat)" (Custom relay, OpenAI Chat-compatible), i.e. /v1/chat/completions
Model: claude-opus-4-8 (via gateway)
Bundled SDK: @ai-sdk/openai-compatible 3.0.12, ai 7.0.31 (extracted from app.asar)
Reproduction
Configure a custom OpenAI Chat-compatible connection pointing at a gateway that emits streamed tool_calls with non-zero-starting indices (e.g. an Anthropic→OpenAI streaming translator that uses the Anthropic content-block index as the OpenAI tool_calls[].index).
Start an agent-mode conversation so the model emits a text block followed by a tool_use block.
The gateway emits choices[0].delta.tool_calls[0].index = 1 (text block consumed index 0).
Maka's stream errors out with "Operation failed" / "未知错误 / 已保留部分输出".
Root cause
@ai-sdk/openai-compatible 3.0.12's StreamingToolCallTracker (in @ai-sdk/provider-utils):
It writes tool calls into the array by their reported index (this.toolCalls[1] = ...), leaving slot 0 as an empty hole. Then flush() iterates the array and reads toolCall.hasFinished on every entry — the empty slot is undefined, so it throws:
TypeError: Cannot read properties of undefined (reading 'hasFinished')
at StreamingToolCallTracker.flush (@ai-sdk/provider-utils/dist/index.js:3570)
at Object.flush (@ai-sdk/openai-compatible/dist/index.js:896)
OpenAI's spec says tool-call indices start at 0 and increment by 1, but real-world gateways (Anthropic→OpenAI translators, aggregators, load balancers) do not always guarantee contiguous indices. The tracker should tolerate gaps (skip null/undefined entries in flush, or use optional chaining) — other clients (e.g. opencode's built-in openai-compatible parser) do exactly that and never crash on the same stream.
Impact
Any tool call in agent mode through such a gateway fails the entire turn. Pure-text turns work; models that don't emit tool_use blocks never trigger it.
Expected behavior
Streamed tool calls with non-contiguous or non-zero indices should be handled gracefully (skip empty slots), not crash the whole stream.
The crash came from @ai-sdk/provider-utils: StreamingToolCallTracker stores tool calls at this.toolCalls[index], so a gateway starting at index: 1 leaves a hole at 0, and flush() walks the array with for...of, which does not skip holes the way forEach would. Your diagnosis was exactly right.
Since upstream still ships the same flush() in the latest release, maka now carries a patch for it (patches/, applied during install). A regression test drives the real provider stack over a gateway streaming indices 0, 1, and 7, plus two tool calls across a hole, so this stays fixed whether or not upstream picks it up. Reported there as vercel/ai#18333.
One thing worth flagging for your gateway: if it ever labels two distinct tool calls in one turn with the same index, they still merge silently into one call with concatenated arguments. That is a separate upstream defect, tracked in #1976. A translator that maps Anthropic content-block indices should not hit it, since those are unique per block.
Activity
fix: keep streamed tool calls alive when a gateway skips index 0
Astro-Han commentedon Aug 3, 2026
Fixed in #1971, shipping in the next build.
The crash came from
@ai-sdk/provider-utils:StreamingToolCallTrackerstores tool calls atthis.toolCalls[index], so a gateway starting atindex: 1leaves a hole at 0, andflush()walks the array withfor...of, which does not skip holes the wayforEachwould. Your diagnosis was exactly right.Since upstream still ships the same
flush()in the latest release, maka now carries a patch for it (patches/, applied during install). A regression test drives the real provider stack over a gateway streaming indices 0, 1, and 7, plus two tool calls across a hole, so this stays fixed whether or not upstream picks it up. Reported there as vercel/ai#18333.One thing worth flagging for your gateway: if it ever labels two distinct tool calls in one turn with the same
index, they still merge silently into one call with concatenated arguments. That is a separate upstream defect, tracked in #1976. A translator that maps Anthropic content-block indices should not hit it, since those are unique per block.中文
已在 #1971 修复,下个构建生效。
崩溃来自
@ai-sdk/provider-utils:StreamingToolCallTracker把工具调用按this.toolCalls[index]存放,网关从index: 1开始就会在 0 号位留下空洞,而flush()用for...of遍历数组,不像forEach那样跳过空洞。你的判断完全正确。上游最新版本仍然是同一份
flush(),所以 maka 自带了一个补丁(patches/,安装时应用)。回归测试通过真实的 provider 链路驱动网关,覆盖 index 0、1、7 以及跨空洞的两个工具调用,因此无论上游是否采纳,这个问题都不会回来。上游已报为 vercel/ai#18333。另外提醒一点:如果你的网关在同一轮里给两个不同的工具调用标了相同的
index,它们仍会被静默合并成一个调用、参数首尾拼接。这是另一个上游缺陷,记录在 #1976。按 Anthropic content-block index 映射的翻译网关不会踩到,因为那些 index 每个 block 唯一。fix: keep streamed tool calls alive when a gateway skips index 0 (apa…
fix(runtime): require index and id to agree on tool call identity
fix(runtime): key streamed tool calls on id instead of index
fix(runtime): require index and id to agree on tool call identity
fix(runtime): agree on every alias a tool call delta carries
fix(runtime): keep a tool call's wire aliases apart from the id it emits
fix(runtime): let a tool call record learn an alias that arrives late
fix(runtime): stop resolution at the call an alias currently claims
fix(runtime): read a blank tool call field as absent, not as a new id…
fix(runtime): a blank tool call alias is not a claim
docs(patches): record what the value-domain enumeration measured
fix(runtime): key streamed tool calls on id instead of index
fix(runtime): require index and id to agree on tool call identity
fix(runtime): agree on every alias a tool call delta carries
fix(runtime): keep a tool call's wire aliases apart from the id it emits
fix(runtime): let a tool call record learn an alias that arrives late
fix(runtime): stop resolution at the call an alias currently claims
fix(runtime): read a blank tool call field as absent, not as a new id…
fix(runtime): a blank tool call alias is not a claim
docs(patches): record what the value-domain enumeration measured
fix(runtime): resolve a streamed tool call delta against the aliases …