fix: proactively clear streaming queue before each request to prevent stale/empty done responses#249
Merged
CJackHwang merged 1 commit intomainfrom Nov 2, 2025
Conversation
…event stale done responses This fixes an intermittent bug where streaming API responses would return empty (done=True, no content), and subsequent requests would also return empty responses until model switch/refresh. The root cause was the STREAM_QUEUE holding leftover done signals from previous requests due to a race condition in queue clearing. - Clear stream queue at request start in _process_request_refactored - Enhance use_stream_response to ignore and log empty stale done signals - Add detailed logging for all stream/queue edge cases for diagnosis - Reduce risk of state leakage between requests; safer under heavy load No breaking changes. Existing APIs and non-streaming mode unaffected.
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
Fixes a long-standing race-condition bug where streaming API responses occasionally returned empty (done=True, no content), causing subsequent requests to also return empty responses until a model switch or page refresh.
Details
use_stream_responseto identify and ignore empty stale done signals if found as the first item in the stream