Skip to content

Accept tool call continuations without function data - #1761

Open
VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/functionless-tool-deltas
Open

VIOLETee0 wants to merge 1 commit into
CodebuffAI:mainfrom
VIOLETee0:fix/functionless-tool-deltas

Conversation

@VIOLETee0

Copy link
Copy Markdown

Problem / Why

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.

@codebuff-team

Copy link
Copy Markdown
Contributor

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.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Nov 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants