Skip to content

fix(grok): preserve upstream media error messages and codes - #8669

Merged
Wei-Shaw merged 3 commits into
Wei-Shaw:mainfrom
r266-tech:codex/grok-top-level-errors
Nov 16, 2026
Merged

Wei-Shaw merged 3 commits into
Wei-Shaw:mainfrom
r266-tech:codex/grok-top-level-errors

Conversation

@r266-tech

@r266-tech r266-tech commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Refs #8666

CI 跟进(2026-11-11):当前 head c8f4264f8 的功能测试、lint 等检查已成功,backend-security 命中当前 Go 1.27.3 基线的 GO-2026-6859。共享工具链升级已独立提交到 #8670;该 PR 精确 head 267e2a954 的 backend-security 已成功。本 PR 的安全失败仍需共享升级合入后同步基线并复核,当前 head 保持本次 Grok 字段修复范围。

xAI 返回 {"code":"invalid_image","error":"Image could not be decoded."} 时,Grok 图片链路会把具体原因替换成 xAI upstream returned status 400,媒体错误包装也会丢失已有的上游错误码。此改动补上顶层字符串 error 和标量 code 的解析回退,并把错误码带入媒体错误对象。异步图片任务复用该对象,轮询结果也保留具体消息和错误码。

既有嵌套错误、detail、message 的解析优先级保持一致;内容拒绝、账号错误码过滤、管理员错误改写和可重试错误的账号切换仍沿用原策略。媒体错误序列化统一对消息及错误码执行现有敏感查询参数脱敏,未知错误对象继续使用通用兜底。本 PR 处理 #8666 中的结构化消息/错误码缺口。

验证使用 Go 1.27.3(macOS arm64):

  • 原始 37 个叶子回归置于未改动的 main:15 个失败,22 个兼容与策略对照通过;补充管理员消息透传的脱敏用例后,最终 38 个叶子场景全部通过。
  • 真实 handler 覆盖 OAuth / API Key 的 /v1/images/edits 以及异步提交、失败保存和任务轮询,并断言确定性 400 只有一次上游调用、敏感查询参数被脱敏。
  • go test -p=2 -tags=unit ./... -json:26,922 通过,41 条件跳过。
  • go test -p=2 -tags=integration ./... -json:16,169 通过,16 条件跳过。
  • CI 固定 golangci-lint v2.14.0:golangci-lint run --timeout=30m ./...,0 issues;git diff --check 通过。

使用合成上游响应,未调用真实 xAI 或验收线上部署。实现与本地验证由 AI 完成。

@cshxql

cshxql commented Nov 12, 2026

Copy link
Copy Markdown

多久合并bro,坐等

@r266-tech

Copy link
Copy Markdown
Contributor Author

@cshxql 修复和功能测试已完成,目前还不能给出合并时间,需要维护者审阅。当前 backend-security 仍被 Go 1.27.3 基线的 GO-2026-6859 检查拦住,其余实质检查已通过。

共享工具链升级在 #8670,该 PR 的安全检查已通过,但尚未合入;合入后我会同步这条 PR 并复核安全检查。以上为 AI agent 核对的当前状态。

extractUpstreamErrorMessage and extractUpstreamErrorCode drive failover,
model-not-found cooldown and account-disable decisions on every platform.
Reading a top-level code there short-circuited the OpenAI-compatible
model-not-found failover for vLLM-style bodies such as
{"object":"error","message":"model not found","code":400}. It also
added top-level token_revoked as a new disable path.

Restore the shared helpers to main. Add Grok-only grokUpstreamErrorMessage
and grokUpstreamErrorCode for the media error path, the content-policy
message and the error passthrough rule, so the Grok media fix in this PR
is unchanged. Adds tests that the shared extractors ignore the xAI flat
shape and that model-not-found still fails over with a top-level code.
@Wei-Shaw

Copy link
Copy Markdown
Owner

维护者复核后已直接在本分支调整,并合入最新 main:

  • 问题:extractUpstreamErrorMessage / extractUpstreamErrorCode 是全平台共用的,决定 failover、model-not-found 冷却和账号停用。加入顶层 code 后,vLLM/SGLang 一类 OpenAI 兼容上游的错误体({"object":"error","message":"model not found","code":400})会被 isOpenAICompatibleModelNotFoundBody 的 code 短路,从能 failover 变成不能 failover。同时顶层 token_revoked 等 code 也成了新的账号停用路径。
  • 调整:两个共用 helper 恢复为 main 原样。新增仅在 Grok 路径使用的 grokUpstreamErrorMessage / grokUpstreamErrorCode,用于 Grok 媒体错误、内容策略消息和错误透传规则。本 PR 对 Grok 媒体错误的修复效果不变,PR 自带的测试仍然通过。新增测试锁定:共用 helper 不识别 xAI 扁平格式;带顶层 code 时 model-not-found 仍能 failover。

Maintainer adjusted this PR and merged the latest main. The shared extractors drive failover, model-not-found cooldown and account-disable decisions on every platform. Reading a top-level code there stopped vLLM-style {"object":"error","message":"model not found","code":400} bodies from failing over, and added top-level token_revoked as a disable path. The shared helpers are restored to main. New Grok-only grokUpstreamErrorMessage / grokUpstreamErrorCode keep your Grok media fix unchanged. Added tests for both cases.

@Wei-Shaw
Wei-Shaw merged commit 7e4c614 into Wei-Shaw:main Nov 16, 2026
9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants