Repository navigation
fix(provider): support per-model Codex context windows - #1996
Conversation
eric8810
left a comment
There was a problem hiding this comment.
The pinned catalog's 500k defaults and 872k ceilings for the three named models match, and the exact Linux managed-provider flow passed the new bounds, startup override, persistence, and reset assertions.
[P2] Do not persist a clamped projection during an unrelated model edit. crates/dim-app-server/src/model_catalog.rs:829–843 caps the effective catalog copy, leaving an older explicitly saved window above the new model maximum intact. But provider/models.rs:449–468 uses that effective copy as the input to merge_visible_edit and writes back the whole entry. Editing only the display name, vision flag, or output limit silently overwrites the original saved context window with today's ceiling; it cannot recover if a later catalog raises that ceiling. This breaks the promised split between preserving explicit overrides and bounding their effective values. Keep the raw stored context when the edit does not set it, while continuing to validate newly submitted values. Add a legacy above-ceiling fixture covering catalog read, an unrelated edit, preserved stored value, and unchanged effective cap.
The required aggregate is also red: the log shows a branch replay/compaction timeout and a TUI task-history test timing out waiting for Earlier content not loaded; neither is established as a context-window regression.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
The change gives each openai-codex chat row a per-model default window and a metadata.raw.max_context_window ceiling, removes the flat provider override, validates new contextWindow values in provider.models.edit and the Session startup override, and caps stored overrides at read time. The targeted managed OAuth flow passes locally. One contract gap blocks approval.
Verdict: REQUEST_CHANGES
P2: The startup input contract and CLI help still promise any positive safe integer
crates/dim-app-server/src/provider/startup.rs:367-373 now rejects a DIM_MAX_CONTEXT_TOKENS value above the model ceiling for openai-codex. The startup owner document says the opposite: docs/design/model-startup.md:30 documents DIM_MAX_CONTEXT_TOKENS as any positive safe integer and explicitly says it is "not a promise that the server supports a larger window". crates/dim-cli/src/args.rs:264-265 tells users the value may go up to 9007199254740991. A user who follows either source and sets DIM_MAX_CONTEXT_TOKENS=900000 for gpt-6.2-sol now fails before the Session is created. The Provider page adds the ceiling (docs/design/appserver/provider-management.md:729-730), but it is not the owner of the startup input, so the two contracts now disagree.
Fix: update the DIM_MAX_CONTEXT_TOKENS row in docs/design/model-startup.md and the startup help text to state the per-model ceiling and the failure behavior, or state the ceiling in the startup document and link to the Provider page. Keep the Provider page as the owner of the limit value.
Agree with the existing P2
Agree with the existing review's P2 on persisting the clamped projection and its requested above-ceiling fixture; I do not repeat it here.
P3 optional: no check that every Codex chat row declares a ceiling
The new test checks three 500k rows and gpt-5.5 (crates/dim-app-server/tests/managed_oauth_flow.rs:1458-1460), and no catalog check asserts max_context_window on the other ten chat rows. A missing or misspelled field makes codex_context_window_ceiling return None (crates/dim-app-server/src/model_catalog.rs:75-83), so edits and the startup override silently accept any positive window for that model, contrary to the new paragraph. A small catalog test or the existing provider catalog script check should assert that every openai-codex chat row declares a positive ceiling no smaller than its default window.
Verification and scope
- Targeted
app_server_flowtestmanaged_oauth_flow::managed_provider_selection_http_recovery_and_restart_flowpasses locally with an isolated home and target. - CI matches the existing review's note:
macos-nativeandscriptspass, whileverify (linux)and the aggregateci-okare red on two tests outside this diff. No context-window test failed. - No conflict with
origin/main. Open PR #1903 rewrites parts ofmodel_catalog.rsandprovider/models.rs, and #1905/#1916 edit the same Provider design page, so a rebase may need a manual merge. No semantic overlap with this change was found. - Not verified: the external Codex catalog values behind the 14 rows, and live long-context behavior.
| .as_mut() | ||
| .expect("Provider adopts capabilities"); | ||
| if let Some(limit) = input.context_window { | ||
| if model.provider_id == "openai-codex" { |
There was a problem hiding this comment.
This now rejects a DIM_MAX_CONTEXT_TOKENS value above the model ceiling, but the startup contract still promises the opposite. docs/design/model-startup.md:30 accepts any positive safe integer and says it may exceed what the server supports, and crates/dim-cli/src/args.rs:264-265 advertises values up to 9007199254740991. A user who sets 900000 for gpt-6.2-sol now fails before the Session exists. Update the startup owner document and the startup help text to state the per-model ceiling and the failure, or move the ceiling statement there and link to the Provider page.
There was a problem hiding this comment.
Fixed in d491746. docs/design/model-startup.md:30 now states the per-model codex ceiling and the failure before Session creation or resume reconfiguration, and crates/dim-cli/src/args.rs:266 states the same failure in the startup help.
| .unwrap() | ||
| .unwrap(); | ||
| for model_id in ["gpt-6.2-sol", "gpt-6.1-sol", "gpt-6.1-terra"] { | ||
| assert_eq!(window(&catalog, model_id), (Some(500_000), Some(872_000))); |
There was a problem hiding this comment.
This covers three of the fourteen Codex chat rows. Nothing asserts max_context_window on the other ten, and codex_context_window_ceiling returns None when the field is absent or misspelled (crates/dim-app-server/src/model_catalog.rs:75-83), which silently removes both the edit and startup checks for that model. Add a catalog check or test that every openai-codex chat row declares a positive ceiling no smaller than its default window.
There was a problem hiding this comment.
Fixed in d491746. The new loop at crates/dim-app-server/tests/managed_oauth_flow.rs:1458-1474 requires a positive max_context_window at least as large as the default on every row whose raw type is chat, so a missing field now fails instead of being skipped.
eric8810
left a comment
There was a problem hiding this comment.
Re-reviewed d491746e. An edit that omits the context window preserves the raw stored value; only an explicit new value is checked against the ceiling. The SQLite regression covers a legacy 900,000-token value projected as 872,000, an unrelated rename that preserves 900,000 in storage, and reset to the bundled 500,000. Startup docs/help and positive ceiling checks for all bundled Codex chat rows also align with the contract. The exact Linux flow and required ci-ok passed. This verifies configuration and adoption, not live model capacity.
yyhhyyyyyy
left a comment
There was a problem hiding this comment.
Reviewed head d491746 against origin/main e4d981b.
The change gives each openai-codex chat row its own default context window and a read-only metadata.raw.max_context_window ceiling, removes the flat provider override, validates new contextWindow values in provider.models.edit and the Session startup override, clamps stored overrides at read time, and preserves a saved above-ceiling window when an unrelated model edit is made. The startup document and CLI help now state the per-model ceiling, and the flow test covers the catalog, above-ceiling rejection, startup override, legacy above-ceiling read, unrelated edit preservation, and reset.
Verdict: APPROVE
P3: The catalog ceiling check can still skip a row when its raw type changes
crates/dim-app-server/tests/managed_oauth_flow.rs:1460 skips every catalog row whose metadata.raw.type is not exactly chat, and the loop asserts no count or explicit id list. The product still treats a row with no type as conversational: chat_only_unavailable excludes a model only when the kind is present and differs from chat (crates/dim-app-server/src/provider.rs:1136-1142). If a catalog edit drops or misspells type on one of the ten rows not pinned below, the loop silently stops checking that row. With its max_context_window also absent, codex_context_window_ceiling returns None (crates/dim-app-server/src/model_catalog.rs:76-83), so DIM_MAX_CONTEXT_TOKENS=900000 and edits above the intended ceiling are accepted for a model that is still selectable.
Fix: assert the expected number of chat rows (14) or list their ids, so a lost type fails the test instead of shrinking coverage.
Prior findings
- The startup contract mismatch is fixed:
docs/design/model-startup.md:30now states the per-model ceiling and the failure before Session creation or resume reconfiguration, andcrates/dim-cli/src/args.rs:266states it in the startup help. The rejection runs after model resolution and applies to new Sessions and resume updates (crates/dim-app-server/src/provider/startup.rs:367-373,crates/dim-app-server/src/connection.rs:1657,crates/dim-app-server/src/connection.rs:2459). - The catalog coverage gap is fixed for every row the test classifies as chat:
crates/dim-app-server/tests/managed_oauth_flow.rs:1458-1474fails when a chat row lacks a positivemax_context_windowor has a ceiling below its default. The P3 above is the remaining type-dependent edge. - The earlier P2 on preserving the saved window is fixed: an unrelated rename keeps the stored 900,000 value while the effective catalog stays at 872,000, and reset restores the bundled 500,000 (
crates/dim-app-server/src/provider/models.rs:454-466,crates/dim-app-server/tests/managed_oauth_flow.rs:1650-1696).
Path checks
- No stored override: an edit without
context_windowwrites an unmarked absent limit, whicheffective_modelsfills from the base (crates/dim-app-server/src/model_catalog.rs:828-846); no base window is erased. - Stored override below, at, or above the ceiling: the new branch copies the stored value before the merge, so an unrelated edit preserves it, and read-time clamping still caps the effective window.
- Reset: removes the override and returns the bundled default.
- User models:
validate_static_recordrejects a user model id that collides with an override (crates/dim-app-server/src/provider.rs:973-983), and validation keeps overrides unique, soindexandusercannot both name one id.indexalways names the merge target for a base-model edit, and the new copy does not run for user models. - Source adoption:
reseed_candidatekeeps overrides and user models (crates/dim-app-server/src/provider.rs:1386-1403), and the read-time clamp applies the adopted base ceiling.
Verification
cargo test -p dim-app-server --test app_server_flow managed_provider_selection_http_recovery_and_restart_flowpasses at the reviewed head, with an isolated home, target and XDG directories.cargo test -p dim-app-server --test app_server_flow model_catalog_flow::passes (60 tests).cargo fmt --all -- --checkpasses;git diff --checkis clean.- CI at this head:
ci-ok,verify (linux),macos-native,windows-cli,scriptsandchangespass;web,static-checks,dependenciesandacp-registryare skipped by path filters. - Merge-tree: clean against
origin/main. PR #1916 merges cleanly. PR #1905 conflicts withorigin/mainon two docs files, and merging it with this head conflicts on those same files only; no conflict touches this change. PR #1903 still conflicts oncrates/dim-app-server/src/provider/models.rs; that overlap predates this head and the new commit adds no new file to it. - Not verified: the external Codex catalog values behind the 14 rows, live long-context behavior, and a source adoption upgrade from a pre-PR catalog state (covered by code inspection only).
| .unwrap(); | ||
| for model in &catalog.models { | ||
| let raw = &model.metadata.as_ref().unwrap().raw; | ||
| if raw.get("type").and_then(Value::as_str) != Some("chat") { |
There was a problem hiding this comment.
The loop skips every row whose metadata.raw.type is not exactly chat and asserts no count or full id set. A row that loses type is still treated as conversational, because chat_only_unavailable excludes a model only when the kind is present and differs from chat (crates/dim-app-server/src/provider.rs:1136-1142). If that row also lacks max_context_window, codex_context_window_ceiling returns None (crates/dim-app-server/src/model_catalog.rs:76-83), so edits and DIM_MAX_CONTEXT_TOKENS above the intended ceiling are accepted for a model that remains selectable, while this test still passes. Assert the expected 14 chat rows or list their ids so a lost type fails here instead of shrinking coverage.
Fixes #1995
Summary
Design rule checklist
managementMethodsdata face serves catalog reads and model edits. The requirement is met by the Provider's existing services.Documentation
Verification
cargo fmt --all -- --check,node scripts/adr-check.mjs --base HEAD^1, andgit diff --check HEAD^1 HEADpassed.