Skip to content

fix(openai): handle mixed content and tool call stream chunks#279

Draft
slegarraga wants to merge 1 commit into
charmbracelet:mainfrom
slegarraga:codex/openai-mixed-tool-deltas
Draft

fix(openai): handle mixed content and tool call stream chunks#279
slegarraga wants to merge 1 commit into
charmbracelet:mainfrom
slegarraga:codex/openai-mixed-tool-deltas

Conversation

@slegarraga

Copy link
Copy Markdown

Summary

  • Handle OpenAI chat-completion stream chunks that contain both delta.content and delta.tool_calls.
  • Add regression coverage so a mixed content/tool-call chunk still emits the tool input and tool call parts.

Root cause

The chat-completion stream parser used a switch over delta content vs. tool calls. When an OpenAI-compatible provider emitted both fields in the same chunk, the content branch ran and the tool-call delta was skipped.

This matches the downstream failure mode described in charmbracelet/crush#2936, where local OpenAI-compatible providers can return finish_reason: "tool_calls" with populated streamed tool-call deltas that never reach the agent loop.

Validation

  • go test ./providers/openai -run 'TestDoStream/should handle content and tool call deltas in the same chunk' -count=1
  • go test ./providers/openai -count=1
  • go test ./providers/openaicompat -count=1
  • go test ./... -count=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant