You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Accept tool call continuations without function data - #1761
An already-open streamed tool call can receive a continuation delta without a function payload. The OpenAI-generated chunk type makes that field optional. The compatible provider currently rejects this frame at schema validation and emits an error part, even when the next frame completes the call's valid arguments.
Making the schema accept the frame also requires guarding the existing argument-delta and index-inference reads; otherwise they dereference the absent function object.
Changes
Allow an absent or null function in the streaming delta schema and use optional access in the existing continuation and inference paths. Complete non-streamed tool calls retain their existing schema.
Add one regression through the existing SSE response fixture, real schema validation and stream converter. It sends both absent and null payloads between argument fragments, covering explicit index, id and the existing indexless fallback. It requires no error part, exactly one call with the original id/name and complete arguments, and a tool-calls finish reason.
Verification
Windows x64, Bun 1.3.14, base 0239a2772126d2c5cf99a06acf69aeddc36195a9; isolated test home, --no-env-file, and placeholder-only sdk/test/setup-env.ts preload.
bun test packages/llm-providers/src: before 41 pass, 1 fail (only the new regression fails); after 42 pass, 0 fail, 70 assertions, no skips. The final test was rerun against unchanged main to confirm the failure, then against the restored fix.
bun node_modules/typescript/bin/tsc --noEmit -p packages/llm-providers: passed.
bun node_modules/typescript/bin/tsc --noEmit -p sdk: passed.
ESLint on the two changed files: 0 errors, 5 warnings, identical to main. A Prettier comparison found the same existing formatting edits as main on both files; only the added test block and changed condition were formatted. git diff --check: passed.
Frozen-lockfile install, SDK build, Windows Freebuff binary build, binary --version and bun cli/scripts/smoke-binary.ts cli/bin/freebuff.exe: passed.
Notes / Scope
This is a source-audit contract regression without an existing issue being claimed. The existing requirement for the opening delta to name the function remains in place. The patch adds no buffering, JSON repair, dependency change or tool retry/replay.
The protocol fixture injects fetch and exercises actual SSE bytes through the parser; it does not call a live model service. Linux/macOS, live provider traffic and the full monorepo suite were not run. This is independent of #1723's compression-trailer handling in the same converter file.
Good catch and a tightly scoped fix. The OpenAI Chat Completions streaming schema does make function optional on tool-call delta chunks after the opening frame (as linked), and the existing Zod schema (createOpenAICompatibleChatChunkSchema) was requiring it unconditionally, which would reject valid continuation frames with a schema-validation error instead of accumulating arguments.
The fix itself is minimal and in the right place:
function: z.object({...}).nullish() relaxes the schema correctly, while leaving the non-streamed tool-call schema untouched as stated.
toolCallDelta.function?.arguments ?? '' and the optional chaining in inferToolCallIndex correctly guard the two call sites that dereference function after the schema change.
The added test in openai-compatible-chat-language-model.test.ts is appropriately targeted: it loops over index-based, id-based, and indexless matching, injects both absent and explicit-null function payloads mid-stream, and asserts no error part is emitted and that the final tool-call has fully concatenated arguments. That's exactly the kind of regression coverage I'd want for this kind of schema loosening.
One thing worth double-checking before porting: are there other call sites in the same file (outside this diff) that read toolCallDelta.function.name or similar without optional chaining, e.g. when first registering a new tool call in the toolCalls array? The diff only touches two reads; if there's a third read elsewhere that assumes function is present, it would need the same guard. Given the test suite passes cleanly (42/42) this is likely already fine, but worth a final grep before merging into the private tree.
Overall: correct root cause, narrowly scoped, tested, no unrelated churn.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Why
An already-open streamed tool call can receive a continuation delta without a
functionpayload. The OpenAI-generated chunk type makes that field optional. The compatible provider currently rejects this frame at schema validation and emits an error part, even when the next frame completes the call's valid arguments.Making the schema accept the frame also requires guarding the existing argument-delta and index-inference reads; otherwise they dereference the absent function object.
Changes
functionin the streaming delta schema and use optional access in the existing continuation and inference paths. Complete non-streamed tool calls retain their existing schema.Verification
Windows x64, Bun 1.3.14, base
0239a2772126d2c5cf99a06acf69aeddc36195a9; isolated test home,--no-env-file, and placeholder-onlysdk/test/setup-env.tspreload.bun test packages/llm-providers/src: before 41 pass, 1 fail (only the new regression fails); after 42 pass, 0 fail, 70 assertions, no skips. The final test was rerun against unchanged main to confirm the failure, then against the restored fix.bun node_modules/typescript/bin/tsc --noEmit -p packages/llm-providers: passed.bun node_modules/typescript/bin/tsc --noEmit -p sdk: passed.git diff --check: passed.--versionandbun cli/scripts/smoke-binary.ts cli/bin/freebuff.exe: passed.Notes / Scope
This is a source-audit contract regression without an existing issue being claimed. The existing requirement for the opening delta to name the function remains in place. The patch adds no buffering, JSON repair, dependency change or tool retry/replay.
The protocol fixture injects fetch and exercises actual SSE bytes through the parser; it does not call a live model service. Linux/macOS, live provider traffic and the full monorepo suite were not run. This is independent of #1723's compression-trailer handling in the same converter file.