Skip to content

fix(openai): emit buffered tool call on [DONE] (fixes #13785) - #13788

Merged
jbg merged 1 commit into
aaif-goose:mainfrom
four1er:fix/openai-done-drops-tool-call
Nov 30, 2026
Merged

jbg merged 1 commit into
aaif-goose:mainfrom
four1er:fix/openai-done-drops-tool-call

Conversation

@four1er

@four1er four1er commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #13785.

On the OpenAI Chat Completions stream parser, a tool call that had already been buffered was discarded when the next line was data: [DONE] and no chunk had carried a finish_reason yet. The agent then continued as if the model produced no tool call. This affects every custom provider with "engine": "openai" that is not routed to the Responses API, including local servers and gateways that send a complete tool delta and then [DONE] without a separate finish_reason: "tool_calls" chunk.

Fix

In response_to_streaming_message (crates/oi-kit-provider-types/src/formats/openai.rs), [DONE] no longer breaks out of the outer loop and drops the buffered call. It now exits the tool-call accumulation loop first, emitting the buffered tool call (or surfacing the argument-parse error if the arguments are still incomplete), and then breaks out — without reading anything after [DONE].

A stream that sends finish_reason: "tool_calls" and then [DONE] keeps working as before, as does a plain text stream ending with [DONE].

Tests

  • 5 new regression tests in crates/oi-kit-provider-types: [DONE] after a complete buffered tool call emits it; [DONE] truncation; finish_reason: "tool_calls" + [DONE] unchanged; incomplete tool-call arguments surface the parse error; plain text stream + [DONE] unchanged. The repro test fails on the old code and passes with the fix.
  • cargo test -p oi-kit-provider-types: 744 passed, 0 failed.
  • cargo fmt and cargo clippy -D warnings pass.

Note: end-to-end verification against a live model / local OpenAI-compatible gateway was not possible in this environment; verification is via the offline SSE fixture from the issue.

@four1er
four1er requested a review from a team as a code owner November 24, 2026 08:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T08:03:29.376862Z fda6240 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbg jbg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser now emits buffered tool calls before stopping at [DONE]. The regression tests cover fragmented arguments, incomplete arguments, a separate finish_reason frame, and text-only streams. I reviewed the diff against the agreed scope and checked the required CI results.

@jbg
jbg added this pull request to the merge queue Nov 30, 2026
Merged via the queue into aaif-goose:main with commit 61d77ab Nov 30, 2026
42 checks passed
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.

Chat Completions: [DONE] before finish_reason drops an in-progress tool call

2 participants