Skip to content

adds stream disconnect handler for streaming calls#1298

Merged
akshaydeo merged 1 commit into
01-09-adds_ts_integration_testsfrom
01-09-adds_stream_disconnect_handler_for_streaming_calls
Jan 11, 2026
Merged

adds stream disconnect handler for streaming calls#1298
akshaydeo merged 1 commit into
01-09-adds_ts_integration_testsfrom
01-09-adds_stream_disconnect_handler_for_streaming_calls

Conversation

@akshaydeo
Copy link
Copy Markdown
Contributor

@akshaydeo akshaydeo commented Jan 9, 2026

Improved Stream Cancellation Handling for Client Disconnects

This PR adds proper handling of client disconnections during streaming operations across all providers. When a client disconnects mid-stream, the system now properly cleans up resources and updates log status from "processing" to "error" with a 499 status code.

Changes

  • Added HandleStreamCancellation utility function in providers/utils to standardize client disconnect handling
  • Implemented context cancellation checks in all provider streaming implementations
  • Added deferred cleanup handlers that detect context cancellation and trigger proper error reporting
  • Added context checks before processing each stream chunk to exit early when clients disconnect
  • Fixed request type tracking for proper cleanup in OpenAI's responses-to-chat fallback mode

Type of change

  • Bug fix
  • Feature

Affected areas

  • Core (Go)
  • Providers/Integrations

How to test

  1. Start a streaming request with any provider
  2. Disconnect the client mid-stream (close browser tab, terminate connection)
  3. Verify logs show proper error status with 499 code
  4. Check that resources are properly released
# Core/Transports
go test ./core/providers/...

Breaking changes

  • No

Security considerations

This change improves resource management by ensuring proper cleanup when clients disconnect unexpectedly, preventing potential resource leaks.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go and UI)

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

2 participants