Skip to content

Improve error transparency and fix connection pool timeout#119

Merged
adambalogh merged 2 commits into
mainfrom
claude/stream-processing-errors-cwa9px
Jul 2, 2026
Merged

Improve error transparency and fix connection pool timeout#119
adambalogh merged 2 commits into
mainfrom
claude/stream-processing-errors-cwa9px

Conversation

@adambalogh

Copy link
Copy Markdown
Contributor

Summary

This PR makes two targeted fixes to improve reliability and debuggability:

  1. Surface actual exception details in image generation error responses — instead of a generic "Stream processing failed" message, the client now receives the real exception string, matching the chat streaming error path for consistency.

  2. Reduce HTTP connection pool keepalive expiry — lower the timeout from 20 minutes to 45 seconds to prevent reuse of stale connections that may have been silently dropped by the enclave's egress NAT layer.

Key Changes

  • image_generation.py: Modified the exception handler in the generate() streaming function to include str(e) in the error payload sent to clients. This provides better visibility into actual failures (e.g., provider API errors, network issues) in browser-side logs, rather than an opaque generic string. The change aligns error reporting with the chat completion streaming path.

  • llm_backend.py: Reduced keepalive_expiry from 60 * 20 (1200 seconds / 20 minutes) to 45.0 seconds in the httpx connection pool limits. Added detailed comment explaining the rationale: gvproxy's NAT flow expiry and the enclave's silent connection termination (no FIN packet) can cause httpx to reuse dead connections, leading to RemoteProtocolError on the first request after an idle gap. A shorter expiry mitigates this by forcing periodic reconnection.

Implementation Details

  • Error payload now uses str(e) or "Stream processing failed" to gracefully fall back if the exception has no string representation.
  • The 45-second keepalive expiry is well under typical provider load balancer idle timeouts (~60s) and gvproxy's NAT flow expiry, reducing the window for connection reuse after silent termination.

https://claude.ai/code/session_012NXSZbLdC1sEJNmTcCszXc

Drop httpx keepalive_expiry from 20 minutes to 45 seconds so pooled
provider connections are not reused after upstream load balancers or
gvproxy's NAT have silently dropped them — the source of intermittent
RemoteProtocolError failures on the first request after an idle gap.

Also include the real exception message in the image-generation SSE
error frame (matching the chat streaming path) instead of a hardcoded
generic string, so clients can see the actual cause.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012NXSZbLdC1sEJNmTcCszXc
@adambalogh adambalogh marked this pull request as ready for review July 2, 2026 13:36
@adambalogh adambalogh merged commit 8217092 into main Jul 2, 2026
7 checks passed
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