Skip to content

fix: proactively clear streaming queue before each request to prevent stale/empty done responses#249

Merged
CJackHwang merged 1 commit intomainfrom
debug-streaming-empty-responses-done-no-content
Nov 2, 2025
Merged

fix: proactively clear streaming queue before each request to prevent stale/empty done responses#249
CJackHwang merged 1 commit intomainfrom
debug-streaming-empty-responses-done-no-content

Conversation

@cto-new
Copy link
Copy Markdown
Contributor

@cto-new cto-new bot commented Nov 2, 2025

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

  • Proactively clears the streaming queue (STREAM_QUEUE) at the start of each request to ensure no leftover/stale done signals are read by new requests
  • Adds detection and logging in use_stream_response to identify and ignore empty stale done signals if found as the first item in the stream
  • Improves logging during queue clearing and response processing for easier troubleshooting and diagnostics
  • No changes to API or business logic surfaces; non-streaming requests remain unaffected

…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.
@CJackHwang CJackHwang merged commit ec9a4f4 into main Nov 2, 2025
@CJackHwang CJackHwang deleted the debug-streaming-empty-responses-done-no-content branch November 2, 2025 09:26
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.

1 participant