Add retry with backoff for transient LLM API failures (429/5xx) - #2
Open
jaiswalakshansh wants to merge 1 commit into
Open
Add retry with backoff for transient LLM API failures (429/5xx)#2jaiswalakshansh wants to merge 1 commit into
jaiswalakshansh wants to merge 1 commit into
Conversation
LLMClient.chat() threw immediately on any non-2xx response, including HTTP 429 rate-limit errors. Findings are verified in a sequential loop, so once a provider's per-minute token budget is exhausted the first call consumes it and every subsequent call fail-fasts with 429 inside the same minute. On lower API tiers this drops most findings to "LLM ERROR / could not verify" in a single burst. Wrap the request in a bounded retry loop (5 attempts) that treats 429 and 5xx (500/502/503/504/529) as transient. Backoff honours the server's Retry-After / retry-after-ms hint when present, otherwise uses exponential backoff (2s base, 60s cap) with jitter. Non-retryable errors (401/403 and other 4xx) still fail fast. Network-level IOExceptions are also retried.
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
LLMClient.chat()throws immediately on any non-2xx response, including HTTP 429 rate-limit errors, with no retry or backoff.Findings are verified in a sequential loop (
TaiEPOC,SemgrepPOC,TruffleHogPOC,PermissionCheckerPOCall callllmClient.chat(...)one flow at a time). Because there is no pacing or retry:LLM ERROR - could not verify, skipping.On lower API tiers (e.g. OpenAI Tier 1, gpt-4o = 30k TPM) a single scan can lose almost every finding to this burst. Observed on a real run: 15 findings, only 1 verified, the other 14 all
429at the same timestamp.Fix
Wrap the request in a bounded retry loop inside
LLMClient:Retry-After/retry-after-mshint when present; otherwise exponential backoff (2s base, 60s cap) with jitter.IOExceptions (timeouts, resets) are also retried.This lets the per-minute budget window reset between attempts, so findings get verified instead of being dropped. No API changes —
chat()keeps the same signature and throws the sameIOExceptiononly after retries are exhausted.Notes
java.util.concurrent.ThreadLocalRandomand existing OkHttp/Gson).Thread.sleepinterruption is surfaced as anIOExceptionwith the interrupt flag restored.mvn compile.