Skip to content

fix(copilot): handle chat tool call ids#22612

Open
eigenpat wants to merge 3 commits intoanomalyco:devfrom
eigenpat:fix/nvidia-nim-tool-call-id
Open

fix(copilot): handle chat tool call ids#22612
eigenpat wants to merge 3 commits intoanomalyco:devfrom
eigenpat:fix/nvidia-nim-tool-call-id

Conversation

@eigenpat
Copy link
Copy Markdown

@eigenpat eigenpat commented Apr 15, 2026

Issue for this PR

Closes #19947

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Kimi/NVIDIA tool calls in opencode are not going through the generic @ai-sdk/openai-compatible runtime path from packages/opencode/src/provider/provider.ts. They go through the Copilot OpenAI-compatible chat runtime in packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts.

The original PR had the right normalization idea, but it fixed the wrong runtime path for this bug. The failing path was still throwing Expected 'id' to be a string. when tool_calls[].id arrived as a number or when the first streamed tool-call chunk omitted id.

This update fixes the actual runtime path by:

  • normalizing numeric tool_calls[].id values to strings in the Copilot chat path
  • generating a stable fallback id when the first streamed tool-call chunk omits id
  • adding regression coverage for both streaming and non-streaming cases

How did you verify your code works?

  • Ran bun test test/provider/copilot/copilot-chat-model.test.ts from packages/opencode
  • Ran bun typecheck from packages/opencode
  • Ran bun run build from packages/opencode

Screenshots / recordings

N/A - backend provider compatibility fix.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@zclkkk
Copy link
Copy Markdown

zclkkk commented Apr 15, 2026

Thanks this works for me

@Qiiks
Copy link
Copy Markdown

Qiiks commented Apr 20, 2026

Bump. This needs to be merged its a good fix

@rekram1-node
Copy link
Copy Markdown
Collaborator

No this is not a good or correct fix, you are editing files specifically for the github copilot provider, Why? you definitely arent using that... that doesnt make sense copilot doesnt even host this model.

Handle non-compliant chat completion responses that return numeric tool call IDs so NVIDIA NIM and similar OpenAI-compatible providers can continue through tool-call parsing.
@eigenpat eigenpat force-pushed the fix/nvidia-nim-tool-call-id branch from d5b9768 to 3743129 Compare April 21, 2026 18:32
@eigenpat eigenpat changed the title fix(provider): handle numeric tool call IDs from NVIDIA NIM kimik2.5 fix(provider): normalize numeric tool call ids for openai-compatible providers Apr 21, 2026
@eigenpat
Copy link
Copy Markdown
Author

Reworked this PR so it no longer touches the GitHub Copilot-specific fork.

The fix now lives in the generic @ai-sdk/openai-compatible path that NVIDIA NIM and similar providers actually use, and it includes regression tests for both streaming and non-streaming chat/completions responses with numeric tool call IDs.

Normalize tool call IDs in the Copilot chat runtime so OpenAI-compatible providers keep working when they send numeric IDs or omit the initial streamed ID chunk.
@eigenpat eigenpat changed the title fix(provider): normalize numeric tool call ids for openai-compatible providers fix(copilot): handle chat tool call ids Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NVIDIA NIM kimik2.5 returns numeric tool call IDs causing 'expected id to be a string' error

4 participants