Skip to content

Conversation

@mt21625457
Copy link
Contributor

fix(网关): 修复工具续链校验与存储策略
fix(网关): 补齐Codex指令回退与输入过滤

完善 function_call_output 续链校验与引用匹配
续链场景强制 store=true,过滤 input 时避免副作用
补充续链判断与过滤相关单元测试

错误日志:
sub2api | 2026/01/13 14:46:53 OpenAI upstream error 400 (account=1 platform=openai type=oauth): {\n "error": {\n "message": "No tool call found for function call output with call_id call_gu9qHxCzZdOYoSpeUSz32uAx.",\n "type": "invalid_request_error",\n "param": "input",\n "code": null\n }\n}
sub2api | 2026/01/13 14:46:53 Account 1: Forward request failed: upstream error: 400 message=No tool call found for function call output with call_id call_gu9qHxCzZdOYoSpeUSz32uAx.
sub2api | 2026/01/13 14:46:53 [GIN] 2026/01/13 - 14:46:53 | 502 | 503.868457ms | 10.0.0.2 | POST /v1/responses
sub2api | 2026/01/13 14:46:54 [DeferredService] BatchUpdateLastUsed flushed 4 accounts

yangjianbo added 6 commits January 12, 2026 14:42
完善 function_call_output 续链校验与引用匹配
续链场景强制 store=true,过滤 input 时避免副作用
补充续链判断与过滤相关单元测试

测试: go test ./...
    openai_codex_transform_test.go:36、backend/internal/service/
    openai_codex_transform_test.go:89、backend/internal/service/
    openai_codex_transform_test.go:104)。
@Wei-Shaw Wei-Shaw merged commit 55fced3 into Wei-Shaw:main Jan 13, 2026
4 checks passed
@cyhhao
Copy link
Contributor

cyhhao commented Jan 13, 2026

@mt21625457 这个不能这么搞吧,@Wei-Shaw 建议先回滚一下,我们一起讨论下。

大概问题是这样:
OpenCode 通过修改 openai 的 baseURL 的方式使用sub2api时,默认 store=true。也就意味着,它会在调用过程中,省略 tool_call 的message,只保留 tool_output 及引用。由OpenAI自己找对应的tool_call。这在 OpenAI 正常的 API 中是生效的。

但是Codex的接口走的 chatgpt.com/backend/codex ,这个API 不支持 store=true (tool_call和tool_output必须成对,否则报错400)。所以需要 OpenCode 请求时传递完整的 tool_call 和 tool_output 链。

所以此时,你在sub2api 这一层强制让参数 store=true 或 store=false 都是没用的。这个应该是客户端处理的事情,否则难道要在sub2api层替Client端做 tool_call message 的缓存mapping吗?这也不合理。

所幸OpenCode提供了一个配置参数,支持开启 store=false 模式,如下配置即可:

{
  "provider": {
    "openai": {
      "options": {
        "baseURL": "https://xxx",
        "apiKey": "sk-xxx"
      },
      "models": {
        "gpt-5.2-codex": {
          "name": "GPT-5.2 Codex",
          "options": {
            "store": false
          },
          "variants": {
            "low": {},
            "medium": {},
            "high": {},
            "xhigh": {}
          }
        }
      }
    }
  },
  "agent": {
    "build": {
      "options": {
        "store": false
      }
    },
    "plan": {
      "options": {
        "store": false
      }
    }
  },
  "$schema": "https://opencode.ai/config.json"
}

这样配置后所使用的models、agents就都会走 store=false的逻辑了。

但遗憾的是,目前只有modelagent 下面可以配置 options.store ,还不能直接给 openai 整个 provider 配置 store=false。

已经给OpenCode提 PR了 anomalyco/opencode#8000 ,耐心等待合并就行了。以后就可以直接:

"provider": {
    "openai": {
      "options": {
        "baseURL": "https://xxx",
        "apiKey": "sk-xxx",
        "store": false
      }
     }
}

在用户 UI 上也加了这个,避免后人踩坑

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants