Repository navigation
feat(llm): support custom retry status codes via retry_codes config - #818
Merged
Merged
Conversation
Add a retry_codes configuration field that allows users to specify additional HTTP status codes (4xx) that should trigger exponential backoff retry. This targets self-hosted LLM clusters that misuse status codes like 403 or 400 for rate limiting. Implementation uses SDK middleware to inject the x-should-retry: true response header when a configured status code is encountered, leveraging the existing SDK retry mechanism (up to 5 retries with exponential backoff) without any SDK modifications. Configuration is supported via: - Provider config: providers.<name>.retry_codes / custom_providers.<name>.retry_codes - Legacy llm config: llm.retry_codes - CLI: ocr config set providers.<name>.retry_codes 403,400 Also fixes cloneProviderEntry to copy previously missing fields (TimeoutSec, ExtraHeaders, RetryCodes) for TUI rollback correctness.
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 5 selected item(s). |
wu21-web
approved these changes
Aug 10, 2026
wu21-web
left a comment
Contributor
There was a problem hiding this comment.
The approach is sound and the wiring is complete. The only real gap is missing tests for the new functions.
Cover ParseRetryCodes validation, retryCodesMiddleware behavior, resolver integration (provider and legacy config paths, invalid codes), and end-to-end retry via httptest for both OpenAI and Anthropic clients.
…d of erroring Replace validateRetryCodes with sanitizeRetryCodes that filters out SDK-default codes and returns warnings. The resolve phase silently drops redundant codes without interrupting startup. The config set command prints warnings to stderr so users are informed. This makes the tool friendlier for users migrating from other tools who habitually configure 429 and similar codes.
…c/RetryCodes/ExtraHeaders Verify that the clone correctly copies these fields and that mutations to the clone do not affect the original. Also pin the nil-stays-nil behavior for RetryCodes and ExtraHeaders.
Verify that redundant codes (429, 408) emit a WARNING to stderr while still writing the valid codes to config. Also verify that valid-only codes produce no warning output.
wu21-web
approved these changes
Aug 10, 2026
lizhengfeng101
added a commit
that referenced
this pull request
Aug 10, 2026
…818) * feat(llm): support custom retry status codes via retry_codes config Add a retry_codes configuration field that allows users to specify additional HTTP status codes (4xx) that should trigger exponential backoff retry. This targets self-hosted LLM clusters that misuse status codes like 403 or 400 for rate limiting. Implementation uses SDK middleware to inject the x-should-retry: true response header when a configured status code is encountered, leveraging the existing SDK retry mechanism (up to 5 retries with exponential backoff) without any SDK modifications. Configuration is supported via: - Provider config: providers.<name>.retry_codes / custom_providers.<name>.retry_codes - Legacy llm config: llm.retry_codes - CLI: ocr config set providers.<name>.retry_codes 403,400 Also fixes cloneProviderEntry to copy previously missing fields (TimeoutSec, ExtraHeaders, RetryCodes) for TUI rollback correctness. * test(llm): add unit tests for retry_codes feature Cover ParseRetryCodes validation, retryCodesMiddleware behavior, resolver integration (provider and legacy config paths, invalid codes), and end-to-end retry via httptest for both OpenAI and Anthropic clients. * feat(llm): silently filter redundant retry_codes (408/409/429) instead of erroring Replace validateRetryCodes with sanitizeRetryCodes that filters out SDK-default codes and returns warnings. The resolve phase silently drops redundant codes without interrupting startup. The config set command prints warnings to stderr so users are informed. This makes the tool friendlier for users migrating from other tools who habitually configure 429 and similar codes. * test(tui): add coverage for cloneProviderEntry deep-copy of TimeoutSec/RetryCodes/ExtraHeaders Verify that the clone correctly copies these fields and that mutations to the clone do not affect the original. Also pin the nil-stays-nil behavior for RetryCodes and ExtraHeaders. * docs(llm): fix contradictory ParseRetryCodes comment * test(config): cover retry_codes warning output in config set path Verify that redundant codes (429, 408) emit a WARNING to stderr while still writing the valid codes to config. Also verify that valid-only codes produce no warning output.
8 of 15 tasks
Githab-capibara
added a commit
to Githab-capibara/open-code-review
that referenced
this pull request
Sep 17, 2026
…libaba#818) * feat(llm): support custom retry status codes via retry_codes config Add a retry_codes configuration field that allows users to specify additional HTTP status codes (4xx) that should trigger exponential backoff retry. This targets self-hosted LLM clusters that misuse status codes like 403 or 400 for rate limiting. Implementation uses SDK middleware to inject the x-should-retry: true response header when a configured status code is encountered, leveraging the existing SDK retry mechanism (up to 5 retries with exponential backoff) without any SDK modifications. Configuration is supported via: - Provider config: providers.<name>.retry_codes / custom_providers.<name>.retry_codes - Legacy llm config: llm.retry_codes - CLI: ocr config set providers.<name>.retry_codes 403,400 Also fixes cloneProviderEntry to copy previously missing fields (TimeoutSec, ExtraHeaders, RetryCodes) for TUI rollback correctness. * test(llm): add unit tests for retry_codes feature Cover ParseRetryCodes validation, retryCodesMiddleware behavior, resolver integration (provider and legacy config paths, invalid codes), and end-to-end retry via httptest for both OpenAI and Anthropic clients. * feat(llm): silently filter redundant retry_codes (408/409/429) instead of erroring Replace validateRetryCodes with sanitizeRetryCodes that filters out SDK-default codes and returns warnings. The resolve phase silently drops redundant codes without interrupting startup. The config set command prints warnings to stderr so users are informed. This makes the tool friendlier for users migrating from other tools who habitually configure 429 and similar codes. * test(tui): add coverage for cloneProviderEntry deep-copy of TimeoutSec/RetryCodes/ExtraHeaders Verify that the clone correctly copies these fields and that mutations to the clone do not affect the original. Also pin the nil-stays-nil behavior for RetryCodes and ExtraHeaders. * docs(llm): fix contradictory ParseRetryCodes comment * test(config): cover retry_codes warning output in config set path Verify that redundant codes (429, 408) emit a WARNING to stderr while still writing the valid codes to config. Also verify that valid-only codes produce no warning output.
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
Some self-hosted LLM clusters misuse HTTP status codes — e.g., returning 403 or 400 for rate limiting instead of the standard 429. This PR adds a
retry_codesconfiguration field that lets users specify additional 4xx status codes to trigger exponential backoff retry.retry_codesfield to provider config, legacy llm config, and CLIconfig setx-should-retry: trueresponse header on configured status codes, reusing the existing SDK retry mechanism (up to 5 retries with exponential backoff)config settime, rather than blocking startupcloneProviderEntryto copy previously missing fields (TimeoutSec,ExtraHeaders,RetryCodes)Configuration example
{ "provider": "my-cluster", "custom_providers": { "my-cluster": { "api_key": "sk-xxx", "url": "https://internal.llm.corp/v1", "protocol": "openai", "model": "gpt-4o", "retry_codes": [403, 400] } } }Or via CLI:
ocr config set custom_providers.my-cluster.retry_codes 403,400Bugfix: cloneProviderEntry data loss
cloneProviderEntry(used by TUI for rollback snapshots) was missingTimeoutSec,ExtraHeaders, andRetryCodes. This caused silent data loss on failed edits — rolling back would discard the user's timeout and extra headers settings. Now fixed with full test coverage for deep-copy isolation and nil preservation.Test plan
make checkpasses (formatting, vet, license headers)make testpasses (all existing + new tests)TestCloneProviderEntry_TimeoutAndRetryCodes— verifies deep-copy and mutation isolationTestCloneProviderEntry_NilRetryCodesAndExtraHeaders— pins nil-stays-nil behaviorretry_codeswith a mock server returning the configured status code, verify retry behavior