[Bug] Codex Desktop automation_update parameters.type=null causes /v1/responses to return 502
问题描述
Codex Desktop 使用自定义 Responses provider 原生透传到 Sub2API 时,Desktop 加载的内置 automation_update function tool 可能包含 parameters.type = null。Sub2API 将该 Schema 转发给 OpenAI upstream,upstream 返回 400 invalid_function_parameters,但客户端最终只收到通用的 502 upstream_error。
该工具定义还可能进入多轮会话历史;之后即使当前轮没有使用 Automation,重放历史中的无效 Schema 也会导致每一轮继续失败。
环境
- Sub2API:
0.1.171 - Endpoint:
POST /v1/responses - Client: Codex Desktop
0.147.0-alpha.1.2/ Desktop build26.730.61639 - Wire protocol: native Responses passthrough
- Reproduced with
gpt-5.5,gpt-5.6-sol, andgpt-5.6-terra
最小复现
{
"model": "gpt-5.6-sol",
"input": "Reply with OK.",
"stream": false,
"store": false,
"tool_choice": "none",
"tools": [
{
"type": "function",
"name": "automation_update",
"description": "Update an automation.",
"parameters": {
"type": null,
"properties": {}
}
}
]
}
实际结果
Sub2API 对客户端返回:
{
"error": {
"message": "Upstream request failed",
"type": "upstream_error"
}
}
HTTP status: 502
Sub2API 的 ops_error_logs 记录到真实 upstream 响应:
upstream_status_code=400
provider_error_code=invalid_function_parameters
Invalid schema for function 'automation_update':
None is not valid under any of the given schemas.
param: tools[0].parameters
当工具定义位于会话历史时,upstream 参数路径类似:
input[234].tools[0].tools[3].parameters
对照结果
automation_update.parameters |
Result |
|---|---|
{"type": null, "properties": {}} |
Sub2API 502, upstream 400 |
{"type": "object", "properties": {}} |
200 |
期望行为
建议至少实现其中一种:
- 兼容 Codex Desktop:转发前将 function tool 中显式的
parameters.type = null修正为"object"。 - 修正范围应覆盖顶层
tools[*],以及多轮历史中的嵌套 tool definitions。 - 如果不做 Schema 修正,应保留 upstream 的
400 invalid_function_parameters和错误详情,而不是转换成可重试的通用502。
这样可以避免上层 gateway 和客户端把确定性的 Schema 错误当成临时上游故障反复重试。
与 #2753 的区别
#2753 处理的是无效的 placeholder tool entry,例如 tools[].type = None/null。
本问题中的 tool entry 本身是合法的 type: "function",无效字段位于 tools[].parameters.type,并且还可能存在于历史输入的嵌套工具定义中,因此不是同一问题。
参考实现:CLIProxyAPI(CPA)
确认 CPA 已经修复过 Codex Desktop automation_update 的同类 Schema 兼容问题:
- Issue: router-for-me/CLIProxyAPI#4343
- Fix commit:
b6ce0be - First release containing the fix:
v7.2.79 - Earlier namespaced-tool fix: router-for-me/CLIProxyAPI#4157
CPA 的处理逻辑位于 internal/runtime/executor/xai_executor.go,会识别并简化:
- namespaced form:
namespace=codex_app+name=automation_update - flattened form:
name=codex_app__automation_update - 参数根节点为
oneOf/anyOf,且包含非 object 分支(例如null)的 function/custom tool
命中后会把参数 Schema 降级为安全的 object Schema,并关闭 strict:
{
"type": "object",
"properties": {},
"additionalProperties": true
}
CPA 的修复目前针对 xAI executor,但问题来源相同,都是 Codex Desktop 加载的 automation_update 根 Schema 无法被严格上游接受,可以作为 Sub2API Responses passthrough 的实现参考。
本 Issue 复现到的 OpenAI upstream 形式还包括显式 parameters.type = null,因此 Sub2API 若复用该思路,建议同时覆盖:
type显式为null- 根节点
oneOf/anyOf含非 object 分支 - 当前
tools[*]和会话历史中的嵌套 tool definitions
OpenAI Codex 官方上游 Issues
OpenAI 官方 openai/codex 仓库已有相同或同根因的问题报告:
- openai/codex#36441(Open)是本 Issue 的精确对应:Codex Desktop 经 CC Switch 使用自定义 provider 时,
codex_app__automation_update的参数 Schema 出现type: null,请求被上游以 HTTP 400 拒绝。 - openai/codex#30132(Closed / completed)是同一根因的另一种表现:
automation_update参数根节点使用oneOf,Azure OpenAI 将其判定为type: "None"并拒绝。 - openai/codex#27877(Closed / not planned)不是
automation_update,但记录了相同类别的兼容问题:bundled plugin 工具参数根节点的oneOf/anyOf被 API 拒绝,而且无效工具定义进入会话历史后会导致后续请求持续失败。
其中 #36441 可以确认,本 Issue 复现的无效 Schema 确实也会由官方 Codex Desktop 产生;#30132 和 #27877 则说明问题不只限于单一模型或单一代理实现,而是 Codex 动态工具 Schema 与严格上游校验之间的兼容性问题。
因此建议 Sub2API 在透传层做兼容规范化,同时保留 upstream 的原始 400 错误详情;这既能兼容官方客户端当前行为,也能避免确定性的 Schema 错误被包装成 502 后反复重试。
三组 cURL 对照:Schema 校验与主动工具调用
以下三组请求使用同一 endpoint、模型和工具名,只改变参数根 Schema 与 tool_choice。API key 已替换为环境变量。
export SUB2API_BASE_URL="https://your-sub2api.example.com"
export SUB2API_API_KEY="<your-api-key>"
1. 无效 Schema,不调用工具
即使 tool_choice 为 none,上游仍会先校验工具 Schema。
curl -sS -w '\nHTTP %{http_code}\n' \
"$SUB2API_BASE_URL/v1/responses" \
-H "Authorization: Bearer $SUB2API_API_KEY" \
-H "Content-Type: application/json" \
--data @- <<'JSON'
{
"model": "gpt-5.6-sol",
"input": "Reply with OK.",
"stream": false,
"store": false,
"max_output_tokens": 200,
"tool_choice": "none",
"tools": [{
"type": "function",
"name": "codex_app__automation_update",
"description": "Update an existing automation.",
"parameters": {
"type": null,
"properties": {
"automation_id": {"type": "string"},
"title": {"type": "string"}
},
"required": ["automation_id", "title"],
"additionalProperties": false
},
"strict": true
}]
}
JSON
实测:Sub2API 返回 HTTP 502 / upstream_error,真实 upstream 为 HTTP 400 invalid_function_parameters。
2. 合法 object Schema,不调用工具
与请求 1 相比,只将 parameters.type 从 null 改为 object。
curl -sS -w '\nHTTP %{http_code}\n' \
"$SUB2API_BASE_URL/v1/responses" \
-H "Authorization: Bearer $SUB2API_API_KEY" \
-H "Content-Type: application/json" \
--data @- <<'JSON'
{
"model": "gpt-5.6-sol",
"input": "Reply with OK.",
"stream": false,
"store": false,
"max_output_tokens": 200,
"tool_choice": "none",
"tools": [{
"type": "function",
"name": "codex_app__automation_update",
"description": "Update an existing automation.",
"parameters": {
"type": "object",
"properties": {
"automation_id": {"type": "string"},
"title": {"type": "string"}
},
"required": ["automation_id", "title"],
"additionalProperties": false
},
"strict": true
}]
}
JSON
实测:HTTP 200,response.status=completed,输出普通 message。
3. 合法 object Schema,强制主动调用工具
通过具体 function tool_choice 强制模型生成 codex_app__automation_update 调用。
curl -sS -w '\nHTTP %{http_code}\n' \
"$SUB2API_BASE_URL/v1/responses" \
-H "Authorization: Bearer $SUB2API_API_KEY" \
-H "Content-Type: application/json" \
--data @- <<'JSON'
{
"model": "gpt-5.6-sol",
"input": "Call codex_app__automation_update to rename automation auto-test-001 to Schema compatibility test.",
"stream": false,
"store": false,
"max_output_tokens": 200,
"tool_choice": {
"type": "function",
"name": "codex_app__automation_update"
},
"tools": [{
"type": "function",
"name": "codex_app__automation_update",
"description": "Update an existing automation.",
"parameters": {
"type": "object",
"properties": {
"automation_id": {"type": "string"},
"title": {"type": "string"}
},
"required": ["automation_id", "title"],
"additionalProperties": false
},
"strict": true
}]
}
JSON
实测:HTTP 200,并返回:
{
"type": "function_call",
"name": "codex_app__automation_update",
"arguments": "{\"automation_id\":\"auto-test-001\",\"title\":\"Schema compatibility test\"}"
}
| 场景 | parameters.type | tool_choice | 实测结果 |
|---|---|---|---|
| 无效 Schema,不调用 | null | none | HTTP 502;upstream HTTP 400 |
| 合法 Schema,不调用 | object | none | HTTP 200;message |
| 合法 Schema,主动调用 | object | 指定 codex_app__automation_update | HTTP 200;function_call |
结论:失败发生在工具 Schema 校验阶段,与模型是否实际调用该工具无关。将根节点修正为 object 后,普通响应和主动 function call 都能正常工作。