Repository navigation
fix(provider): support per-model Codex context windows #1996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ use dim_app_server::{ | |
| OpenAICodexOAuthService, | ||
| }, | ||
| grok_oauth::{GrokOAuthPlugin, GrokOAuthService}, | ||
| provider::{ModelPreferences, ProviderPlugin, ProviderService}, | ||
| provider::{ModelPreferences, ProviderCatalog, ProviderError, ProviderPlugin, ProviderService}, | ||
| }; | ||
| use futures_util::StreamExt; | ||
| use rutis::Ctx; | ||
|
|
@@ -1443,6 +1443,118 @@ async fn managed_provider_selection_http_recovery_and_restart_flow() { | |
| .await | ||
| .unwrap(); | ||
| assert!(updated.info.connection.unwrap().credential_configured); | ||
| let window = |catalog: &ProviderCatalog, id| { | ||
| let model = catalog.models.iter().find(|model| model.id == id).unwrap(); | ||
| ( | ||
| model.capabilities.context_window, | ||
| model.metadata.as_ref().unwrap().raw["max_context_window"].as_u64(), | ||
| ) | ||
| }; | ||
| let catalog = provider | ||
| .catalog_for("openai-codex".into(), &cancel) | ||
| .await | ||
| .unwrap() | ||
| .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") { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop skips every row whose |
||
| continue; | ||
| } | ||
| assert!( | ||
| matches!( | ||
| ( | ||
| model.capabilities.context_window, | ||
| raw.get("max_context_window").and_then(Value::as_u64) | ||
| ), | ||
| (Some(default), Some(ceiling)) if default > 0 && ceiling >= default | ||
| ), | ||
| "{} must declare a positive default and a ceiling at least as large", | ||
| model.id | ||
| ); | ||
| } | ||
| 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))); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This covers three of the fourteen Codex chat rows. Nothing asserts
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d491746. The new loop at |
||
| } | ||
| assert_eq!(window(&catalog, "gpt-5.5"), (Some(272_000), Some(272_000))); | ||
| let target = ModelId { | ||
| provider_id: "openai-codex".into(), | ||
| model_id: "gpt-6.2-sol".into(), | ||
| }; | ||
| let edit_window = |version, tokens| { | ||
| provider.update_model_config( | ||
| target.provider_id.clone(), | ||
| version, | ||
| target.model_id.clone(), | ||
| Some(serde_json::from_value(json!({"contextWindow": tokens})).unwrap()), | ||
| &cancel, | ||
| ) | ||
| }; | ||
| assert!(matches!( | ||
| edit_window(catalog.version, 872_001_u64).await, | ||
| Err(ProviderError::InvalidConfig(message)) if message.contains("872000") | ||
| )); | ||
| let edited = edit_window(catalog.version, 872_000_u64).await.unwrap(); | ||
| assert_eq!( | ||
| window(&edited, "gpt-6.2-sol"), | ||
| (Some(872_000), Some(872_000)) | ||
| ); | ||
| let selection = provider | ||
| .configuration( | ||
| Some(target.clone()), | ||
| None, | ||
| ModelPreferences::default(), | ||
| &cancel, | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!( | ||
| selection | ||
| .capability_snapshot | ||
| .unwrap() | ||
| .capabilities | ||
| .context_window, | ||
| 872_000 | ||
| ); | ||
| let startup = |tokens| { | ||
| provider.startup_configuration( | ||
| dim_app_server::protocol::ModelSelection { | ||
| provider: Some(target.provider_id.clone()), | ||
| model_id: Some(target.model_id.clone()), | ||
| }, | ||
| &home, | ||
| ModelPreferences::default(), | ||
| serde_json::from_value(json!({"contextWindow": tokens, "autoCompactWindow": 400_000})) | ||
| .unwrap(), | ||
| None, | ||
| &cancel, | ||
| ) | ||
| }; | ||
| assert!( | ||
| matches!(startup(872_001_u64).await, Err(error) if error.to_string().contains("872000")) | ||
| ); | ||
| let startup = startup(600_000_u64).await.unwrap(); | ||
| assert_eq!( | ||
| startup | ||
| .model | ||
| .capability_snapshot | ||
| .as_ref() | ||
| .unwrap() | ||
| .capabilities | ||
| .context_window, | ||
| 600_000 | ||
| ); | ||
| assert_eq!( | ||
| startup | ||
| .model | ||
| .metadata | ||
| .as_ref() | ||
| .unwrap() | ||
| .startup | ||
| .as_ref() | ||
| .unwrap() | ||
| .auto_compact_window, | ||
| Some(400_000) | ||
| ); | ||
| let old_request = { | ||
| let selection = provider | ||
| .configuration( | ||
|
|
@@ -1487,6 +1599,16 @@ async fn managed_provider_selection_http_recovery_and_restart_flow() { | |
| assert_eq!(record["credentialAuthority"], "openai_codex"); | ||
| assert!(record["credential"].is_null()); | ||
| assert!(!record.to_string().contains("rotated-")); | ||
| let legacy_window = 900_000_i64; | ||
| assert_eq!( | ||
| db.execute( | ||
| "UPDATE provider_models SET entry=json_set(entry, '$.capabilities.contextWindow', ?1) \ | ||
| WHERE provider_id='openai-codex' AND model_id='gpt-6.2-sol' AND source='override'", | ||
| [legacy_window], | ||
| ) | ||
| .unwrap(), | ||
| 1 | ||
| ); | ||
| drop(db); | ||
| let (restarted, _, _, _) = self::codex(&home, &f.base).await; | ||
| let plugins = [ | ||
|
|
@@ -1521,6 +1643,57 @@ async fn managed_provider_selection_http_recovery_and_restart_flow() { | |
| .await | ||
| .unwrap() | ||
| .unwrap(); | ||
| assert_eq!( | ||
| window(&catalog, "gpt-6.2-sol"), | ||
| (Some(872_000), Some(872_000)) | ||
| ); | ||
| let renamed = provider | ||
| .update_model_config( | ||
| target.provider_id.clone(), | ||
| catalog.version, | ||
| target.model_id.clone(), | ||
| Some(serde_json::from_value(json!({"displayName": "Renamed Sol"})).unwrap()), | ||
| &cancel, | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!( | ||
| renamed | ||
| .models | ||
| .iter() | ||
| .find(|model| model.id == target.model_id) | ||
| .unwrap() | ||
| .name, | ||
| "Renamed Sol" | ||
| ); | ||
| assert_eq!( | ||
| window(&renamed, "gpt-6.2-sol"), | ||
| (Some(872_000), Some(872_000)) | ||
| ); | ||
| let stored_window: i64 = rusqlite::Connection::open(home.join("native.sqlite")) | ||
| .unwrap() | ||
| .query_row( | ||
| "SELECT json_extract(entry, '$.capabilities.contextWindow') FROM provider_models \ | ||
| WHERE provider_id='openai-codex' AND model_id='gpt-6.2-sol' AND source='override'", | ||
| [], | ||
| |row| row.get(0), | ||
| ) | ||
| .unwrap(); | ||
| assert_eq!(stored_window, legacy_window); | ||
| let reset = provider | ||
| .update_model_config( | ||
| target.provider_id, | ||
| renamed.version, | ||
| target.model_id, | ||
| None, | ||
| &cancel, | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!( | ||
| window(&reset, "gpt-6.2-sol"), | ||
| (Some(500_000), Some(872_000)) | ||
| ); | ||
| assert_eq!( | ||
| catalog | ||
| .models | ||
|
|
||
There was a problem hiding this comment.
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_TOKENSvalue above the model ceiling, but the startup contract still promises the opposite.docs/design/model-startup.md:30accepts any positive safe integer and says it may exceed what the server supports, andcrates/dim-cli/src/args.rs:264-265advertises values up to 9007199254740991. A user who sets 900000 forgpt-6.2-solnow 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.
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:30now states the per-model codex ceiling and the failure before Session creation or resume reconfiguration, andcrates/dim-cli/src/args.rs:266states the same failure in the startup help.