[INT-715] Retry transient failures when verifying OpenAI keys - #5117
Merged
Conversation
The OpenAI verification endpoint can be slow to respond under load, and a single 5s client timeout was recorded as an indeterminate verification result with no retry. Switch the default client to the common retryable client with a 10s per-attempt timeout and up to 2 retries with backoff on timeouts, connection errors, and 429/5xx responses.
Corpora Test ResultsNo detector regex or keyword changes in this PR. Bench skipped. |
martinlocklear
approved these changes
Jul 8, 2026
martinlocklear
left a comment
Contributor
There was a problem hiding this comment.
I'd add at least one test case for the failure path, but maybe that's already covered elsewhere?
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.
Description
During bulk reverification, an OpenAI key verification failed with
context deadline exceeded (Client.Timeout exceeded while awaiting headers)and was recorded as an indeterminate result. The detector's default client wascommon.SaneHttpClient(): a 5s timeout with no retries, so any single slow response from the OpenAI API becomes a permanent verification failure.This switches the default client to
common.RetryableHTTPClient(the same pattern already used by thetwilioandprivatekeydetectors) with:The retryable client respects the parent context, so callers with their own deadlines still bound the total time. Scanners constructed with an explicit client are unaffected.
Adds a unit test asserting the default client retries transient errors (500, 500, then 200 → exactly 3 attempts, final 200).
Checklist
go test ./pkg/detectors/openai/)go vetandgofmtcleanNote
Low Risk
Scoped to OpenAI detector verification HTTP behavior; may slightly increase verification latency on failures but reduces false indeterminate results.
Overview
OpenAI key verification no longer treats a single slow or flaky API response as an indeterminate result during bulk reverification.
The detector’s default HTTP client is switched from
common.SaneHttpClient()(5s timeout, no retries) tocommon.RetryableHTTPClientwith a 10s per-attempt timeout and up to 2 retries on transient failures (timeouts, connection errors, 429/5xx), matching patterns used by detectors such as Twilio and privatekey. Scanners that inject their ownclientare unchanged.Unit tests assert the default client retries until success (500 → 500 → 200, three attempts) and stops after the retry budget when errors persist.
Reviewed by Cursor Bugbot for commit 84b316c. Bugbot is set up for automated code reviews on this repo. Configure here.