fix: emit tool-input-end before tool-call in multi-chunk and flush paths#415
Open
robert-j-y wants to merge 1 commit intomainfrom
Open
fix: emit tool-input-end before tool-call in multi-chunk and flush paths#415robert-j-y wants to merge 1 commit intomainfrom
robert-j-y wants to merge 1 commit intomainfrom
Conversation
Fixes #413. The multi-chunk tool call merge path and the flush path for unsent tool calls were missing the tool-input-end event before tool-call, diverging from the stream event protocol used by @ai-sdk/openai. Changes: - Multi-chunk merge path: add tool-input-end before tool-call - Flush path: emit full tool-input-start/delta/end sequence for unsent tools - Update existing test expectations to match corrected protocol - Add e2e regression test for issue #413 Co-Authored-By: Robert Yeakel <robert.yeakel@openrouter.ai>
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.
Description
Fixes #413. The multi-chunk tool call merge path and the flush path for unsent tool calls were missing
tool-input-endevents before emittingtool-call, diverging from the stream event protocol used by@ai-sdk/openai.Before (multi-chunk path):
tool-input-start → tool-input-delta… → tool-call(missingtool-input-end)After (multi-chunk path):
tool-input-start → tool-input-delta… → tool-input-end → tool-callThe flush path for unsent tool calls now also emits the full
tool-input-start → tool-input-delta → tool-input-endsequence beforetool-call.Validated by comparing line-by-line against the
@ai-sdk/openaireference implementation (openai-chat-language-model.ts), which consistently emitstool-input-endbeforetool-callin both its single-chunk and multi-chunk paths.Key areas for review
src/chat/index.tsflush section): When a tool call was partially streamed (deltas sent duringtransform) but never completed, the flush now sendstool-input-deltawith the full accumulated input. This overlaps with the partial deltas already sent. This matches the reference implementation's approach but reviewers should verify this is acceptable.tool-input-start/delta/endemissions are only covered by the e2e test.openai/gpt-5.2; the e2e test usesopenai/gpt-4.1-nanoandopenai/gpt-4.1-minifor availability/stability.Checklist
pnpm stylecheckandpnpm typecheckpnpm testand all tests passChangeset
pnpm changesetto create a changeset fileLink to Devin run | Requested by @robert-j-y