Skip to content

Commit 95116e0

Browse files
committed
Preserve Codex template context defaults
1 parent 185a2df commit 95116e0

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

sdk/api/handlers/openai/codex_client_models.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ func loadCodexClientModelTemplates() (map[string]map[string]any, map[string]any,
100100

101101
func applyCodexClientContextWindowOverride(entry map[string]any, id string, model map[string]any) {
102102
contextWindow := intModelValue(model, "context_length")
103-
if contextWindow <= 0 {
104-
if info := registry.LookupModelInfo(id); info != nil {
105-
contextWindow = info.ContextLength
106-
}
107-
}
108103
if contextWindow <= 0 {
109104
return
110105
}
@@ -126,7 +121,7 @@ func applyCodexClientModelMetadata(entry map[string]any, id string, model map[st
126121
if info.Description != "" {
127122
description = info.Description
128123
}
129-
if info.ContextLength > 0 {
124+
if info.ContextLength > 0 && contextWindow <= 0 {
130125
contextWindow = info.ContextLength
131126
}
132127
if info.Type == registry.OpenAIImageModelType {

sdk/api/handlers/openai/codex_client_models_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,40 @@ func TestBuildCodexClientModelsAppliesContextLengthToTemplateModel(t *testing.T)
2323
t.Fatal("expected template metadata to be preserved")
2424
}
2525
}
26+
27+
func TestBuildCodexClientModelsLeavesTemplateContextUnchangedWithoutOverride(t *testing.T) {
28+
models := buildCodexClientModels([]map[string]any{{
29+
"id": "gpt-5.4",
30+
"object": "model",
31+
"owned_by": "heybox",
32+
}})
33+
34+
if len(models) != 1 {
35+
t.Fatalf("models len = %d, want 1", len(models))
36+
}
37+
if got := intModelValue(models[0], "context_window"); got != 272000 {
38+
t.Fatalf("context_window = %d, want template default 272000", got)
39+
}
40+
if got := intModelValue(models[0], "max_context_window"); got != 1000000 {
41+
t.Fatalf("max_context_window = %d, want template default 1000000", got)
42+
}
43+
}
44+
45+
func TestBuildCodexClientModelsPrefersModelContextLengthForCustomModel(t *testing.T) {
46+
models := buildCodexClientModels([]map[string]any{{
47+
"id": "gpt-5.4-custom",
48+
"object": "model",
49+
"owned_by": "heybox",
50+
"context_length": 700000,
51+
}})
52+
53+
if len(models) != 1 {
54+
t.Fatalf("models len = %d, want 1", len(models))
55+
}
56+
if got := intModelValue(models[0], "context_window"); got != 700000 {
57+
t.Fatalf("context_window = %d, want 700000", got)
58+
}
59+
if got := intModelValue(models[0], "max_context_window"); got != 700000 {
60+
t.Fatalf("max_context_window = %d, want 700000", got)
61+
}
62+
}

0 commit comments

Comments
 (0)