pref(provider):移除 Provider 透明重连机制#174
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 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.
变更说明
OpenAI Provider 的
Chat()方法此前在 SSE 流中途断连时,会自动将已累积的部分 assistant 消息(文本片段 + 未完成的 tool call)注入请求上下文并重新发起请求,实现"透明续传"。该机制在实际使用中导致输出不稳定:注入的半成品消息改变模型注意力分布、provider 与 runtime 双层累积状态不一致、上下文随重连次数膨胀。本次改动将Chat()退化为语义清晰的"单次请求-单次响应"模式,流中断时直接返回错误,重试策略完全由上层 runtime 层统一管理。主要改动
internal/provider/openai/openai.goChat():移除重连循环、指数退避、originalMessages拷贝逻辑,直接内联原chatOnce()的 HTTP 请求与流消费流程。失败即返回,不做隐式重试。chatOnce():合并进Chat()。consumeStream():移除accumText/accumCalls跨周期共享参数,tool call 累积改为方法内部局部变量。buildAssistantMsg():不再需要构造 assistant 快照用于重连上下文注入。mergeToolCallDeltaWithAccum():consumeStream内部直接调用mergeToolCallDelta()。internal/provider/errors.goMarkNonRetryable():仅服务于透明重连耗尽后的"防叠加标记",移除后无业务调用方。IsRecoverableStreamError():仅服务于透明重连循环中的可恢复性判断,移除后无业务调用方。internal/provider/openai/openai_test.goTestProviderChatReconnect_*、TestBuildAssistantMsg_*、TestMergeToolCallDeltaWithAccum_*、TestReconnect_*)及辅助函数(countMessagesByRole、roundTripperFunc)。consumeStream()签名变更涉及的 3 个测试。internal/provider/errors_test.goTestIsRecoverableStreamError_*共 8 个测试函数。TestMarkNonRetryable_*共 4 个测试函数。docs/provider-api-reference.mdIsRecoverableStreamErrorAPI 条目。未改动项
transport/retry.go(RetryTransport) — HTTP 层 RoundTripper 中间件,仅在首次请求未收到响应时重试 429/5xx,与流中途续传无关,保留不变。ProviderError.Retryable字段 — 被 RetryTransport 和 runtime 广泛使用,保留不变。runtime.go重试机制 — 整轮 Chat 调用失败后的完整重试,保留不变。预期收益
Chat()从"可能多次请求的复合操作"回归为"单次请求-单次响应"的基本语义,错误处理路径可预测。