fix(aibridge): correlate other client-run tool result types (#32390)

This commit is contained in:
Roo Thorp authored and GitHub committed 2026-11-20 09:56:30 +00:00
1 parent 35bd24ee3b
commit cba1647cdf
2 files changed
+43 -4

No files matched your search

+18 -4
View File
@@ -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
}
@@ -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 {