fix: handle remaining stream and tool-call edge cases after #3 - #10
Merged
thaolaptrinh merged 1 commit intoSep 9, 2026
Merged
Conversation
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
Follow-up to #3: this addresses reproducible edge cases that remain on
mainata97eb903932f2253d8ebeca2bcfabdbb47908889, which already includes that PR. It does not replace the earlier streaming/backpressure work or change authentication, model routing, deployment configuration, or supported API routes.Changes
ServerResponse.closerather than the already-completed request upload. Cancel upstream reads for disconnected SSE and JSON clients, settle backpressured writes on close/error, and avoid retrying an already-aborted caller.ReadableStreamDefaultReader.cancel()resolves a pending read as EOF; it does not reject that read. Explicitly destroy the Node stream with the idle error so the encoder's existing error/terminal-record path runs instead of an indistinguishable successful EOF. Normal successful streams retain their existing behavior.errorevent into an empty successful response.Reproduction examples on unmodified main
POST /v1/messages/count_tokenswith JSONnullreturns 500.tool-call-deltawith{"x":1}followed by the matching canonicaltool-callproduces concatenated arguments{"x":1}{"x":1}in both protocols.The automated reproductions use synthetic upstream events/credentials, native Web streams, and real loopback HTTP connections. They demonstrate specific edge cases, not that every model/request encounters these failures. In particular, this is not a claim to fix the provider-side model availability problem discussed in #7.
Verification
deepseek/deepseek-v4-flash.No real credentials, host-specific paths, private network configuration, or generated build artifacts are included. Happy to split the validation change or other independent pieces if smaller follow-up PRs would be preferred.