Skip to content

fix(config): generate custom model catalog for non-standard models with context_window#1261

Open
lennney wants to merge 1 commit into
BigPizzaV3:mainfrom
lennney:fix/model-context-window-custom
Open

fix(config): generate custom model catalog for non-standard models with context_window#1261
lennney wants to merge 1 commit into
BigPizzaV3:mainfrom
lennney:fix/model-context-window-custom

Conversation

@lennney

@lennney lennney commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Problem

When model_context_window is set for a custom model (e.g. mimo-v2.5) that isn't in the standard OpenAI catalog, Codex CLI ignores the configured value and falls back to its default 272000 tokens.

Why this happens: Codex CLI uses model_catalog_json as its model metadata source. Custom models aren't in the built-in catalog, so model_context_window has no catalog entry to attach to — it gets dropped silently.

Solution

Detect when model_context_window is set but model_catalog_json isn't configured, and auto-generate ~/.codex/model_catalog_custom.json with the model's context window entry.

This is complementary to the existing suffix-based catalog (model_list: "deepseek-v4-pro[1M]") — this PR handles the single-model case where the user sets context_window directly in the UI.

New function: ensure_custom_model_catalog(home, config_text, profile) — no-ops when catalog already exists or context_window is empty.

Changes

  • relay_config.rs (+68): New ensure_custom_model_catalog() + caller updates to pass home
  • tests/relay_config.rs (+4 test cases): all catalog generation scenarios

Test Coverage

Scenario Verdict
Custom model + context_window → catalog generated
Empty context_window → skip
Empty model → skip
Existing model_catalog_json → preserved, no overwrite

Relation to #1451

This PR handles the per-model context_window use case. #1451 (model catalog precompute) handles the startup speed use case by generating a catalog for all models. Both write to separate files and don't conflict.

@BigPizzaV3

Copy link
Copy Markdown
Owner

当前 PR 的 Windows artifacts 检查仍然失败,暂时不能合并。请先 rebase/merge 最新 main,解决与近期 model catalog 和 watcher 修改的重叠,然后重新运行完整 CI;如果仍失败,请根据日志修复并说明原因。合并前需要三平台检查全部通过。

…th context_window

When model_context_window is set for a custom model (e.g. mimo-v2.5)
that isn't in the standard OpenAI catalog, Codex CLI previously
ignored the value and fell back to the default 272000.

Now apply_context_limits_to_config() detects when:
- model_context_window is set
- model_catalog_json is not already configured
- A model name is present

And generates ~/.codex/model_catalog_custom.json with the model's
context_window, then sets model_catalog_json to point to it.

Also fixes:
- Restore select_packaged_codex_debug_port lost in rebase
- Move custom catalog generation after model_catalog_to_config
  to avoid overwriting

Closes BigPizzaV3#1260
@lennney lennney force-pushed the fix/model-context-window-custom branch from 8dbeefc to f2f912f Compare July 13, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants