mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
add client-side ModelInfo overrides
This commit is contained in:
@@ -13,6 +13,7 @@ use codex_otel::OtelManager;
|
||||
use codex_otel::TelemetryAuthMode;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::ReasoningSummary;
|
||||
use codex_protocol::openai_models::ModelInfoPatch;
|
||||
use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use core_test_support::load_default_config_for_test;
|
||||
@@ -233,8 +234,10 @@ async fn responses_stream_includes_subagent_header_on_other() {
|
||||
);
|
||||
}
|
||||
|
||||
// Request-construction integration test:
|
||||
// enabling summaries via config should result in reasoning.summary being sent in /responses.
|
||||
#[tokio::test]
|
||||
async fn responses_respects_model_info_overrides_from_config() {
|
||||
async fn responses_includes_reasoning_summary_when_enabled_in_config() {
|
||||
core_test_support::skip_if_no_network!();
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
@@ -352,6 +355,127 @@ async fn responses_respects_model_info_overrides_from_config() {
|
||||
);
|
||||
}
|
||||
|
||||
// Request-construction integration test for model_info_overrides:
|
||||
// patching supports_reasoning_summaries on the selected model should enable reasoning.summary
|
||||
// in the actual outbound /responses body.
|
||||
#[tokio::test]
|
||||
async fn responses_respects_model_info_overrides_from_config() {
|
||||
core_test_support::skip_if_no_network!();
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let response_body = responses::sse(vec![
|
||||
responses::ev_response_created("resp-1"),
|
||||
responses::ev_completed("resp-1"),
|
||||
]);
|
||||
|
||||
let request_recorder = responses::mount_sse_once(&server, response_body).await;
|
||||
|
||||
let provider = ModelProviderInfo {
|
||||
name: "mock".into(),
|
||||
base_url: Some(format!("{}/v1", server.uri())),
|
||||
env_key: None,
|
||||
env_key_instructions: None,
|
||||
experimental_bearer_token: None,
|
||||
wire_api: WireApi::Responses,
|
||||
query_params: None,
|
||||
http_headers: None,
|
||||
env_http_headers: None,
|
||||
request_max_retries: Some(0),
|
||||
stream_max_retries: Some(0),
|
||||
stream_idle_timeout_ms: Some(5_000),
|
||||
requires_openai_auth: false,
|
||||
supports_websockets: false,
|
||||
};
|
||||
|
||||
let codex_home = TempDir::new().expect("failed to create TempDir");
|
||||
let mut config = load_default_config_for_test(&codex_home).await;
|
||||
config.model = Some("gpt-3.5-turbo".to_string());
|
||||
config.model_provider_id = provider.name.clone();
|
||||
config.model_provider = provider.clone();
|
||||
config.model_reasoning_summary = ReasoningSummary::Detailed;
|
||||
config.model_info_overrides.insert(
|
||||
"gpt-3.5-turbo".to_string(),
|
||||
ModelInfoPatch {
|
||||
supports_reasoning_summaries: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let effort = config.model_reasoning_effort;
|
||||
let summary = config.model_reasoning_summary;
|
||||
let model = config.model.clone().expect("model configured");
|
||||
let auth_manager = AuthManager::from_auth_for_testing(CodexAuth::from_api_key("Test API Key"));
|
||||
let auth_mode = auth_manager.auth_mode().map(TelemetryAuthMode::from);
|
||||
let models_manager = ModelsManager::new(config.codex_home.clone(), auth_manager);
|
||||
let config = Arc::new(config);
|
||||
let model_info = models_manager.get_model_info(model.as_str(), &config).await;
|
||||
|
||||
let conversation_id = ThreadId::new();
|
||||
let session_source =
|
||||
SessionSource::SubAgent(SubAgentSource::Other("override-check".to_string()));
|
||||
let otel_manager = OtelManager::new(
|
||||
conversation_id,
|
||||
model.as_str(),
|
||||
model_info.slug.as_str(),
|
||||
None,
|
||||
Some("test@test.com".to_string()),
|
||||
auth_mode,
|
||||
"test_originator".to_string(),
|
||||
false,
|
||||
"test".to_string(),
|
||||
session_source.clone(),
|
||||
);
|
||||
|
||||
let client = ModelClient::new(
|
||||
None,
|
||||
conversation_id,
|
||||
provider,
|
||||
session_source,
|
||||
config.model_verbosity,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
None,
|
||||
);
|
||||
let mut client_session = client.new_session();
|
||||
|
||||
let mut prompt = Prompt::default();
|
||||
prompt.input = vec![ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".into(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: "hello".into(),
|
||||
}],
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
}];
|
||||
|
||||
let mut stream = client_session
|
||||
.stream(&prompt, &model_info, &otel_manager, effort, summary, None)
|
||||
.await
|
||||
.expect("stream failed");
|
||||
while let Some(event) = stream.next().await {
|
||||
if matches!(event, Ok(ResponseEvent::Completed { .. })) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let request = request_recorder.single_request();
|
||||
let body = request.body_json();
|
||||
let reasoning = body
|
||||
.get("reasoning")
|
||||
.and_then(|value| value.as_object())
|
||||
.cloned();
|
||||
|
||||
assert_eq!(
|
||||
reasoning
|
||||
.as_ref()
|
||||
.and_then(|value| value.get("summary"))
|
||||
.and_then(|value| value.as_str()),
|
||||
Some("detailed")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn responses_stream_includes_turn_metadata_header_for_git_workspace_e2e() {
|
||||
core_test_support::skip_if_no_network!();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use codex_core::CodexAuth;
|
||||
use codex_core::features::Feature;
|
||||
use codex_core::models_manager::manager::ModelsManager;
|
||||
use codex_protocol::openai_models::ModelInfoPatch;
|
||||
use codex_protocol::openai_models::ModelVisibility;
|
||||
use codex_protocol::openai_models::TruncationPolicyConfig;
|
||||
use core_test_support::load_default_config_for_test;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -42,3 +44,141 @@ async fn offline_model_info_with_tool_output_override() {
|
||||
TruncationPolicyConfig::tokens(123)
|
||||
);
|
||||
}
|
||||
|
||||
// Existing remote model path:
|
||||
// fetch model metadata for a known slug, then apply per-slug patch values from config.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn model_info_patch_overrides_remote_model_fields() {
|
||||
let codex_home = TempDir::new().expect("create temp dir");
|
||||
let mut config = load_default_config_for_test(&codex_home).await;
|
||||
config.features.enable(Feature::RemoteModels);
|
||||
let auth_manager = codex_core::AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
);
|
||||
let manager = ModelsManager::new(config.codex_home.clone(), auth_manager);
|
||||
|
||||
let mut baseline_config = config.clone();
|
||||
baseline_config.model_info_overrides.clear();
|
||||
let baseline = manager.get_model_info("gpt-5.1", &baseline_config).await;
|
||||
|
||||
config.model_info_overrides.insert(
|
||||
"gpt-5.1".to_string(),
|
||||
ModelInfoPatch {
|
||||
display_name: Some("gpt-5.1-dev".to_string()),
|
||||
context_window: Some(123_456),
|
||||
visibility: Some(ModelVisibility::Hide),
|
||||
supported_in_api: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let model_info = manager.get_model_info("gpt-5.1", &config).await;
|
||||
|
||||
let mut expected = baseline;
|
||||
expected.display_name = "gpt-5.1-dev".to_string();
|
||||
expected.context_window = Some(123_456);
|
||||
expected.visibility = ModelVisibility::Hide;
|
||||
expected.supported_in_api = false;
|
||||
|
||||
assert_eq!(model_info, expected);
|
||||
}
|
||||
|
||||
// Unknown model path:
|
||||
// when slug is not known remotely, manager falls back to synthetic metadata and still
|
||||
// applies the patch for that requested slug.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn model_info_patch_can_define_new_model_from_fallback() {
|
||||
let codex_home = TempDir::new().expect("create temp dir");
|
||||
let mut config = load_default_config_for_test(&codex_home).await;
|
||||
config.features.enable(Feature::RemoteModels);
|
||||
let auth_manager = codex_core::AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
);
|
||||
let manager = ModelsManager::new(config.codex_home.clone(), auth_manager);
|
||||
|
||||
let mut baseline_config = config.clone();
|
||||
baseline_config.model_info_overrides.clear();
|
||||
let baseline = manager.get_model_info("gpt-fake", &baseline_config).await;
|
||||
|
||||
config.model_info_overrides.insert(
|
||||
"gpt-fake".to_string(),
|
||||
ModelInfoPatch {
|
||||
display_name: Some("gpt-fake-dev".to_string()),
|
||||
context_window: Some(400_000),
|
||||
supports_parallel_tool_calls: Some(true),
|
||||
base_instructions: Some("Custom model instructions".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let model_info = manager.get_model_info("gpt-fake", &config).await;
|
||||
|
||||
let mut expected = baseline;
|
||||
expected.slug = "gpt-fake".to_string();
|
||||
expected.display_name = "gpt-fake-dev".to_string();
|
||||
expected.context_window = Some(400_000);
|
||||
expected.supports_parallel_tool_calls = true;
|
||||
expected.base_instructions = "Custom model instructions".to_string();
|
||||
|
||||
assert_eq!(model_info, expected);
|
||||
}
|
||||
|
||||
// Offline helper parity path:
|
||||
// construct_model_info_offline should apply model_info_overrides before global
|
||||
// top-level overrides, matching get_model_info precedence.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn offline_helper_applies_model_info_patch() {
|
||||
let codex_home = TempDir::new().expect("create temp dir");
|
||||
let mut config = load_default_config_for_test(&codex_home).await;
|
||||
config.features.enable(Feature::RemoteModels);
|
||||
config.model_context_window = Some(111_111);
|
||||
config.model_info_overrides.insert(
|
||||
"gpt-fake-offline".to_string(),
|
||||
ModelInfoPatch {
|
||||
display_name: Some("gpt-fake-offline-dev".to_string()),
|
||||
context_window: Some(222_222),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
let model_info =
|
||||
codex_core::test_support::construct_model_info_offline("gpt-fake-offline", &config);
|
||||
assert_eq!(model_info.display_name, "gpt-fake-offline-dev".to_string());
|
||||
assert_eq!(model_info.context_window, Some(111_111));
|
||||
}
|
||||
|
||||
// Prefix-resolution path (requested slug differs from resolved slug):
|
||||
// request a custom slug that resolves to known remote base model via longest-prefix match,
|
||||
// then ensure the requested-slug patch is still applied.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn model_info_patch_applies_when_requested_slug_differs_from_resolved_slug() {
|
||||
let codex_home = TempDir::new().expect("create temp dir");
|
||||
let mut config = load_default_config_for_test(&codex_home).await;
|
||||
config.features.enable(Feature::RemoteModels);
|
||||
let auth_manager = codex_core::AuthManager::from_auth_for_testing(
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
);
|
||||
let manager = ModelsManager::new(config.codex_home.clone(), auth_manager);
|
||||
|
||||
let requested_slug = "gpt-5.1-eval";
|
||||
let mut baseline_config = config.clone();
|
||||
baseline_config.model_info_overrides.clear();
|
||||
let baseline = manager
|
||||
.get_model_info(requested_slug, &baseline_config)
|
||||
.await;
|
||||
|
||||
config.model_info_overrides.insert(
|
||||
requested_slug.to_string(),
|
||||
ModelInfoPatch {
|
||||
display_name: Some("gpt-5.1-eval-dev".to_string()),
|
||||
context_window: Some(456_789),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let model_info = manager.get_model_info(requested_slug, &config).await;
|
||||
|
||||
let mut expected = baseline;
|
||||
expected.slug = requested_slug.to_string();
|
||||
expected.display_name = "gpt-5.1-eval-dev".to_string();
|
||||
expected.context_window = Some(456_789);
|
||||
|
||||
assert_eq!(model_info, expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user