fix: 修复 Chat Completions 兼容层误将 response.failed 返回为成功响应#2972
Open
northya wants to merge 1 commit into
Open
Conversation
Contributor
|
All contributors have signed the CLA. ✅ |
f67f3e6 to
2e212d1
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
背景
当
/v1/chat/completions通过 OpenAI Responses 兼容路径转发时,上游 Responses SSE 可能返回终止事件response.failed,例如输入超过模型上下文窗口时。修复前,Chat Completions 兼容转换逻辑会把
response.failed当作普通终止事件处理,并转换成一个成功的 Chat Completion 响应:finish_reason: "stop"这会导致客户端把上游失败误判为正常的空响应,并且和
/v1/responses接口的行为不一致;/v1/responses会把同类上游失败作为错误返回。修复方式
本次修改在 Chat Completions 兼容路径中显式识别
response.failed,避免它继续进入 Responses 到 Chat Completions 的成功响应转换逻辑。具体包括:
/v1/chat/completions:当 buffered Responses SSE 的最终响应状态为failed时,返回UpstreamFailoverError,不再写出 HTTP 200。/v1/chat/completions:当上游返回response.failed时,在 pending compatibility chunks flush 到客户端之前中止成功响应转换。测试
新增了两个回归测试,分别覆盖:
response.failedresponse.failed已验证: