Repository navigation
fix(hume): don't retry 4xx errors such as an invalid API key - #8148
Open
omChauhanDev wants to merge 1 commit into
Open
omChauhanDev wants to merge 1 commit into
omChauhanDev wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Problem
ChunkedStream._runturns every failure except a timeout into a retryableAPIConnectionError. That includes theClientResponseErrorfromraise_for_status(), so when Hume rejects a request (401 for a bad API key, 400 or 422 for a request it can't process) the status is dropped and the framework sends the same request three more times. With the default connect options that's four requests and about 4 s of retries per sentence, all logged as connection errors, and the caller getsAPIConnectionError('Connection error.'), marked retryable, with no status code. Hume's own in-stream error line ("type": "error") is wrapped the same way, so its message only shows up in__cause__.Changes
_runnow checksresp.statusinside theasync with. If theAPIStatusErrorbuilt bycreate_api_error_from_httpisn't retryable, it's raised as is, so a 401 fails after one request withstatus_code=401. Retryable statuses (408, 429, 499, 5xx) still go throughraise_for_status()and are retried as before.APIErrors raised by the plugin itself, including the in-stream error, are re-raised instead of being wrapped as connection errors.