Skip to content

fix(openai): 补齐 WS HTTP bridge 的客户端工具适配 - #5764

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
hansnow:fix/ws-http-bridge-custom-tools
Aug 18, 2026
Merged

fix(openai): 补齐 WS HTTP bridge 的客户端工具适配#5764
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
hansnow:fix/ws-http-bridge-custom-tools

Conversation

@hansnow

@hansnow hansnow commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

问题

当 Codex 通过 WebSocket ingress 发起 Responses 请求,而选中的 OpenAI API-key 账号需要走 HTTP bridge 时,后续轮次会重放历史工具调用。Codex 的客户端工具历史使用:

{"type":"custom_tool_call","name":"exec","input":"..."}

部分 OpenAI Responses 兼容上游只接受标准 function_call.arguments。当前 bridge 直接发送 replay body,因而可能返回:

Missing required parameter: 'input[N].arguments'.

同时,即使请求侧完成降级,上游返回的 function_call 也必须在发送给 Codex、以及写入下一轮 replay 历史之前恢复成 custom_tool_call

与现有 Issue / PR 的关系

本 PR 是对 #5661 的补充,不替代其普通 HTTP passthrough 修复。

改动

  • 将已有 Grok 路径内部使用的客户端工具请求适配入口抽成中性的共享实现,并保留原有 Grok wrapper,避免改变现有调用方。
  • 仅对 OpenAI API-key 的 WS-to-HTTP bridge 请求执行客户端工具降级;OAuth 和其他平台保持原行为。
  • 在 bridge 扫描上游 SSE、转发给客户端和收集 replay input 之前,使用同一轮请求生成的 mapping 恢复客户端工具事件。
  • mapping 仅存在于单次 bridge turn 的局部变量中,避免跨 turn 或 failover 污染。

测试

新增回归测试覆盖完整路径:

  1. 历史 custom_tool_call.input 被转换为 function_call.arguments
  2. 对应的 function_call_output 保持对齐;
  3. 上游流式 function_call 被恢复为 custom_tool_call.input
  4. response.completed 和下一轮 replay input 都保留恢复后的 custom 类型。

已运行:

go test ./internal/service -run '^TestProxyOpenAIWSHTTPBridgeTurnAPIKeyAdaptsClientTools$' -count=1
go test ./internal/service ./internal/pkg/apicompat -count=1
make test-unit
go vet ./...
git diff --check

完整集成测试由本 PR 的 GitHub Actions 验证。

@Wei-Shaw
Wei-Shaw merged commit 26cb59d into Wei-Shaw:main Aug 18, 2026
8 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 18, 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.

2 participants