From cdda333cd28703dce9cd31d5a57c9291c3171b86 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Thu, 3 Sep 2026 13:25:56 +0800 Subject: [PATCH] fix(codex): clear unsupported reasoning levels --- internal/client/codex/models/models.go | 4 +- internal/client/codex/models/models_test.go | 53 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/internal/client/codex/models/models.go b/internal/client/codex/models/models.go index 7b807c67..8cf9310b 100644 --- a/internal/client/codex/models/models.go +++ b/internal/client/codex/models/models.go @@ -374,7 +374,7 @@ func applyCodexClientInputModalitiesMetadata(entry map[string]any, modalities [] } func applyCodexClientThinkingMetadata(entry map[string]any, thinking *registry.ThinkingSupport, clientVersion string) { - if thinking == nil || len(thinking.Levels) == 0 { + if thinking == nil { return } @@ -398,6 +398,8 @@ func applyCodexClientThinkingMetadata(entry map[string]any, thinking *registry.T }) } if len(levels) == 0 { + delete(entry, "supported_reasoning_levels") + delete(entry, "default_reasoning_level") return } if defaultLevel == "" { diff --git a/internal/client/codex/models/models_test.go b/internal/client/codex/models/models_test.go index a9029b17..fe2852fc 100644 --- a/internal/client/codex/models/models_test.go +++ b/internal/client/codex/models/models_test.go @@ -493,3 +493,56 @@ func TestCodexClientModelsResponseUsesProvidedCapabilitiesForNewHomeModel(t *tes } } } + +func TestCodexClientModelsResponseDoesNotInheritUnsupportedReasoningLevels(t *testing.T) { + tests := []struct { + name string + version string + levels []string + wantEfforts []string + wantDefault string + }{ + {name: "modern client", version: "0.144.0", levels: []string{"max", "ultra"}, wantEfforts: []string{"max", "ultra"}, wantDefault: "max"}, + {name: "legacy client with no compatible level", version: "0.143.9", levels: []string{"max", "ultra"}}, + {name: "legacy client with one compatible level", version: "0.143.9", levels: []string{"high", "max"}, wantEfforts: []string{"high"}, wantDefault: "high"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + resp := BuildResponseForClient([]map[string]any{{ + "id": "home-extended-reasoning-model-test", + "thinking": ®istry.ThinkingSupport{ + Levels: tt.levels, + }, + }}, nil, false, tt.version) + models, ok := resp["models"].([]map[string]any) + if !ok || len(models) != 1 { + t.Fatalf("models = %#v, want one model", resp["models"]) + } + model := models[0] + if len(tt.wantEfforts) == 0 { + if _, exists := model["supported_reasoning_levels"]; exists { + t.Fatalf("supported_reasoning_levels = %#v, want absent", model["supported_reasoning_levels"]) + } + if _, exists := model["default_reasoning_level"]; exists { + t.Fatalf("default_reasoning_level = %#v, want absent", model["default_reasoning_level"]) + } + return + } + + rawLevels, ok := model["supported_reasoning_levels"].([]any) + if !ok || len(rawLevels) != len(tt.wantEfforts) { + t.Fatalf("supported_reasoning_levels = %#v, want %v", model["supported_reasoning_levels"], tt.wantEfforts) + } + for index, want := range tt.wantEfforts { + level, ok := rawLevels[index].(map[string]any) + if !ok || stringModelValue(level, "effort") != want { + t.Fatalf("supported_reasoning_levels[%d] = %#v, want %q", index, rawLevels[index], want) + } + } + if got := stringModelValue(model, "default_reasoning_level"); got != tt.wantDefault { + t.Fatalf("default_reasoning_level = %q, want %q", got, tt.wantDefault) + } + }) + } +} -- 2.51.2