Repository navigation
fix(ollama-native): key response tool calls by native id before index - #6858
Conversation
Ollama Cloud's mistral-large-4 streams several distinct tool calls in one frame, each with its own id but all with function.index 0. The parser keyed calls by index, so the second call collided with the first and the stream failed with "changed a tool-call id for an existing index" (or "reused a tool-call index for another function" when the names differ). A valid native id is now the call's identity. Index, then position, is the fallback only for entries without an id, and a later id adopts the call that was first seen without one at the same index. Two entries in one frame share a call only when they share an id. Budget keys follow first-seen order instead of the index, so distinct calls at one index keep separate argument and metadata accounting. The parallelToolCalls:false guard is unchanged: the captured shape now reaches it and fails closed with the parallel-call error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. This PR stays in draft until every box above is ticked. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to This change lets Ollama native streams with distinct tool-call IDs sharing the same index be handled as separate calls. The parallel-call rejection when disabled remains by design. No merge-blocking risk is identified. Pre-merge checks |
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Summary
Fixes #6857.
Ollama Cloud's
mistral-large-4streams several distinct tool calls in one native frame, each with its ownid, but all withfunction.index: 0:{"message":{"role":"assistant","content":"","tool_calls":[ {"id":"PpZ8JqRmm","function":{"index":0,"name":"read_file","arguments":{"path":"/etc/hostname"}}}, {"id":"DDe4wZqkx","function":{"index":0,"name":"read_file","arguments":{"path":"/etc/os-release"}}}]},"done":false}nativeMessageEventsinsrc/adapters/ollama-native.tsusedindex:${index}as the call's identity, so the second call collided with the first. The turn then failed withchanged a tool-call id for an existing index, or withreused a tool-call index for another functionwhen the names differed.parallelToolCalls:falseguard and its feat(providers): native Ollama /api/chat transport with /api/show metadata for ollama-cloud #2863 test are unchanged. The captured shape now reaches that guard and fails closed with the parallel-call error, instead of the misleading id error.structure/providers/chat-compat.mdanddocs-site/.../reference/adapters.mddescribe the identity rule.For the maintainer: the generated catalog advertises
supports_parallel_tool_calls: falsefor Ollama models, because native adapters advertise it only on explicit opt-in (src/codex/catalog/model-hints.ts:349). Ollama's/api/chathas no field to forward that preference, and this model emits parallel calls regardless. So with default settings these turns still fail, now with the correct error. Shouldollama-nativeadvertise parallel calls by default, likeopenai-chat? I did not change that here.src/adapters/openai-chat.ts:508resolves tool calls index-first in the same way. I have no provider capture showing it collide, so it is out of scope here.Verification
Test runner: Bun 1.4.0 (
OCX_TEST_RUNNER_BUN).bun run test -- tests/providers/ollama/ --parallel=1: 155 pass, 0 fail.tests/providers/ollama/ollama-native-parser.test.ts. With the source change reverted, 10 of them fail: the captured frame (streamed and buffered), the parallel-guard error text, and the id-first identity rules. The other 7, including a later id adopting a call first seen without one, pin behavior that was already correct and must survive the change.bun run typecheck,bun run structure:check,bun run privacy:scan: pass.bun run test -- tests/providers/ tests/adapters/: 9418 pass, 13 fail. Rerun serially, 3 still fail:codebuddy-mcp-server,codebuddy-adapter(SIGTERM abort), andopenai-chat-image-normalization. All 3 fail the same way on unmodifieddev(93ed1a40b) on this host, and none touchesollama-native.bun run test: the host's load average was ~33 on 4 cores, and suite-wide 5 s timeouts made the results meaningless. Remaining coverage is left to CI.docs-sitebuild not run locally.Checklist
🤖 Generated with Claude Code
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
Required local validation passed; commands, results, and any full-suite exception are documented.
I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit