codexcat: Codex shows a model's whole window and compacts at Long conversations' threshold (#3975, #3562; 01huadalang on Discord)

01huadalang on Discord: a Command Code model with a 1M window showed
258,400 in Codex. EasonSpirit (#3975) and greenfinchgreen-gif (#3562)
saw the same on OpenCode Go's 1M models.

The cause: magpie put Long conversations' threshold (272K by default, a
Compact at set on the model or provider, or a size typed in Settings)
into the Codex catalog entry's context_window, and the real window into
max_context_window. Codex shows context_window at 95% as the
conversation's context, so 272000 showed as 258400. The plugin was not
at fault: commandcode lists these models at 1M, from Command Code's
own list or its fallback table.

Now each catalog entry carries two values:
- context_window is the model's whole window.
- auto_compact_token_limit is the threshold, written only when it is
  below the window. Full window writes none.
This applies to entries magpie writes itself (entriesAt) and to a
relay's own Codex-shape entry (listedEntry). Codex 0.165 compacts at
the lesser of the threshold and 90% of the window. A
model_auto_compact_token_limit the user put in config.toml still comes
first.

Two other changes:
- max_context_window is never written now. It stays a field of
  codexcat's model, so Keep doesn't carry an old catalog's value
  forward as if the user had added it.
- Tag carries a format mark (catalogFormat), so a Codex holding a list
  in the old shape fetches it again.

Codex's own models (codex/) and Codex's base_instructions are
unchanged.

One behaviour moves. Codex used to compact at 90% of 272000 (244,800).
It now compacts at 272,000, the number the setting shows ("Compact at
272K").

Tests:
- TestCodexWindowShownCompactApart (new). Checks Command Code's
  claude-opus-5-5 at 1M, a relay entry, and a relay entry with its own
  Compact at, under the default, Compact at 400K, and Full window.
- TestCodexCatalogCompactAt, TestCodexCatalogToolSearch,
  TestCodexCatalogCompactAtReachesDisk and
  TestTypedWindowReachesCodexAndClaudeCode now expect the window in
  context_window and the threshold in auto_compact_token_limit.

Broken by hand: I put the old codexcat.go back. TestCodexCatalogToolSearch,
TestCodexCatalogCompactAt and TestCodexWindowShownCompactApart went red
("commandcode/claude-opus-5-5 told window/compact [272000 <nil>]; want
[1e+06 272000]"). With this change restored, all three are green.

Real Codex 0.165.0 in a sandbox CODEX_HOME, against a local fake
Responses server, using the catalog codexcat.Catalog now writes for
commandcode/claude-opus-5-5 at 1M:
- The rollout records model_context_window 950000. The old-shape entry
  (272000 with a max of 1000000) records 258400, the reporter's number.
- A turn reporting 260K tokens is not compacted. One reporting 280K is
  (CONTEXT CHECKPOINT COMPACTION). The old shape compacted at 260K.
- model_auto_compact_token_limit = 500000 in config.toml keeps the
  280K turn uncompacted.

Run (mote-run, at this change on origin/main 9b833205f; rebased onto 56bc3d515, which touches only GUI plugin files, and codexcat run again there: ok):
- gofmt -l: clean.
- go vet -tags nogui ./... for darwin, GOOS=linux and GOOS=windows.
- go test -tags nogui -count=1 -timeout 90m on codexcat, agent, gateway,
  provider, gui, cli and catalog: all 7 ok (codexcat 1.0s, agent 182s, gateway 510s,
  provider 119s, gui 70s, cli 43s, catalog 0.7s).

Not changed or not tried:
- Claude Code's CLAUDE_CODE_AUTO_COMPACT_WINDOW and Grok Build's
  context_window still carry the threshold, so they show it as the
  window. Filed as #4319.
- Not tried: a real Command Code account, and the Codex desktop app.
  The app reads the same catalog through the same app-server.
- #3553 asks for effective_context_window_percent 100. That isn't done:
  95% is Codex's own value for its models.
This commit is contained in:
yetone
2026-10-30 03:47:58 +08:00
parent 56bc3d515a
commit deb0b8da72
6 changed files with 125 additions and 40 deletions
+1
View File
@@ -23,6 +23,7 @@ something else shows up as drift.
| Keeping configs current | `Reseat` moves agents off a model magpie no longer serves (#200). `OnGateway` and `Rewire` write the new gateway address into every connected agent when the port changes. `Source` and `Stale` say what an unconnected agent runs on, and whether running copies still use the old list. | [`reseat.go`](../../internal/agent/reseat.go), [`rewire.go`](../../internal/agent/rewire.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
| Restarting a desktop app | Claude Desktop and WorkBuddy (WorkBuddy AI on macOS) read magpie's settings only as they start (微雨南山 and stones on Discord). `AppBehind` names one running here that started more than a second before magpie last changed what it reads (`changedAt`, which puts a change no file's time shows, such as Claude Desktop's gateway model list, at when it is first seen); only for an agent connected in magpie or disconnected in it. The row's Restart asks first in magpie's own dialog (`confirmRestart`), then `POST /api/agents/restart/{id}` runs `RestartApp`. On macOS (`restartApps`, the bundle found by id under `appFolders`, its `CFBundleExecutable` matched in `pgrep`) it quits as ⌘Q does and waits for every process of the bundle (`reopenBundle`); one still open after `appQuitWait` (a "Save?" question) is left as it is and not opened again (`noticeRestartStillOpen`). On Windows (`claude.exe` under `AnthropicClaude` or its Store package, `WorkBuddy.exe` outside the WorkBuddy AI folder) its processes are asked to close (`taskkill` without `/F`); one that has hidden every window and still runs after `appTrayGrace` (1s) is in the tray and has its tree ended at once (`waitClosed`, `winShown`: Claude Desktop hides its window in ~0.6s and keeps all its processes, so waiting the whole `appCloseWait` made a Restart ~12s where quitting by hand takes ~2s, CyberCaius on Discord, 10-29); one still showing a window (a question) gets `appCloseWait` before it is ended, and it is opened again through its Store id or Squirrel's stub. The Codex app's own Restart (`ReopenCodexApp`) asks first too, then ends only the app-server that app runs for itself (`provider.RestartCodexApp`: under its bundle, never a `--listen` one), as a switch does; the app starts another and keeps its window. Quitting and opening it, as before, opened a new window (yoshi037070 on Discord, 10-27). Codex on Windows, WorkBuddy AI on Windows and Linux aren't restarted: their process names aren't known. | [`apprestart.go`](../../internal/agent/apprestart.go), [`apprestart_windows.go`](../../internal/agent/apprestart_windows.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
| Codex background compaction | Long conversations' Codex background compaction, in Codex's opened row on the Agents page (`CodexAsyncCompact`, `CodexAsyncCompactPercent`, #2490) writes `[features.async_compaction]` `enabled = true` and `model_async_compact_threshold_percent` (Codex 0.163 reads it only in that table) into each Codex config magpie routes, on every `Sync`. The table is written only when every Codex that reads the config is 0.163.0-alpha.8 or later (`codexReaders`: the CLI on PATH, the Mac app's bundled `codex-cli/codex-package.json`, the Windows Store app and an editor's `openai.chatgpt` extension, whose versions aren't known, a WSL distro's CLI): an older Codex takes every unknown `[features]` entry for a bool and won't load a config with the table ("invalid type: map, expected a boolean"). Otherwise, or with no Codex found, magpie writes the bare `[features]` `async_compaction = true`, which every Codex loads, and no threshold; a table magpie wrote before is taken out on the next `Sync`, and Settings' row names the Codex that held it (`CodexAsyncHeld`). Codex starts a background compaction only on a provider whose `capabilities.remote_compaction` is `"v2"`, which it gives OpenAI and Azure alone, so `[model_providers.magpie]` gets `capabilities = { remote_compaction = "v2" }` too, also when the user turned the feature on by hand (#2493); `putProvider` carries the table's capabilities over when it writes it again. What magpie wrote is in the stash under `codex.async`: a value the user set, or changed since, is never written over and stays when the switch goes off; a bare `async_compaction = true` the stash doesn't name as magpie's (`bool`), an inline or dotted table is the user's as written. | [`codex_async.go`](../../internal/agent/codex_async.go) |
| Codex windows | Each magpie model's entry in Codex's catalog (`codexcat.entriesAt`, and `listedEntry` for a relay's own entry) says the model's whole window as `context_window`, which Codex shows (95% of it) as the conversation's context. Where Codex compacts goes in the entry's `auto_compact_token_limit`: the threshold set on the model or its provider, else Long conversations' (`settings.Working`, 272K by default), only when that is below the window; Full window writes none. Codex 0.165 compacts at the lesser of it and 90% of the window, and a `model_auto_compact_token_limit` the user put in config.toml comes before it. Until 10-30 the threshold went in `context_window` with the window as `max_context_window`, so a 1M model showed 258K in Codex (01huadalang on Discord); `max_context_window` stays a field magpie owns so `Keep` doesn't carry an old catalog's over. Codex's own models (`codex/`) keep their entry's window. `Tag` carries `catalogFormat`, so a Codex holding a list in the old shape asks again. `TestCodexCatalogCompactAt`, `TestCodexWindowShownCompactApart`. | [`codexcat.go`](../../internal/codexcat/codexcat.go) |
| Named omp profiles | omp keeps a profile's settings under `~/.omp/profiles/<name>` (or under `PI_CONFIG_DIR`), each with its own `config.yml` and `models.yml`. Every such profile is an agent of its own — `omp#<name>` on Windows, `omp#<name>@wsl:<distro>` in a distro — so each can be connected, drifted and disconnected on its own. They share omp's model lists (`ListsFor`), and the default `omp` row is the folder `ompDir`/`ompIn` already pick, so an `OMP_PROFILE` that row is already pointed at is not listed twice. A name omp refuses is not a row: `default`, a trailing dot, or a Windows reserved device name (`aux`, `nul`, `com1`, `lpt9.x`, `con.work`), on every platform (`ompProfileOK`). A distro's profile names come from its probe and are kept in `wsl.json`; a stopped distro is never started to list them, its profile rows showing what was last seen (`asleep`). | [`omp.go`](../../internal/agent/omp.go), [`wsl.go`](../../internal/agent/wsl.go) |
| WSL twins | On Windows each running distro is probed once, without starting a stopped one. The `wslKinds` agents found there become agents of their own, `<id>@wsl:<distro>`, edited through `\\wsl.localhost\<distro>`. A kind is found by its folder under the distro's home or by its command there (not one on a Windows drive). Where another tool shares one of them, the kind leaves it out: Gemini CLI is found by its command alone, because Antigravity keeps `~/.gemini` too. Antigravity CLI is found by its own `~/.gemini/antigravity-cli` or its `agy` command (mimi001234 on Discord). Goose is found by its folder alone, because a `goose` command can be pressly's migration tool. Reasonix also needs the version its command gives (`accept`), because the old npm client is named `reasonix` too. The gateway address and key follow the distro's networking: mirrored or NAT (`place`, `keyAt`). Under NAT the key is the gateway's WSL key (`gateway.WSLKey`, `-<agent>` after it where the agent's key names it), sharing on or off; the gateway listens at that address itself (gateway-routing's WSL under NAT). `ListsFor` keeps a twin's model picks under the Windows twin's id (#927). | [`wsl.go`](../../internal/agent/wsl.go), [`gatewaykey.go`](../../internal/agent/gatewaykey.go) |
| Settings tuned from use | Usage › Context's "Tuned for you" advises, per agent, the settings that would have spent the fewest tokens on the user's own calls of the range, and puts one in on a click. Package `tune` replays the calls `sessions.Calls` reads from the agents' session files under each candidate value (`Compact`, `CacheTTL`); `tuneOf` picks the agents and models (Claude Code per model, Codex pooled). `TuneRead`, `TuneApply` and `TuneUndo` know where each setting lives: Claude Code's `modelSettings.<model>.autoCompactWindow` (where its `/autocompact` saves), `promptCacheTtl` and `subagentPromptCacheTtl` in `~/.claude/settings.json`. Where Codex compacts, and Claude Code wherever magpie's own window is what it runs at, is one value with Long conversations in the agents' settings sheet (`settings.CompactAt`/`FullContext`, source `long`; 7eleven on Discord): the card reads it, Use sets it through `provider.SetCompactAt`, and Sync writes it into each agent's config as it does for the sheet; the note says it is Long conversations, shared by Codex and Claude Code (`compact-one-value.test.cjs`). The advice is weighed by tokens alone: it is labelled "Fewest tokens", and a compaction window it would change says it doesn't measure how well the agent keeps the task after a compaction, and that a lower window compacts more often (#1854, `context-tune.test.cjs`). A compaction row's "Other window…" opens the app menu with every value of the curve, each with its estimated extra tokens over the fewest and about how many compactions it would have made (`Point.compacts`, from the same replay), and puts the one picked in like Use (#1860). An agent whose files time its compactions also has their wait weighed (HirotaNagai on X): Claude Code's `compact_boundary` line says `compactMetadata.durationMs`, which `sessions` puts on the first call after it, and Codex compacts by a call of its own (the record a `compacted` line names, in rollouts since 2026-09), whose time is the compaction's (`Call.Compact`; an older rollout's compaction has no call and stays untimed). With 3 or more timed for a model (`minTimed`), `Facts.took` is their median seconds, each window says its wait (`Point.wait`, its compactions × `took`), and the row says what a compaction took, the wait at the advice against the window now, and the cheaper window the advice passed over for waiting longer (`Compaction.cheapest`, `wait_cheapest`) when it saves 3% or more; the advice is labelled "Tokens + wait", its caveat says tokens and waiting only, and the picker says each window's wait with "Fewest tokens" on the cheapest (`context-tune.test.cjs`). An agent or model with fewer timed reads and is advised as before. | [`internal/tune`](../../internal/tune/tune.go), [`tune.go`](../../internal/agent/tune.go), [`internal/gui/tune.go`](../../internal/gui/tune.go) |
+12 -12
View File
@@ -34,13 +34,13 @@ func TestCodexCatalogCompactAtReachesDisk(t *testing.T) {
t.Fatal(err)
}
contextOf := func() (window, max int) {
contextOf := func() (window, at int) {
t.Helper()
var got struct {
Models []struct {
Slug string `json:"slug"`
ContextWindow int `json:"context_window"`
MaxContext int `json:"max_context_window"`
Compact int `json:"auto_compact_token_limit"`
} `json:"models"`
}
raw := readFile(filepath.Join(home, ".codex", "magpie-models.json"))
@@ -49,7 +49,7 @@ func TestCodexCatalogCompactAtReachesDisk(t *testing.T) {
}
for _, m := range got.Models {
if m.Slug == "relay/glm-4.6" {
return m.ContextWindow, m.MaxContext
return m.ContextWindow, m.Compact
}
}
slugs := make([]string, 0, len(got.Models))
@@ -60,19 +60,19 @@ func TestCodexCatalogCompactAtReachesDisk(t *testing.T) {
return 0, 0
}
// relay's own "*" threshold, below the model's window: the window it is
// told is the threshold, and the model's own window is kept as the
// maximum so Codex still knows how much the model really takes
if window, max := contextOf(); window != 100000 || max != 204800 {
t.Fatalf("with relay's Compact at 100000: context_window = %d, max_context_window = %d; want 100000 and 204800", window, max)
// relay's own "*" threshold, below the model's window: Codex is told
// the model's whole window, which it shows, and compacts at the
// threshold
if window, at := contextOf(); window != 204800 || at != 100000 {
t.Fatalf("with relay's Compact at 100000: context_window = %d, auto_compact_token_limit = %d; want 204800 and 100000", window, at)
}
// the model's own threshold comes before its provider's
if err := provider.SetModelCompacts("relay", map[string]int{"*": 100000, "glm-4.6": 150000}); err != nil {
t.Fatal(err)
}
if window, max := contextOf(); window != 150000 || max != 204800 {
t.Fatalf("with relay/glm-4.6's own Compact at 150000: context_window = %d, max_context_window = %d; want 150000 and 204800", window, max)
if window, at := contextOf(); window != 204800 || at != 150000 {
t.Fatalf("with relay/glm-4.6's own Compact at 150000: context_window = %d, auto_compact_token_limit = %d; want 204800 and 150000", window, at)
}
// taken away, the one for every model answers again: the whole window,
@@ -80,7 +80,7 @@ func TestCodexCatalogCompactAtReachesDisk(t *testing.T) {
if err := provider.SetModelCompacts("relay", nil); err != nil {
t.Fatal(err)
}
if window, max := contextOf(); window != 204800 || max != 0 {
t.Fatalf("with no threshold set: context_window = %d, max_context_window = %d; want the window and no maximum", window, max)
if window, at := contextOf(); window != 204800 || at != 0 {
t.Fatalf("with no threshold set: context_window = %d, auto_compact_token_limit = %d; want the window and no threshold", window, at)
}
}
+11 -11
View File
@@ -16,7 +16,7 @@ import (
// one set on the provider for a model, isn't cut to magpie's default
// working window (272K, which Codex ran to 95% of: ~258K). Codex is told
// it as its context_window, on disk and in the gateway's list, with no
// max_context_window; Claude Code is handed no CLAUDE_CODE_AUTO_COMPACT_
// auto_compact_token_limit; Claude Code is handed no CLAUDE_CODE_AUTO_COMPACT_
// WINDOW, so it runs to the CLAUDE_CODE_MAX_CONTEXT_TOKENS it is told. A
// model whose window nobody typed keeps the default, and a size typed in
// Settings (Compact at) still comes before a typed window.
@@ -36,14 +36,14 @@ func TestTypedWindowReachesCodexAndClaudeCode(t *testing.T) {
must(provider.SaveGroup(provider.Group{ID: "flash", Name: "Flash", Members: []string{"ds/flash"}, Context: 500000}))
must(codex(home).Fields[0].Set("group/flash"))
type window struct{ context, max int }
type window struct{ context, compact int }
onDisk := func() map[string]window {
t.Helper()
var got struct {
Models []struct {
Slug string `json:"slug"`
Context int `json:"context_window"`
Max int `json:"max_context_window"`
Compact int `json:"auto_compact_token_limit"`
} `json:"models"`
}
raw := readFile(filepath.Join(home, ".codex", "magpie-models.json"))
@@ -52,7 +52,7 @@ func TestTypedWindowReachesCodexAndClaudeCode(t *testing.T) {
}
out := map[string]window{}
for _, m := range got.Models {
out[m.Slug] = window{m.Context, m.Max}
out[m.Slug] = window{m.Context, m.Compact}
}
return out
}
@@ -81,7 +81,7 @@ func TestTypedWindowReachesCodexAndClaudeCode(t *testing.T) {
expect("typed windows", map[string]window{
"group/flash": {500000, 0}, // the group's own size
"ds/pro": {400000, 0}, // the provider's for the model
"ds/flash": {272000, 1000000}, // nobody typed it: the default
"ds/flash": {1000000, 272000}, // nobody typed it: the default
}, map[string]int{"group/flash": 500000, "ds/pro": 400000, "ds/flash": 0})
path := filepath.Join(home, ".claude", "settings.json")
@@ -105,8 +105,8 @@ func TestTypedWindowReachesCodexAndClaudeCode(t *testing.T) {
must(provider.SetCompactAt(300000))
SyncCatalog()
expect("Compact at 300K", map[string]window{
"group/flash": {300000, 500000},
"ds/pro": {300000, 400000},
"group/flash": {500000, 300000},
"ds/pro": {400000, 300000},
}, map[string]int{"group/flash": 0, "ds/pro": 0})
must(a.Field("model").Set("group/flash"))
if c := env(claudeCompactEnv); c != "300000" {
@@ -196,15 +196,15 @@ func TestLargestMemberTypedWindow(t *testing.T) {
Models []struct {
Slug string `json:"slug"`
Context int `json:"context_window"`
Max int `json:"max_context_window"`
Compact int `json:"auto_compact_token_limit"`
} `json:"models"`
}
raw := readFile(filepath.Join(home, ".codex", "magpie-models.json"))
must(json.Unmarshal([]byte(raw), &disk))
for _, m := range disk.Models {
want := map[string][2]int{"group/ultra": {872000, 0}, "group/loose": {272000, 1000000}}
if w, ok := want[m.Slug]; ok && [2]int{m.Context, m.Max} != w {
t.Errorf("Codex: on disk %s is told %d (max %d); want %v", m.Slug, m.Context, m.Max, w)
want := map[string][2]int{"group/ultra": {872000, 0}, "group/loose": {1000000, 272000}}
if w, ok := want[m.Slug]; ok && [2]int{m.Context, m.Compact} != w {
t.Errorf("Codex: on disk %s is told %d (compacting at %d); want %v", m.Slug, m.Context, m.Compact, w)
}
}
+23 -7
View File
@@ -150,10 +150,19 @@ type model struct {
} `json:"truncation_policy"`
Tools []string `json:"experimental_supported_tools"`
Modalities []string `json:"input_modalities"`
Context *int `json:"context_window,omitempty"`
// the model's whole window when Context is the working one
// (settings.Working): Codex's model_context_window may raise it
// that far, as it does OpenAI's own models'
// the model's whole window, which Codex shows (95% of it) as the
// context the conversation has
Context *int `json:"context_window,omitempty"`
// where Codex compacts the conversation when that is before the
// window: the threshold set on the model or its provider, else
// Long conversations' (settings.Working). Codex compacts at the
// lesser of this and 90% of Context, and a
// model_auto_compact_token_limit the user put in config.toml comes
// before it. Until 10-30 the threshold went in Context, so a 1M
// model showed 258K in Codex (01huadalang on Discord).
AutoCompact *int `json:"auto_compact_token_limit,omitempty"`
// never written now; kept a field so it is one magpie owns, and
// Keep doesn't carry an old catalog's over
MaxContext *int `json:"max_context_window,omitempty"`
Tiers []tier `json:"service_tiers"`
// Without the search, Codex puts every MCP tool's schema (a
@@ -275,9 +284,9 @@ func entriesAt(ms []catalog.Model, after int, effort string) []any {
if m.Compact > 0 {
w = min(c, m.Compact)
}
e.Context = &w
e.Context = &c
if w < c {
e.MaxContext = &c
e.AutoCompact = &w
}
}
e.Truncation.Mode, e.Truncation.Limit = "tokens", 10000
@@ -897,7 +906,7 @@ func listedEntry(m catalog.Model, priority int, work settings.Settings, autoRevi
w = work.Working(c)
}
if w < c {
e["context_window"] = w
e["auto_compact_token_limit"] = w
}
}
// the levels, where the user's differ from the vendor's: those the
@@ -983,6 +992,7 @@ func Window(e map[string]any, n, most int) {
// Tag names a list of magpie's models: another list, another tag.
func Tag(ms []catalog.Model) string {
b, _ := json.Marshal(ms)
b = append(b, catalogFormat...)
sum := sha256.Sum256(b)
return hex.EncodeToString(sum[:6])
}
@@ -997,6 +1007,12 @@ func UsedTag(used []string) string {
return hex.EncodeToString(sum[:6])
}
// catalogFormat changes when the entries made of the same models change
// shape, so a Codex holding the list magpie gave before asks again: v2 put
// the window in context_window and the threshold in
// auto_compact_token_limit (10-30).
const catalogFormat = "v2"
// tagMark is where a tag starts in an ETag magpie made.
const tagMark = "+magpie-"
+5 -4
View File
@@ -71,8 +71,9 @@ func TestCodexCatalogImages(t *testing.T) {
// A model magpie describes has Codex search its MCP tools rather than send
// every one in each request (#258), with its prompt, context window, and
// neither code mode nor Responses Lite. A window above the working window
// is told as that, the whole one as its max, unless settings.FullContext.
// neither code mode nor Responses Lite. Its whole window is told, and a
// window above the working one is compacted at that (auto_compact_token_
// limit), unless settings.FullContext.
func TestCodexCatalogToolSearch(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
@@ -87,7 +88,7 @@ func TestCodexCatalogToolSearch(t *testing.T) {
t.Fatalf("%v", got)
}
e := got.Models[0]
if e["supports_search_tool"] != true || e["base_instructions"] != Prompt || e["context_window"] != float64(settings.WorkingWindow) || e["max_context_window"] != float64(996147) {
if e["supports_search_tool"] != true || e["base_instructions"] != Prompt || e["context_window"] != float64(996147) || e["auto_compact_token_limit"] != float64(settings.WorkingWindow) || e["max_context_window"] != nil {
t.Errorf("entry: %v", e)
}
if err := settings.Save(settings.Settings{FullContext: true}); err != nil {
@@ -99,7 +100,7 @@ func TestCodexCatalogToolSearch(t *testing.T) {
json.Unmarshal(Catalog([]catalog.Model{
{ID: "group/auto-gemini-3-8-flash", Name: "auto", Context: 996147},
}), &full)
if e := full.Models[0]; e["context_window"] != float64(996147) || e["max_context_window"] != nil {
if e := full.Models[0]; e["context_window"] != float64(996147) || e["auto_compact_token_limit"] != nil || e["max_context_window"] != nil {
t.Errorf("full context: %v", e)
}
for _, off := range []string{"tool_mode", "use_responses_lite", "multi_agent_version", "model_messages"} {
+73 -6
View File
@@ -30,7 +30,10 @@ func TestCodexCatalogCompactAt(t *testing.T) {
}), &got)
out := map[string][2]any{}
for _, e := range got.Models {
out[e["slug"].(string)] = [2]any{e["context_window"], e["max_context_window"]}
if e["max_context_window"] != nil {
t.Errorf("%s: max_context_window %v; the window is context_window", e["slug"], e["max_context_window"])
}
out[e["slug"].(string)] = [2]any{e["context_window"], e["auto_compact_token_limit"]}
}
return out
}
@@ -44,24 +47,88 @@ func TestCodexCatalogCompactAt(t *testing.T) {
}
}
check("default", map[string][2]any{
"d/flash": {float64(500000), float64(1000000)},
"d/flash": {float64(1000000), float64(500000)},
"d/pro": {float64(1000000), nil},
"x/big": {float64(settings.WorkingWindow), float64(1000000)},
"x/big": {float64(1000000), float64(settings.WorkingWindow)},
"x/small": {float64(128000), nil},
})
if err := settings.Save(settings.Settings{CompactAt: 400000}); err != nil {
t.Fatal(err)
}
check("compact at 400K", map[string][2]any{
"d/flash": {float64(500000), float64(1000000)},
"x/big": {float64(400000), float64(1000000)},
"d/flash": {float64(1000000), float64(500000)},
"x/big": {float64(1000000), float64(400000)},
"x/small": {float64(128000), nil},
})
if err := settings.Save(settings.Settings{CompactAt: 400000, FullContext: true}); err != nil {
t.Fatal(err)
}
check("full window", map[string][2]any{
"d/flash": {float64(500000), float64(1000000)},
"d/flash": {float64(1000000), float64(500000)},
"x/big": {float64(1000000), nil},
})
}
// Codex shows a model's context_window (95% of it) as the conversation's
// context, so a 1M model of a plugin's told magpie's 272K threshold there
// showed 258K (01huadalang on Discord, Command Code's 1M models). The
// window is the model's own, and the threshold goes where Codex compacts
// (auto_compact_token_limit), for a model magpie describes and for a
// relay's own entry alike.
func TestCodexWindowShownCompactApart(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
t.Setenv("XDG_CONFIG_HOME", filepath.Join(os.Getenv("HOME"), ".config"))
relay := json.RawMessage(`{"slug":"big-listed","display_name":"Big","base_instructions":"x","context_window":1000000,"max_context_window":1000000,"auto_compact_token_limit":null,"supported_reasoning_levels":[]}`)
entries := func() map[string]map[string]any {
var got struct {
Models []map[string]any `json:"models"`
}
json.Unmarshal(Catalog([]catalog.Model{
{ID: "commandcode/claude-opus-5-5", Name: "Claude Opus 5.5", Context: 1000000},
{ID: "relay/big-listed", Name: "Big", Context: 1000000, Codex: relay},
{ID: "relay/big-own", Name: "Big own", Context: 1000000, Codex: relay, Compact: 200000},
}), &got)
out := map[string]map[string]any{}
for _, e := range got.Models {
out[e["slug"].(string)] = e
}
return out
}
check := func(what string, want map[string][2]any) {
t.Helper()
got := entries()
for id, w := range want {
e := got[id]
if e == nil {
t.Fatalf("%s: no entry for %s", what, id)
}
if have := [2]any{e["context_window"], e["auto_compact_token_limit"]}; have != w {
t.Errorf("%s: %s told window/compact %v; want %v", what, id, have, w)
}
}
}
// magpie's default: the plugin's 1M model shows 1M and compacts at
// 272K; a relay's entry is the vendor's (its null), unless the user
// set a threshold on it
check("default", map[string][2]any{
"commandcode/claude-opus-5-5": {float64(1000000), float64(settings.WorkingWindow)},
"relay/big-listed": {float64(1000000), nil},
"relay/big-own": {float64(1000000), float64(200000)},
})
if err := settings.Save(settings.Settings{CompactAt: 400000}); err != nil {
t.Fatal(err)
}
check("compact at 400K", map[string][2]any{
"commandcode/claude-opus-5-5": {float64(1000000), float64(400000)},
"relay/big-listed": {float64(1000000), float64(400000)},
"relay/big-own": {float64(1000000), float64(200000)},
})
if err := settings.Save(settings.Settings{FullContext: true}); err != nil {
t.Fatal(err)
}
check("full window", map[string][2]any{
"commandcode/claude-opus-5-5": {float64(1000000), nil},
"relay/big-listed": {float64(1000000), nil},
})
}