Skip to content

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
devin/1770920678-fix-tool-input-end-streaming
Open

fix: emit tool-input-end before tool-call in multi-chunk and flush paths#415
robert-j-y wants to merge 1 commit intomainfrom
devin/1770920678-fix-tool-input-end-streaming

Conversation

@robert-j-y
Copy link
Contributor

Description

Fixes #413. The multi-chunk tool call merge path and the flush path for unsent tool calls were missing tool-input-end events before emitting tool-call, diverging from the stream event protocol used by @ai-sdk/openai.

Before (multi-chunk path): tool-input-start → tool-input-delta… → tool-call (missing tool-input-end)
After (multi-chunk path): tool-input-start → tool-input-delta… → tool-input-end → tool-call

The flush path for unsent tool calls now also emits the full tool-input-start → tool-input-delta → tool-input-end sequence before tool-call.

Validated by comparing line-by-line against the @ai-sdk/openai reference implementation (openai-chat-language-model.ts), which consistently emits tool-input-end before tool-call in both its single-chunk and multi-chunk paths.

Key areas for review

  1. Flush path delta behavior (src/chat/index.ts flush section): When a tool call was partially streamed (deltas sent during transform) but never completed, the flush now sends tool-input-delta with 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.
  2. No dedicated unit test for flush path changes: The existing multi-chunk test covers the transform-path fix, but the new flush-path tool-input-start/delta/end emissions are only covered by the e2e test.
  3. E2e test models: The issue reported against openai/gpt-5.2; the e2e test uses openai/gpt-4.1-nano and openai/gpt-4.1-mini for availability/stability.

Checklist

  • I have run pnpm stylecheck and pnpm typecheck
  • I have run pnpm test and all tests pass
  • I have added tests for my changes (if applicable)
  • I have updated documentation (if applicable)

Changeset

  • I have run pnpm changeset to create a changeset file

Link to Devin run | Requested by @robert-j-y

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>
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.

Tool call events are buffered until stream ends (flush) causing perceived streaming delay

1 participant