Skip to content

fix: allow null function.name in streaming tool calls for OpenAI-compatible providers - #26433

Closed
xxiaoxiong wants to merge 3 commits into
anomalyco:devfrom
xxiaoxiong:fix/allow-null-function-name-in-streaming-tool-calls
Closed

fix: allow null function.name in streaming tool calls for OpenAI-compatible providers#26433
xxiaoxiong wants to merge 3 commits into
anomalyco:devfrom
xxiaoxiong:fix/allow-null-function-name-in-streaming-tool-calls

Conversation

@xxiaoxiong

Copy link
Copy Markdown

Description

Fixes #26412

This PR resolves the Expected 'function.name' to be a string error when using custom OpenAI-compatible providers (vLLM, LM Studio, llama.cpp server, etc.) that send function.name: null in streaming tool call chunks.

Problem

Per the OpenAI streaming API spec, function.name is only required in the first chunk of a tool call; subsequent chunks may send name: null. However, some OpenAI-compatible providers send name: null even in the first chunk, then send the actual name in later chunks.

The current code strictly validates that function.name must be present when creating a new tool call (first chunk for a given index), causing all tool calls to fail with these providers.

Solution

This PR makes the validation more lenient to match the behavior of the OpenAI Python SDK and other clients:

  1. Remove strict validation: Don't throw an error if function.name is null in the first chunk
  2. Defer event emission: Only send tool-input-start event when name is available
  3. Late name updates: If name arrives in a later chunk, update the tool call and send the tool-input-start event at that point
  4. Maintain correctness: Tool calls still require a valid name before completion (checked at line 623)

Changes

Modified file: packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts

  • Lines 548-553: Removed strict function.name validation, replaced with conditional tool-input-start emission
  • Line 565: Changed name: toolCallDelta.function.name to name: toolCallDelta.function?.name ?? ""
  • Lines 610-621: Added logic to update name when it arrives in later chunks

Testing

This fix enables OpenCode to work with:

The change is backward-compatible: providers that send name in the first chunk (OpenAI, Anthropic via compatibility layer, etc.) continue to work as before.

Related Issues

xxiaoxiong added 3 commits May 9, 2026 08:38
The SessionPromptData type was missing the 'format' field that exists
in the OpenAPI spec. This field allows users to specify structured
output formats (text or json_schema) when sending prompts.

Added missing types:
- OutputFormatText: for plain text output
- OutputFormatJsonSchema: for JSON schema-based structured output
- OutputFormat: union type of the above
- format?: OutputFormat field in SessionPromptData.body

This allows TypeScript users to use the format parameter without
type errors, matching the actual API behavior.

Fixes #26408
GitHub Actions bot comments were using the old hardcoded URL format
'https://opencode.ai/s/<id>' which now 404s. The canonical share URL
format is now 'https://opncd.ai/share/<id>' and is returned by the
share API.

Changes:
- Capture the full share URL from sessionShare.share() result
- Use the returned URL directly in comments and links
- Extract share ID from URL for social card image generation
- Update both packages/opencode/src/cli/cmd/github.ts and github/index.ts

Before:
  shareId = session.id.slice(-8)
  link = `${shareBaseUrl}/s/${shareId}`

After:
  shareUrl = result.url  // e.g. 'https://opncd.ai/share/xxx'
  link = shareUrl

Fixes #26417
…atible providers

Per OpenAI streaming spec, function.name may be null in non-first chunks.
Some OpenAI-compatible providers (vLLM, LM Studio, llama.cpp server) send
name: null even in the first chunk, causing 'Expected function.name to be
a string' errors.

Changes:
- Remove strict function.name validation on first chunk
- Allow creating tool calls with empty name
- Update name when it arrives in later chunks
- Send tool-input-start event only when name is available

This makes OpenCode compatible with more OpenAI-compatible providers while
maintaining correct behavior for providers that follow the spec strictly.

Fixes #26412
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 9, 2026
@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 9, 2026
@github-actions github-actions Bot closed this May 9, 2026
@dfischer-mw

Copy link
Copy Markdown

I would be very grateful for this to be re-opened and merged as it fixes a very important problem with currently 12 open parallel issues.

@Stee-T

Stee-T commented May 20, 2026

Copy link
Copy Markdown

This bug prevents me from using any local agents (Qwen3.6) via LM Studio on Windows 11, so I'd be grateful that this is re-opened and merged. Thanks in advance!

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.

Custom OpenAI-compatible provider: "Expected 'function.name' to be a string" on streaming tool call chunks

3 participants