Skip to content

fix(openai): normalize streamed stop responses with tool calls - #360

Open
akirarat wants to merge 1 commit into
charmbracelet:mainfrom
akirarat:codex/fix-openai-stop-tool-stream
Open

akirarat wants to merge 1 commit into
charmbracelet:mainfrom
akirarat:codex/fix-openai-stop-tool-stream

Conversation

@akirarat

Copy link
Copy Markdown

OpenAI-compatible streams can return tool calls with finish_reason: "stop". Previously, the adapter published completed tool calls followed by a normal stop. The streaming agent then recorded those calls without dispatching them or continuing. Malformed or empty arguments could also pass through this path as a successful stop.

Validate all accumulated tool arguments before finalizing this response shape. Normalize valid calls to FinishReasonToolCalls; reject malformed or empty arguments with the existing retryable incomplete-stream error before publishing ToolInputEnd, ToolCall, or a successful finish. The existing guards for truncated and abnormal finishes remain in place.

The new mock-stream regressions cover valid, malformed, and empty arguments, plus agent-level dispatch and continuation. Applying only these tests to the base commit reproduces the failures; all pass with this change.

Validation:

  • go test ./... -count=1 -timeout=10m
  • go build ./...
  • golangci-lint run using CI's v2.13.2: zero issues
  • Formatted with gofumpt; git diff --check passed

Additional check: standalone builds in examples and examples/structured-outputs request go mod tidy before compilation. Both failures also reproduce on unchanged main; this patch does not modify their module files.

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features). Not applicable: bug fix.

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