Skip to content

fix(desktop): sanitize XD Gateway Grok tools - #2444

Open
yuaiccc wants to merge 2 commits into
makecindy:mainfrom
yuaiccc:fix/gateway-grok-namespace-tools
Open

fix(desktop): sanitize XD Gateway Grok tools#2444
yuaiccc wants to merge 2 commits into
makecindy:mainfrom
yuaiccc:fix/gateway-grok-namespace-tools

Conversation

@yuaiccc

@yuaiccc yuaiccc commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

这次改了什么

摘要

新增 createGatewayGrokResponsesCompatTransform,加入 Codex 代理的请求 transform 链。当 session provider 为 xd(XD Gateway)、model 以 x-ai/grok 开头、且 providerRoutingServesWireModel('xd', 'codex', model) 为真时,复用既有 sanitizeXaiTools 清理 Codex namespace tools(如 multi_agent_v1)与 web_searchexternal_web_access 标记,避免 Grok Responses 上游因不支持的 tool 形状返回 400。区别于已有的 first-party xai/ OAuth provider 变换,本变换只作用于网关路由下的 x-ai/grok 模型。

变更类型

  • feat 新功能
  • fix 缺陷修复
  • refactor / perf 重构或性能优化
  • docs / test / chore 文档、测试或工程维护
  • 其他:

范围

  • 关联 Issue / 需求:无
  • 本 PR 包含:createGatewayGrokResponsesCompatTransform 加入 createTransformRequestChain(计数 13 → 14);新增单测 drops Codex namespace tools for XD Gateway Grok models;同步 transform 链计数与注释清单。
  • 明确不包含:first-party xai/ OAuth provider 变换、其它 provider 路由。
  • 用户可见变化:使用 XD Gateway 的 x-ai/grok* 模型时不再因 tool 形状被上游 400。
  • 是否存在 breaking change:无

UI 变化

不涉及:仅改主进程请求 transform 链,无 renderer / 视觉 / 交互 / 文案变化。

怎么验证的

自动验证

pnpm --filter desktop exec vitest run src/main/maker-host/__tests__/codexProxyHost.test.ts
结果:PR 作者本地已通过;本次触发重审后以 CI 为准。

手工验证

不涉及:transform 行为由单测覆盖。

未执行的验证

本次未本地复跑单测,依赖 CI 重跑确认。

风险

风险分类

  • 无已知风险
  • SQLite / migration
  • system prompt
  • 协议兼容
  • 权限 / 安全 / 用户数据
  • 存量插件兼容
  • 原生层 / fingerprint / OTA
  • 跨平台差异
  • 其他:

影响与回滚

  • 影响范围:守卫较窄(provider xd + model x-ai/grok 前缀 + 路由服务校验三重条件),只影响 XD Gateway Grok 路径,不影响 first-party xai OAuth 或其它 provider。复用既有 sanitizeXaiTools,无新逻辑分支;未匹配时返回 null 透传,不改写请求。
  • 回滚 / 降级方式:从 transform 链移除 createGatewayGrokResponsesCompatTransform(计数回 13)。

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名
  • UI 改动已在「UI 变化」注明(不涉及 UI)
  • 未提交凭证、令牌或授权文件
  • 已补充必要文档
  • 已确认测试结果或说明未执行原因

Signed-off-by: yuaiccc <yuaiccc@aliyun.com>
@yuaiccc
yuaiccc requested a review from a team as a code owner August 11, 2026 10:02
@greptile-apps

greptile-apps Bot commented Aug 11, 2026

Copy link
Copy Markdown

Greptile Summary

此 PR 为 XD Gateway 下的 Grok Responses 请求新增一层有针对性的工具形状清理,以避免不受支持的 Codex namespace 工具和 external_web_access 字段导致上游拒绝请求。

  • 仅在会话 provider 为 xd、模型匹配 x-ai/grok* 且路由声明可服务该模型时执行清理
  • 复用既有 sanitizeXaiTools,并将新 transform 加入 Codex 请求链
  • 新增覆盖 namespace 删除、web search 字段清理及普通 function 工具保留行为的测试

Confidence Score: 5/5

未发现仍需阻止合并的故障,此 PR 看起来可以安全合并。

未发现阻塞性故障。

Important Files Changed

Filename Overview
apps/desktop/src/main/maker-host/codex-proxy-host.ts 新增范围受限的 XD Gateway Grok 工具兼容 transform,并接入现有 Codex 请求转换链。
apps/desktop/src/main/maker-host/tests/codexProxyHost.test.ts 新增端到端转换链测试,并同步更新 transform 数量和顺序断言。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Codex Responses 请求] --> B{provider 为 xd?}
  B -- 否 --> P[原样传递]
  B -- 是 --> C{模型以 x-ai/grok 开头?}
  C -- 否 --> P
  C -- 是 --> D{XD Codex 路由可服务该模型?}
  D -- 否 --> P
  D -- 是 --> E[sanitizeXaiTools]
  E --> F[删除 namespace 工具]
  E --> G[清理 web_search 不兼容字段]
  E --> H[保留受支持工具]
  F --> I[继续后续 transform 链]
  G --> I
  H --> I
Loading

Reviews (2): Last reviewed commit: "chore: complete PR description per forma..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47bd4366d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

) {
return null;
}
return sanitizeXaiTools(body);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 保留 Grok 请求禁用外网搜索的语义

当 Codex 为 XD Grok 发出 {type: 'web_search', external_web_access: false}(表示只允许缓存搜索、明确禁止访问外网)时,这里复用 sanitizeXaiTools 会把它改成裸 {type: 'web_search'},从而让 Gateway 按默认方式启用实时外网搜索。仓库里的 Seed 兼容层已经为同一输入选择删除该工具来保留禁令;这里也应删除搜索工具或用 Grok 支持的方式表达禁用,而不能静默扩大网络访问权限。

Useful? React with 👍 / 👎.

@MagicLizi MagicLizi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式检查未通过

请补充 PR Description 的必要段落:

  • 这次改了什么:说明 sanitize XD Gateway Grok tools 的具体改动
  • 怎么验证的:说明测试覆盖和验证方式
  • 风险:评估此改动对 Codex proxy 链的影响

修完描述后 push 即可触发重新审查。

@MagicLizi MagicLizi added the status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) label Aug 11, 2026
@MagicLizi

Copy link
Copy Markdown
Contributor

@yuaiccc 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/main/maker-host/codex-proxy-host.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

Signed-off-by: yuaiccc <yuaiccc@aliyun.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 039433e29a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

) {
return null;
}
return sanitizeXaiTools(body);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 同步清理指向已删除工具的 tool_choice

当 Grok 请求只声明 namespace 等不支持的工具,或 tool_choice 强制选择其中一个时,sanitizeXaiTools 会删除该工具,却保留 tool_choiceparallel_tool_calls;最终请求会出现“没有 tools 仍指定 tool_choice”或 choice 引用不存在工具的形态,Gateway 仍会返回 schema 400。相邻的 Seed 兼容层已经通过重置失效 choice、在工具清空时删除这些控制字段处理了同一情况;这里复用 sanitizer 时也需要保持这些字段一致。

Useful? React with 👍 / 👎.

@MagicLizi

Copy link
Copy Markdown
Contributor

@yuaiccc 👋 这个 PR 还有 2 条 review conversation 没 resolve(apps/desktop/src/main/maker-host/codex-proxy-host.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。

如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。

@MagicLizi MagicLizi added status:ci-failed CI 失败(review-pr 自动维护,仅展示) status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) and removed status:awaiting-author 等作者修改(review-pr 自动维护,仅展示) status:ci-failed CI 失败(review-pr 自动维护,仅展示) labels Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:awaiting-author 等作者修改(review-pr 自动维护,仅展示)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants