Repository navigation
Preserve streamed text and tool args for nullable delta.role and tool call id - #8333
Merged
tim-smart merged 4 commits intoSep 21, 2026
Conversation
Accept OpenAI-compatible streaming chunks that encode `delta.role` as null,
and tool call continuation fragments that encode `tool_calls[].id` as null.
Cloudflare Workers AI emits both on any tool-enabled request: `role: null` on
text deltas, and the tool call id only on the opening fragment with `id: null`
on every continuation. Either makes the whole chunk an
`UnknownChatCompletionEvent`, so `delta.content` is skipped and tool arguments
never accumulate — the caller sees empty text, or a tool invoked with `{}`,
with no error raised.
🦋 Changeset detectedLatest commit: b945eca The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
tim-smart
enabled auto-merge (squash)
September 21, 2026 02:30
Merged
arrudaricardo
pushed a commit
to arrudaricardo/effect
that referenced
this pull request
Sep 23, 2026
… call id (Effect-TS#8333) Co-authored-by: Tim Smart <[email protected]>
1 of 5 tasks
This branch had an error being deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
delta.roleasnulltool_calls[].idasnull@effect/ai-openai-compatRoot cause
The streaming chunk schema requires
delta.roleandtool_calls[].idto be strings whenever present. Cloudflare Workers AI sendsrole: nullon text deltas, and sends a tool call id only on the opening fragment withid: nullon every continuation.Either shape makes the whole chunk an
UnknownChatCompletionEvent, sodelta.contentis skipped and tool arguments never accumulate past the opening fragment. The caller sees empty text, or a tool invoked with{}and aMissing keyparameter error, with nothing raised at the transport level. The non-streaming path surfaces a loudInvalidOutputErrorfor the same provider, which makes the streaming silence easy to misread as a model problem.This is the same class as #7268 (
tool_calls: null, Inception Mercury) and the existingfunction.name: nullhandling for Fireworks.Reproduction
Streaming
@cf/zai-org/glm-5.3-flashthrough Cloudflare's OpenAI-compatible endpoint (/accounts/{id}/ai/v1/chat/completions), countingdeltashapes across the stream:delta.roletool_calls[].idstream_options.include_usage@cf/meta/llama-3.3-70b-instruct-fp8-fastThe trigger is simply having a standard
toolsarray in the request; the provider's plain streaming is spec-correct. It is also model-specific rather than account-wide.Notes
Only the schema needed widening. The consumer side already tolerates both:
deltaTool.idis read throughactiveToolCall?.id ?? deltaTool.id ?? ..., anddelta.roleis not read by the stream handler.ChatCompletionMessage.roleis deliberately left alone. The non-streaming responses from this provider all carry"assistant", so there is no observed case to justify widening it.Validation
pnpm vitest run packages/ai/openai-compat/test/OpenAiClient.test.ts(15 tests pass)UnknownChatCompletionEventpnpm --filter @effect/ai-openai-compat checkpnpm lint -- packages/ai/openai-compat/test/OpenAiClient.test.ts packages/ai/openai-compat/test/OpenAiLanguageModel.test.tsCloses EFF-1454