Files
magpie/internal/codexcat
yetone deb0b8da72 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.
2026-10-30 03:47:58 +08:00
..
test: every package's tests pass on Windows, and none writes outside its sandbox (the user: 把 Windows 上那几个失败的测试修掉) — on a Windows box the suite failed in most packages, and the root package hung for 25 minutes. Tests set HOME, which os.UserHomeDir ignores on Windows (it reads USERPROFILE), so they read and wrote the runner's own home; each now sets USERPROFILE beside HOME, and Devin's, Goose's, Crush's and Claude Desktop's tests set APPDATA/LOCALAPPDATA, where those keep their files there. said() read the command's output only once it returned, and a pipe holds a few KB on Windows, so magpie model --help blocked forever; it reads while the command writes. Unix permission bits (the gateway key store's 0600 too), exec bits and symlinks Windows lacks are checked only off Windows; TOML strings hold Windows paths as literal strings, JSON as marshalled ones; a URL's path is compared as one. The provider and usage packages run in a home of their own (TestMain, as the gateway's already does), since a CLI's identity kept by a refresh still going when its test ended landed in the runner's ~/.config/magpie — and on a Mac in the user's own. Two product fixes came out of it: imagemcp took a file:///C:/… root or image for the path /C:/…, which doesn't exist on Windows, and now makes a Windows path of it (a host for a UNC share); and session discovery could keep a new Cowork session hidden on Linux, where a folder's mtime is a kernel tick and its size doesn't change, so an entry added within the tick of the last listing left both as they were — a listing made within 2s of its folder's last change is read again, as git does for racy files. TestFilePath and TestRacyDirectoryListedAgain fail without the change. On Windows 11 every package passes (32 of 32) and a run of each package in a fresh home leaves nothing in home, APPDATA or LOCALAPPDATA; on Linux (WSL) and macOS go test -tags nogui ./... passes. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build pass.
2026-10-01 23:15:07 +08:00