fix(codex): default missing Claude tool input arguments

- Normalize omitted or blank Claude tool_use input to an empty JSON object string for Codex.
- Add a regression test that verifies the argument value and its JSON string type.

Closes: #7939
This commit is contained in:
Luis Pater
2026-11-23 21:13:37 +08:00
parent f5ef0c0f8e
commit d2b7dbbdbc
2 changed files with 23 additions and 1 deletions

View File

@@ -401,7 +401,11 @@ func convertClaudeRequestToCodex(modelName string, inputRawJSON []byte, stream,
}
_ = functionCallMessageDoc.Set("name", name)
}
_ = functionCallMessageDoc.Set("arguments", messageContentResult.Get("input").Raw)
arguments := strings.TrimSpace(messageContentResult.Get("input").Raw)
if arguments == "" {
arguments = "{}"
}
_ = functionCallMessageDoc.Set("arguments", arguments)
inputItems = append(inputItems, functionCallMessageDoc.Bytes())
case "tool_reference":
if len(pendingSystemReminders) > 0 {

View File

@@ -45,6 +45,24 @@ func TestConvertClaudeRequestToCodex_MaxOutputTokens(t *testing.T) {
}
}
func TestConvertClaudeRequestToCodex_DefaultsMissingToolInputToEmptyObject(t *testing.T) {
input := []byte(`{"model":"test-model","messages":[{"role":"assistant","content":[{"type":"tool_use","id":"call_1","name":"get_time"}]}]}`)
out, errConvert := ConvertClaudeRequestToCodex("test-model", input, false)
if errConvert != nil {
t.Fatalf("ConvertClaudeRequestToCodex() error = %v", errConvert)
}
functionCall := ojson.GetBytesNoCopy(out, `input.#(type=="function_call")`)
arguments := functionCall.Get("arguments")
if arguments.Type != ojson.String {
t.Fatalf("function_call.arguments type = %v, want string; item=%s", arguments.Type, functionCall.Raw)
}
if got := arguments.String(); got != "{}" {
t.Fatalf("function_call.arguments = %q, want %q; item=%s", got, "{}", functionCall.Raw)
}
}
func TestConvertClaudeRequestToCodex_SystemMessageScenarios(t *testing.T) {
tests := []struct {
name string