Skip to content

test(openai-compat): keep complete tool calls when a stream finishes at the output limit - #10

Closed
calclavia wants to merge 58 commits into
mainfrom
test/openai-compat-length-tool-calls
Closed

calclavia wants to merge 58 commits into
mainfrom
test/openai-compat-length-tool-calls

Conversation

@calclavia

@calclavia calclavia commented Sep 23, 2026 •

Copy link
Copy Markdown

This PR only adds a failing test. It describes the behavior we want and is expected to stay red until a fix lands. The fix is the maintainer's call.

Behavior

A streamed Chat Completions response can end with finish_reason: "length" after emitting several tool calls. When that happens, some of those calls may already have complete, valid JSON arguments. Only the last one may be cut off.

Currently, makeStreamResponse skips every tool call when the finish reason is length. It emits tool-params-end for each call but no tool-call part, so the complete calls are lost along with the cut-off one.

The new test streams one complete call and one cut-off call, then ends with length. It expects:

  • a tool-call part for the complete call, with its decoded params
  • no tool-call part for the cut-off call
  • the stream to finish without an error, with finish reason length

The same situation comes up with any OpenAI-compatible endpoint that streams parallel tool calls, including OpenRouter, Vercel AI Gateway and direct vendor APIs.

Current result

AssertionError: expected [] to deeply equal [ [ 'call_complete', { input: 'kept' } ] ]

For comparison, the Responses adapter in @tardie/ai-openai already tolerates a parse error on a length finish (OpenAiLanguageModel.ts, the toolParseError reset).

🤖 Generated with Claude Code

tim-smart and others added 30 commits September 11, 2026 13:58
Co-authored-by: Xia Chao <236466140+bun-unsafe@users.noreply.github.com>
Co-authored-by: Tim Smart <hello@timsmart.co>
Co-authored-by: Tim Smart <hello@timsmart.co>
Co-authored-by: Maxwell Brown <maxwellbrown1990@gmail.com>
Co-authored-by: Xia Chao <236466140+bun-unsafe@users.noreply.github.com>
Co-authored-by: Tim Smart <hello@timsmart.co>
Co-authored-by: Tim Smart <hello@timsmart.co>
…ffect-TS#8208)

Co-authored-by: xia-chao <xia-chao@users.noreply.github.com>
Co-authored-by: Tim Smart <hello@timsmart.co>
Co-authored-by: Tim Smart <tim.smart@effectful.co>
…nd prompt titles (Effect-TS#8228)

Co-authored-by: Tim Smart <hello@timsmart.co>
arjunkmrm and others added 27 commits September 14, 2026 13:43
fix(openai-compat): accept nullable stream fields
…at the output limit

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@calclavia
calclavia requested a review from arjunkmrm September 23, 2026 08:35
@arjunkmrm

Copy link
Copy Markdown
Collaborator

Superseded by #1, now merged. That PR includes the fix and regression coverage for complete and partial tool calls at the output limit.

@arjunkmrm arjunkmrm closed this Oct 15, 2026
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.