fix(iflow): add connection error retry logic and silent context failure detection#139
Open
MasuRii wants to merge 3 commits intoMirrowel:devfrom
Open
fix(iflow): add connection error retry logic and silent context failure detection#139MasuRii wants to merge 3 commits intoMirrowel:devfrom
MasuRii wants to merge 3 commits intoMirrowel:devfrom
Conversation
…ication Include httpx.RemoteProtocolError in the error type tuple for api_connection classification. This error occurs when a peer closes the connection without sending a complete message and should be treated as a transient connection issue rather than an unhandled exception.
…handler Wrap stream_handler in a retry loop with exponential backoff for transient connection errors (RemoteProtocolError, ConnectError, ReadTimeout, NetworkError). Retries up to 3 times with 1s/2s/4s backoff before re-raising for higher-level error handling. Changes: - Add CONNECTION_ERROR_TYPES tuple and CONTEXT_WINDOW_ERROR_PATTERNS as module-level constants for reuse and clarity - Add MAX_CONNECTION_RETRIES and RETRY_BACKOFF_BASE configuration - Restructure stream_handler with while-loop retry around the stream context manager, re-creating the stream on each retry attempt - Add context window error detection from HTTP error response bodies to surface token limit issues explicitly - Import asyncio for async sleep during backoff
- Detect empty choices array in HTTP 200 responses - Detect zero completion_tokens with non-zero prompt_tokens - Detect empty assistant messages (no content/reasoning/tool_calls) - Detect streams that complete without any data chunks - Raise non-retryable context_window_exceeded error for these cases - Prevents quota waste from repeated failed requests
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
Add robust connection error handling with retry logic and silent context failure detection for the iFlow provider, preventing quota waste from transient network issues and undetected empty responses.
Changes
stream_handlerin a retry loop with exponential backoff (1s/2s/4s) for transient connection errors (RemoteProtocolError,ConnectError,ReadTimeout,NetworkError), retrying up to 3 times before re-raisingcontext_window_exceedederrorhttpx.RemoteProtocolErrorto theapi_connectionerror type classification in the global error handlerCONNECTION_ERROR_TYPES,CONTEXT_WINDOW_ERROR_PATTERNS,MAX_CONNECTION_RETRIES, andRETRY_BACKOFF_BASEfor clarity and reuseFiles Changed
src/rotator_library/providers/iflow_provider.pysrc/rotator_library/error_handler.pyhttpx.RemoteProtocolErrortoapi_connectionclassification tuple (+6/-1 lines)Testing Instructions
Important
Enhances iFlow provider with retry logic for connection errors and detection of silent context failures, updating error classifications and constants.
stream_handleriniflow_provider.pyfor connection errors (RemoteProtocolError,ConnectError,ReadTimeout,NetworkError), retrying up to 3 times.iflow_provider.pyby checking for HTTP 200 responses with no choices, zero completion tokens, empty messages, or streams without data, raisingcontext_window_exceeded.iflow_provider.py.httpx.RemoteProtocolErrortoapi_connectionerror classification inerror_handler.py.CONNECTION_ERROR_TYPES,CONTEXT_WINDOW_ERROR_PATTERNS,MAX_CONNECTION_RETRIES, andRETRY_BACKOFF_BASEiniflow_provider.pyfor clarity and reuse.This description was created by
for a6e3024. You can customize this summary. It will automatically update as commits are pushed.