Skip to content

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

Open
lennney wants to merge 4 commits 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 4 commits 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 value and falls back to the default 272000.

Root cause: Codex CLI looks up models in its catalog. Custom models aren't found, so the configured model_context_window is never used.

Solution

Modified apply_context_limits_to_config() to detect 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.

This allows Codex CLI to find the model in the catalog and use the user-specified context window.

Changes

  • relay_config.rs (+68 lines): Added ensure_custom_model_catalog() function and updated callers to pass home
  • ports.rs: Fixed unsafe set_var/remove_var calls for Rust 2024 edition
  • tests/relay_config.rs (+136 lines): 4 new test cases covering all scenarios

Test Results

All tests pass:

  • 68 relay_config tests ✅
  • 6 model_catalog tests ✅

Scenarios Covered

  1. ✅ Custom model + context_window → generates catalog
  2. ✅ Empty context_window → no catalog generated
  3. ✅ Empty model name → no catalog generated
  4. ✅ Existing model_catalog_json → no override

Closes #1260

lennney added 2 commits July 2, 2026 23:23
Prevents port collision when multiple Windows RDP users run Codex++
on the same machine.

Resolution order:
1. CODEX_PLUS_GUARD_PORT env var — exact override for all roles
2. CODEX_PLUS_LAUNCHER_GUARD_PORT / CODEX_PLUS_MANAGER_GUARD_PORT
   — role-specific env override
3. CODEX_PLUS_GUARD_PORT_OFFSET env var — explicit offset from base
4. Windows: auto-offset by USERNAME hash (mod 1000)
5. Other platforms: 0 (backward-compatible default)

Old constants LAUNCHER_GUARD_PORT / MANAGER_GUARD_PORT replaced
with launcher_guard_port() / manager_guard_port() functions.

Fixes BigPizzaV3#328
…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.

This allows Codex CLI to find the model in the catalog and use
the user-specified context window.

Also fixes unsafe set_var/remove_var calls in ports.rs tests
for Rust 2024 edition compatibility.

Closes BigPizzaV3#1260
@lennney lennney force-pushed the fix/model-context-window-custom branch from 32f5899 to f60bef3 Compare July 2, 2026 15:23
@lennney lennney force-pushed the fix/model-context-window-custom branch from 7a9d5ce to 95baadb Compare July 2, 2026 15:26
…nfig

The custom model catalog fallback (ensure_custom_model_catalog) was
incorrectly placed inside apply_context_limits_to_config, which runs
BEFORE apply_model_catalog_to_config. This caused two bugs:

1. For suffixed model_list: ensure_custom_model_catalog wrote
   model_catalog_custom.json first, then apply_model_catalog_to_config
   saw a mismatched model_catalog_json value and skipped relay catalog
   generation entirely.

2. For unsuffixed model_list: ensure_custom_model_catalog generated
   an unwanted catalog, even when no context_window was set.

Fix:
- Remove home param and ensure_custom_model_catalog call from
  apply_context_limits_to_config
- Add apply_custom_catalog_fallback() called AFTER
  apply_model_catalog_to_config at all profile-based call sites
- Update test for context_window without suffixes to expect
  custom fallback catalog generation
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.

[Bug]: config.toml 中的 model_context_window 对自定义供应商不生效

1 participant