Settings > Models > Routing has a Longest context field (magpie model context-cap [<size>|off], POST /api/settings/context-cap). It lowers every model's window to it, so a user need not set each model. A window the user set on a model, or on its provider with "*", wins and is not capped; a model whose window is unknown stays unknown. It is applied where the window is derived, provider.windowIn, so /v1/models, every agent's catalog, group windows and the compaction thresholds that follow the window all agree. Codex's own models take it through CodexNativeWindow, CodexWindow and codexcat.Cap on the list the gateway serves; the list's ETag carries the cap so Codex asks again. The provider editor's Listed value stays the vendor's. Run (mote): provider, codexcat, cli, settings, settingsapi, gateway tests; GUI context-cap, model-load, settings-places, i18n-keys, settings-general in chromium and webkit (en, zh); TestCoreScriptBudget; gofmt; vet on darwin, linux nogui and windows. Broken by hand: windowIn without the cap turns TestContextCapHoldsEveryModelButTheOnesTheUserSet and TestModelsListContextCap red. Not tried: the whole GUI suite (one row added to an existing list, no new API read on page load), a real Codex reading the capped list, Windows run. Not covered: Claude Code's own [1m] choice (claudeRunName) and agent/claude.go's fallback when a ref has no window.
25 lines
888 B
Go
25 lines
888 B
Go
package codexcat
|
|
|
|
import "testing"
|
|
|
|
// Cap holds one of Codex's own entries to a window, with the most it may be
|
|
// raised to and the threshold it compacts at, and touches nothing else.
|
|
func TestCapHoldsAnEntry(t *testing.T) {
|
|
e := map[string]any{"slug": "gpt-5.5", "context_window": float64(272000), "max_context_window": float64(872000), "auto_compact_token_limit": float64(244800)}
|
|
Cap(e, 200000)
|
|
for _, k := range []string{"context_window", "max_context_window", "auto_compact_token_limit"} {
|
|
if got, _ := e[k].(int); got != 200000 {
|
|
t.Errorf("%s: %v, want 200000", k, e[k])
|
|
}
|
|
}
|
|
short := map[string]any{"context_window": float64(128000)}
|
|
Cap(short, 200000)
|
|
if short["context_window"] != float64(128000) {
|
|
t.Errorf("a shorter window changed: %v", short)
|
|
}
|
|
Cap(short, 0)
|
|
if short["context_window"] != float64(128000) {
|
|
t.Errorf("no cap changed it: %v", short)
|
|
}
|
|
}
|