Skip to content

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

Description

@xiaoyuCR7

Describe the bug

On the OpenAI Chat Completions stream parser, a tool call that has already been buffered is discarded when the next line is data: [DONE] and no chunk has carried a finish_reason yet. The agent then continues 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.

The same parser treats a closed connection differently: end-of-stream falls out of the tool-call loop and still emits the buffered call. [DONE], which is the normal terminal sentinel, leaves via break 'outer in response_to_streaming_message (crates/oi-kit-provider-types/src/formats/openai.rs) and never reaches that emit.

This is not #13637. That report is a text stream that ends with neither [DONE] nor finish_reason and is accepted as a completed turn. Here the stream does send [DONE], and the tool call is dropped.


To Reproduce

Feed these two SSE lines to response_to_streaming_message. No model is required.

data: {"id":"x","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"call_1","type":"function","function":{"name":"shell","arguments":"{\"command\":\"echo hi\"}"}}]},"finish_reason":null}]}

data: [DONE]

The parsed result contains no shell tool request.


Expected behavior

[DONE] should end tool-call accumulation and emit the call that was already buffered, the same way a naturally ended stream does. If the arguments are still incomplete, the existing argument-parse error should surface so the model can retry. The call should not disappear.

A stream that sends finish_reason: "tool_calls" and then [DONE] should keep working as it does today.


Screenshots

Not applicable. This is a parser behavior, reproduced from the stream fixture above on current main (03a343f).


Please provide the following information

  • OS & Arch: Windows 11 x64 (the parser bug is not OS-specific)
  • Interface: CLI, and any client using the OpenAI Chat Completions engine
  • Version: main at 03a343f
  • Extensions enabled: not relevant; the tool call never leaves the parser
  • Provider & Model: custom provider, "engine": "openai"

Additional context

I would like to fix this myself. Please leave it with me so it is not picked up by someone else. I will wait until the issue is Ready on the Goose Issues board before opening a pull request, and the change will stay within the direction above: treat [DONE] during tool-call accumulation as the end of the stream, not as a reason to discard the buffered call. A regression test should cover a complete tool delta followed by [DONE] with no finish_reason.

Activity

  1. added theissue type on Nov 24, 2026
  2. four1er commented on Nov 24, 2026

    @four1er
    Contributor

    I am reproducing this now and preparing a PR: data: [DONE] after a buffered tool-call delta should emit the buffered call instead of dropping it (same as the end-of-stream path in response_to_streaming_message). Will link the PR here shortly.

  3. xiaoyuCR7 commented on Nov 24, 2026

    @xiaoyuCR7
    Author

    @four1er Thanks for looking. I'm the reporter, and I already have the fix ready. I'm waiting to hear from a maintainer before opening the PR, since external PRs need the issue to be Ready. Please don't open a competing PR.

  4. moved this from Inbox to Ready in Goose Issueson Nov 30, 2026
  5. jbg commented on Nov 30, 2026

    @jbg
    Collaborator

    Thanks to both contributors. The two patches make the same parser change, so let’s proceed with #13788, which was opened first. The scope is to emit buffered tool calls when [DONE] arrives before finish_reason, preserve the existing parse error for incomplete arguments, and keep the normal finish_reason and text-only paths covered.

  6. added a commit that references this issue on Nov 30, 2026
    61d77ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions