Skip to content

fix(provider): support per-model Codex context windows - #1996

Merged
yyhhyyyyyy merged 2 commits into
mainfrom
dimagent/1995-codex-context-window
Nov 22, 2026
Merged

yyhhyyyyyy merged 2 commits into
mainfrom
dimagent/1995-codex-context-window

Conversation

@zerob13

@zerob13 zerob13 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1995

Summary

  • Replace the flat 258,400-token Codex window with per-model defaults. GPT-6.2 Sol, GPT-6.1 Sol and GPT-6.1 Terra default to 500,000 tokens and can be configured up to 872,000. Dim computes request and compaction budgets from the nominal window. Codex model catalog
  • Use the existing Provider model edit and reset operations and the Session-local startup override. Catalog adoption preserves saved edits and bounds their effective windows. New values above the model ceiling report the allowed maximum. Provider contract

Design rule checklist

  • The process Provider owns the catalog, user configuration, new validation and edit transaction.
  • Session adoption uses the existing model configuration operation, handover and atomic publication.
  • Validation runs at the Provider's edit and startup boundaries, outside Timeline callbacks.
  • The Provider passes the capacity through the existing capability snapshot. The context consumer uses its established input path.
  • The existing managementMethods data face serves catalog reads and model edits. The requirement is met by the Provider's existing services.
  • The catalog and Provider-owned record hold configuration. The Session publishes the adopted value in its existing fact. Provider edits use the typed process write.

Documentation

  • The English and Chinese Provider design pages describe the Provider-owned contract. The ADR freeze check passed.

Verification

  • The managed OAuth fixture flow passed for default windows, persisted edits, over-ceiling rejection, Session-local startup and compaction settings, restart, and reset.
  • The existing v25 bundle upgrade and pinned base flows passed.
  • A catalog comparison checked all 14 Codex chat declarations and verified the other provider declarations against the base.
  • cargo fmt --all -- --check, node scripts/adr-check.mjs --base HEAD^1, and git diff --check HEAD^1 HEAD passed.
  • The fixture exercises Dim's configuration path. Live long-context capacity was outside the verification.

@zerob13
zerob13 marked this pull request as ready for review November 22, 2026 02:23

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_flow test managed_oauth_flow::managed_provider_selection_http_recovery_and_restart_flow passes locally with an isolated home and target.
  • CI matches the existing review's note: macos-native and scripts pass, while verify (linux) and the aggregate ci-ok are red on two tests outside this diff. No context-window test failed.
  • No conflict with origin/main. Open PR #1903 rewrites parts of model_catalog.rs and provider/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" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:30 now states the per-model ceiling and the failure before Session creation or resume reconfiguration, and crates/dim-cli/src/args.rs:266 states 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-1474 fails when a chat row lacks a positive max_context_window or 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_window writes an unmarked absent limit, which effective_models fills 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_record rejects a user model id that collides with an override (crates/dim-app-server/src/provider.rs:973-983), and validation keeps overrides unique, so index and user cannot both name one id. index always names the merge target for a base-model edit, and the new copy does not run for user models.
  • Source adoption: reseed_candidate keeps 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_flow passes 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 -- --check passes; git diff --check is clean.
  • CI at this head: ci-ok, verify (linux), macos-native, windows-cli, scripts and changes pass; web, static-checks, dependencies and acp-registry are skipped by path filters.
  • Merge-tree: clean against origin/main. PR #1916 merges cleanly. PR #1905 conflicts with origin/main on two docs files, and merging it with this head conflicts on those same files only; no conflict touches this change. PR #1903 still conflicts on crates/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") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@yyhhyyyyyy
yyhhyyyyyy merged commit d757f78 into main Nov 22, 2026
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.

Support per-model Codex context windows and user overrides

3 participants