pref(provider):修正 Provider 生成重试默认语义并放宽退避上限#503
Merged
phantom5099 merged 1 commit into1024XEngineer:mainfrom Apr 28, 2026
Merged
pref(provider):修正 Provider 生成重试默认语义并放宽退避上限#503phantom5099 merged 1 commit into1024XEngineer:mainfrom
phantom5099 merged 1 commit into1024XEngineer:mainfrom
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
| @@ -179,7 +179,7 @@ generate_idle_timeout_sec: 300 | |||
|
|
|||
There was a problem hiding this comment.
已核对本次语义更新与实现:generate_max_retries 的“未配置默认值”与“显式 0 关闭重试”表述一致。此处无阻塞问题。
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
之前存在的问题
1.
generate_max_retries无法区分“未配置”和“显式关闭”原实现里
GenerateMaxRetries是普通int:provider.yaml未填写generate_max_retriesprovider.yaml显式写入generate_max_retries: 0这两种情况在解码后都会变成
0。结果是配置层丢失了“字段是否被显式设置”的信息。
直接后果:
2. 文档语义与代码实际行为不一致
原文档将
generate_max_retries描述为:<= 0时回退默认值5但生产代码中:
0会原样进入运行时配置这意味着正常配置路径几乎不可能触发“负数回退默认值”的语义,文档与实现存在偏差。
3. 生成重试退避上限偏紧
原退避窗口是:
1s5s对短时 429 / 5xx 抖动场景而言,这个上限偏保守。在重试次数有限的情况下,稍微放宽上限可以提升恢复概率,同时不会引入不可控的长时间阻塞。
采取的方案
方案一:为
generate_max_retries增加“三态语义”GenerateMaxRetries:继续承载数值GenerateMaxRetriesSet:记录字段是否被显式配置运行时语义调整为:
50:关闭生成重试这样可以在不大面积改动调用方的前提下,把“默认值”和“显式关闭”重新区分开。
方案二:在
provider.yaml读写链路中保留显式零值为了避免 YAML 层再次吞掉语义,本次对持久化链路做了收口:
generate_max_retries是否真的出现0时会保留generate_max_retries: 0方案三:放宽统一退避上限
保留现有指数退避 + 抖动策略,只把最大等待时间从
5s提升到7s:改动情况
配置与运行时语义修正
涉及文件:
internal/config/provider.gointernal/config/provider_loader.gointernal/config/provider_custom_normalize.go核心改动:
ProviderConfig中引入GenerateMaxRetriesSetresolveGenerateMaxRetries(),集中解析默认值 / 显式关闭 / 显式数值三种语义provider.yaml的generate_max_retries走“可选字段”解析0,未配置时继续省略测试补强
涉及文件:
internal/config/provider_test.gointernal/config/loader_test.gointernal/provider/constants_test.go新增覆盖点:
generate_max_retries时,运行时默认使用5generate_max_retries: 0时,运行时保持禁用重试provider.yaml持久化时,显式0不会被丢失7s文档对齐
涉及文件:
docs/guides/configuration.mddocs/guides/adding-providers.md修正内容:
generate_idle_timeout_sec的原有默认语义说明不变