Skip to content

fix: preserve replay tool output continuation#2247

Open
anzhen-tech wants to merge 1 commit intoWei-Shaw:mainfrom
anzhen-tech:codex/fix-ws-replay-function-call-output
Open

fix: preserve replay tool output continuation#2247
anzhen-tech wants to merge 1 commit intoWei-Shaw:mainfrom
anzhen-tech:codex/fix-ws-replay-function-call-output

Conversation

@anzhen-tech
Copy link
Copy Markdown

问题说明

现有修复并不完整。

当前版本只在“当前 payload”里检查是否存在 function_call_output,然后决定是否可以移除 previous_response_id 做恢复重试。

但在 WS ingress 的 store=false 重放链路里,function_call_output 不一定出现在当前客户端 payload 中。当前 payload 可能只是普通输入,而服务端会通过 buildOpenAIWSReplayInputSequence 把历史 turn 合并成完整 replay input。

也就是说,真实请求可能是:

  1. 历史 turn 中包含 function_call_output
  2. 当前 turn 只带普通输入和 previous_response_id
  3. preflight ping 失败
  4. 现有恢复逻辑只看当前 payload,误以为没有 function_call_output
  5. 于是删除 previous_response_id 并用 replay input 重试
  6. replay input 里仍然包含 function_call_output
  7. 上游缺少 response chain 锚点,返回:

No tool call found for function call output with call_id ...

为什么现有版本没有完全修复

现有版本只覆盖了“当前 payload 直接包含 function_call_output”的场景。

它没有覆盖“当前 payload 不包含 function_call_output,但重建后的 replay input 包含 function_call_output”的场景。

这就是线上仍然会出现:

No tool call found for function call output...

的原因。

本 PR 的修复

本 PR 将判断范围从:

  • 当前 payload 是否包含 function_call_output

扩展为:

  • 当前 payload 是否包含 function_call_output
  • 或者重建后的 replay input 是否包含 function_call_output

只要任一位置存在 function_call_output,就不能移除 previous_response_id,避免破坏上游 response chain。

额外安全处理

直接保留旧的 previous_response_id 并换新上游 WS 连接重试也不安全。

因为 previous_response_id 依赖原来的上游续链连接。原连接不可用后,把旧 previous_response_id 发到新连接,可能触发:

previous_response_not_found

所以本 PR 在这种情况下选择本地 fail-close,而不是把必然不可靠的请求继续发给新上游。

验证

go test ./internal/service -run 'TestOpenAIGatewayService_ProxyResponsesWebSocketFromClient_StoreDisabledPreflightPingFailClosesWhenReplayHasFunctionCallOutput|TestOpenAIGatewayService_ProxyResponsesWebSocketFromClient_StoreDisabledPreflightPingFailClosesWhenFunctionCallOutputNeedsPreviousResponseID' -count=1

go test ./internal/service -count=1

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@anzhen-tech
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 7, 2026
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.

1 participant