From cba1647cdff1cea091d2b1f8482b9b30f8fa39cc Mon Sep 17 00:00:00 2001 From: Roo Thorp Date: Fri, 20 Nov 2026 09:56:30 +0000 Subject: [PATCH] fix(aibridge): correlate other client-run tool result types (#32390) --- aibridge/intercept/responses/reqpayload.go | 22 +++++++++++++--- .../responses/reqpayload_internal_test.go | 25 +++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/aibridge/intercept/responses/reqpayload.go b/aibridge/intercept/responses/reqpayload.go index d4e83f6333e..5ab74099e8d 100644 --- a/aibridge/intercept/responses/reqpayload.go +++ b/aibridge/intercept/responses/reqpayload.go @@ -19,6 +19,7 @@ import ( const ( reqPathBackground = "background" reqPathCallID = "call_id" + reqPathID = "id" reqPathRole = "role" reqPathInput = "input" reqPathParallelToolCalls = "parallel_tool_calls" @@ -27,11 +28,15 @@ const ( ) var ( + constApplyPatchCallOutput = string(constant.ValueOf[constant.ApplyPatchCallOutput]()) + constComputerCallOutput = string(constant.ValueOf[constant.ComputerCallOutput]()) constCustomToolCallOutput = string(constant.ValueOf[constant.CustomToolCallOutput]()) constDeveloper = string(constant.ValueOf[constant.Developer]()) constFunctionCallOutput = string(constant.ValueOf[constant.FunctionCallOutput]()) constInputText = string(constant.ValueOf[constant.InputText]()) + constLocalShellCallOutput = string(constant.ValueOf[constant.LocalShellCallOutput]()) constReasoning = string(constant.ValueOf[constant.Reasoning]()) + constShellCallOutput = string(constant.ValueOf[constant.ShellCallOutput]()) constSystem = string(constant.ValueOf[constant.System]()) constUser = string(constant.ValueOf[constant.User]()) @@ -95,16 +100,25 @@ func (p RequestPayload) correlatingToolCallID() *string { // because the full history is resent on every request, so a new prompt // always has older tool results earlier in the input. // - // Both function and custom (freeform) tool results reference the - // originating tool call by call_id. Codex sends custom_tool_call_output - // for custom tools such as apply_patch. + // Results of tools the client runs reference the originating tool call + // by call_id. Codex sends custom_tool_call_output for custom tools such + // as apply_patch. Hosted tools (web search, file search, code + // interpreter, image generation, MCP) run within a single response and + // send no result back, so they never correlate. switch itemType { - case constFunctionCallOutput, constCustomToolCallOutput: + case constFunctionCallOutput, constCustomToolCallOutput, + constComputerCallOutput, constShellCallOutput, + constApplyPatchCallOutput, constLocalShellCallOutput: default: return nil } callID := item.Get(reqPathCallID).String() + // The API schema gives local_shell_call_output only an id field, which + // holds the call ID, but clients also send call_id. + if callID == "" && itemType == constLocalShellCallOutput { + callID = item.Get(reqPathID).String() + } if callID == "" { return nil } diff --git a/aibridge/intercept/responses/reqpayload_internal_test.go b/aibridge/intercept/responses/reqpayload_internal_test.go index 1156da225fe..06b07ca2e68 100644 --- a/aibridge/intercept/responses/reqpayload_internal_test.go +++ b/aibridge/intercept/responses/reqpayload_internal_test.go @@ -153,6 +153,31 @@ func TestCorrelatingToolCallID(t *testing.T) { name: "tool result missing call id followed by developer message does not fall back to older result", payload: []byte(`{"model":"gpt-5","input":[{"type":"function_call_output","call_id":"call_first","output":"r1"},{"type":"function_call_output","output":"r2"},{"role":"developer","content":"dev"}]}`), }, + { + name: "computer_call_output", + payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"computer_call_output","call_id":"call_computer","output":{"type":"computer_screenshot","image_url":"data:image/png;base64,AA=="}}]}`), + wantCall: new("call_computer"), + }, + { + name: "shell_call_output followed by developer message", + payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"shell_call_output","call_id":"call_shell","output":[{"stdout":"/home","stderr":"","outcome":{"type":"exit","exit_code":0}}]},{"role":"developer","content":"dev"}]}`), + wantCall: new("call_shell"), + }, + { + name: "apply_patch_call_output", + payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"apply_patch_call_output","call_id":"call_patch","status":"completed"}]}`), + wantCall: new("call_patch"), + }, + { + name: "local_shell_call_output with call_id", + payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"local_shell_call_output","call_id":"call_local","output":"ok"}]}`), + wantCall: new("call_local"), + }, + { + name: "local_shell_call_output with only id", + payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"local_shell_call_output","id":"call_local","output":"ok"}]}`), + wantCall: new("call_local"), + }, } for _, tc := range tests {