feat(provider): make outer OpenAI retry count configurable#9099
feat(provider): make outer OpenAI retry count configurable#9099x1051445024 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a configurable provider_error_retries setting to replace the hardcoded retry limit of 10 in OpenAI provider chat methods, allowing users to control outer-loop recovery paths. Feedback highlights that a default value of 1 effectively disables these recovery paths (such as key rotation and image fallback) and suggests a higher default. Additionally, the new setting needs to be added to CONFIG_METADATA_3 and localization files for WebUI visibility. Finally, a potential AttributeError should be avoided by guarding against self.provider_settings being None, along with adding corresponding unit tests.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| "default_provider_id": "", | ||
| "fallback_chat_models": [], | ||
| "request_max_retries": 5, | ||
| "provider_error_retries": 1, |
There was a problem hiding this comment.
⚠️ Critical Reliability & WebUI Configuration Issues
-
Default Value of
1Disables All Recovery Paths:
Setting the default value ofprovider_error_retriesto1means the outer retry loop runs exactly once (i.e., 0 retries). As a result, all provider-level recovery paths (such as context length trimming, image fallback, key rotation, and tool removal) are completely disabled by default. If any of these errors occur on the first attempt, the request will immediately fail without attempting recovery.To preserve these robust recovery features out-of-the-box, consider keeping the default value higher (e.g.,
3or5), while still allowing proxy/aggregator users to configure it down to1if they want to avoid nested retries. -
Missing from
CONFIG_METADATA_3:
This setting is not added toCONFIG_METADATA_3indefault.py. SinceCONFIG_METADATA_3is used to render the settings in the WebUI, users will not be able to see or configure this setting from the admin panel. Please add it toCONFIG_METADATA_3underai_group -> metadata -> ai -> itemsand update the corresponding i18n locale files (config-metadata.json).
| multiplying latency for proxy/aggregator providers that already perform | ||
| their own upstream retry and fallback. | ||
| """ | ||
| raw = self.provider_settings.get("provider_error_retries", 1) |
| provider.provider_settings = {} | ||
| assert provider._provider_error_retries() == 1 |
There was a problem hiding this comment.
Add a test case to verify that _provider_error_retries handles provider_settings being None gracefully.
| provider.provider_settings = {} | |
| assert provider._provider_error_retries() == 1 | |
| provider.provider_settings = None | |
| assert provider._provider_error_retries() == 1 | |
| provider.provider_settings = {} | |
| assert provider._provider_error_retries() == 1 |
Summary
provider_settings.provider_error_retriesto configure the OpenAI-compatible provider's outer recovery retry loop.request_max_retries.request_max_retriessetting.Motivation
OpenAI-compatible proxy/aggregator providers often perform their own upstream retry and fallback. AstrBot currently has an inner request retry loop plus a fixed outer provider-level retry loop of 10 attempts. When the upstream proxy is slow or unstable, those nested retries can significantly delay fallback to other providers.
This change makes the outer loop configurable while preserving the existing recovery paths for users who need more attempts.
Testing
python -m py_compile astrbot/core/provider/sources/openai_source.py astrbot/core/config/default.py tests/test_openai_source.pypytestwas not available in the local environment used for this change.Summary by Sourcery
Make the OpenAI-compatible provider’s outer recovery retry loop configurable via provider settings and align defaults.
New Features:
Enhancements:
Tests: