chore(codex-rs) rm ModelInfo.base_instructions

This commit is contained in:
Dylan Hurd
2026-07-06 14:56:42 -07:00
parent 1013295c2d
commit 90da93fce5
26 changed files with 102 additions and 96 deletions
@@ -32,7 +32,6 @@ fn preset_to_info(preset: &ModelPreset, priority: i32) -> ModelInfo {
service_tiers: preset.service_tiers.clone(),
default_service_tier: preset.default_service_tier.clone(),
upgrade: preset.upgrade.as_ref().map(Into::into),
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -177,7 +177,6 @@ async fn list_models_uses_chatgpt_remote_catalog_as_source_of_truth() -> Result<
"supported_in_api": true,
"priority": 0,
"upgrade": null,
"base_instructions": "base instructions",
"supports_reasoning_summaries": false,
"support_verbosity": false,
"default_verbosity": null,
@@ -204,7 +204,6 @@ mod tests {
"supported_in_api": true,
"priority": 1,
"upgrade": null,
"base_instructions": "base instructions",
"supports_reasoning_summaries": false,
"support_verbosity": false,
"default_verbosity": null,
@@ -78,7 +78,6 @@ async fn models_client_hits_models_endpoint() {
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
-1
View File
@@ -254,7 +254,6 @@ fn test_model_info() -> ModelInfo {
"supported_in_api": true,
"priority": 1,
"upgrade": null,
"base_instructions": "base instructions",
"model_messages": null,
"supports_reasoning_summaries": false,
"support_verbosity": false,
+6 -1
View File
@@ -4,6 +4,7 @@ use codex_model_provider_info::ModelProviderInfo;
use codex_model_provider_info::WireApi;
use codex_protocol::models::DEFAULT_IMAGE_DETAIL;
use codex_protocol::models::InternalChatMessageMetadataPassthrough;
use codex_protocol::openai_models::ModelMessages;
use pretty_assertions::assert_eq;
use std::sync::Arc;
@@ -11,7 +12,11 @@ async fn process_compacted_history_with_test_session(
compacted_history: Vec<ResponseItem>,
previous_turn_settings: Option<&PreviousTurnSettings>,
) -> (Vec<ResponseItem>, Vec<ResponseItem>) {
let (session, turn_context) = crate::session::tests::make_session_and_context().await;
let (session, mut turn_context) = crate::session::tests::make_session_and_context().await;
turn_context.model_info.model_messages = Some(ModelMessages {
instructions_template: Some("current model instructions".to_string()),
instructions_variables: None,
});
let turn_context = Arc::new(turn_context);
session
.set_previous_turn_settings(previous_turn_settings.cloned())
+1 -1
View File
@@ -595,7 +595,7 @@ impl Codex {
// Resolve base instructions for the session. Priority order:
// 1. config.base_instructions override
// 2. conversation history => session_meta.base_instructions
// 3. base_instructions for current model
// 3. rendered instructions for the current model
let model_info = models_manager
.get_model_info(model.as_str(), &config.to_models_manager_config())
.await;
+10 -4
View File
@@ -57,6 +57,7 @@ use codex_protocol::models::FunctionCallOutputPayload;
use codex_protocol::models::ImageDetail;
use codex_protocol::models::PermissionProfile;
use codex_protocol::models::SandboxEnforcement;
use codex_protocol::openai_models::ModelMessages;
use codex_protocol::openai_models::ModelServiceTier;
use codex_protocol::permissions::FileSystemAccessMode;
use codex_protocol::permissions::FileSystemPath;
@@ -1262,20 +1263,21 @@ async fn get_base_instructions_no_user_content() {
for test_case in test_cases {
let model_info = model_info_for_slug(test_case.slug, &config);
let model_instructions = model_info.get_model_instructions(config.personality);
if test_case.expects_apply_patch_description {
assert_eq!(
model_info.base_instructions.as_str(),
model_instructions.as_str(),
prompt_with_apply_patch_instructions
);
}
{
let mut state = session.state.lock().await;
state.session_configuration.base_instructions = model_info.base_instructions.clone();
state.session_configuration.base_instructions = model_instructions.clone();
}
let base_instructions = session.get_base_instructions().await;
assert_eq!(base_instructions.text, model_info.base_instructions);
assert_eq!(base_instructions.text, model_instructions);
}
}
@@ -9128,7 +9130,11 @@ async fn record_context_updates_and_set_reference_context_item_persists_split_fi
#[tokio::test]
async fn build_initial_context_prepends_model_switch_message() {
let (session, turn_context) = make_session_and_context().await;
let (session, mut turn_context) = make_session_and_context().await;
turn_context.model_info.model_messages = Some(ModelMessages {
instructions_template: Some("current model instructions".to_string()),
instructions_variables: None,
});
let previous_turn_settings = PreviousTurnSettings {
model: "previous-regular-model".to_string(),
comp_hash: None,
-1
View File
@@ -239,7 +239,6 @@ fn remote_model_with_auto_review_override(slug: &str, review_model: &str) -> Mod
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -122,7 +122,6 @@ fn test_model_info(
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -947,7 +946,6 @@ async fn model_switch_to_smaller_model_updates_token_context_window() -> Result<
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -350,7 +350,6 @@ fn test_remote_model(slug: &str, priority: i32) -> ModelInfo {
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
+7 -18
View File
@@ -89,7 +89,7 @@ fn read_only_text_turn_with_personality(
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn personality_does_not_mutate_base_instructions_without_template() {
async fn personality_without_template_has_empty_model_instructions() {
let codex_home = TempDir::new().expect("create temp dir");
let mut config = load_default_config_for_test(&codex_home).await;
config
@@ -98,11 +98,8 @@ async fn personality_does_not_mutate_base_instructions_without_template() {
.expect("test config should allow feature update");
config.personality = Some(Personality::Friendly);
let model_info = codex_core::test_support::construct_model_info_offline("gpt-5.4", &config);
assert_eq!(
model_info.get_model_instructions(config.personality),
model_info.base_instructions
);
let model_info = codex_core::test_support::construct_model_info_offline("gpt-5.2", &config);
assert_eq!(model_info.get_model_instructions(config.personality), "");
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -119,11 +116,8 @@ async fn base_instructions_override_disables_personality_template() {
let model_info =
codex_core::test_support::construct_model_info_offline("gpt-5.3-codex", &config);
assert_eq!(model_info.base_instructions, "override instructions");
assert_eq!(
model_info.get_model_instructions(config.personality),
"override instructions"
);
assert_eq!(model_info.model_messages, None);
assert_eq!(model_info.get_model_instructions(config.personality), "");
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -449,7 +443,7 @@ async fn user_turn_personality_same_value_does_not_add_update_message() -> anyho
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn instructions_uses_base_if_feature_disabled() -> anyhow::Result<()> {
async fn instructions_are_empty_if_feature_disabled() -> anyhow::Result<()> {
let codex_home = TempDir::new().expect("create temp dir");
let mut config = load_default_config_for_test(&codex_home).await;
config
@@ -460,10 +454,7 @@ async fn instructions_uses_base_if_feature_disabled() -> anyhow::Result<()> {
let model_info =
codex_core::test_support::construct_model_info_offline("gpt-5.3-codex", &config);
assert_eq!(
model_info.get_model_instructions(config.personality),
model_info.base_instructions
);
assert_eq!(model_info.get_model_instructions(config.personality), "");
Ok(())
}
@@ -565,7 +556,6 @@ async fn remote_model_friendly_personality_instructions_with_feature() -> anyhow
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: Some(ModelMessages {
instructions_template: Some("Base instructions\n{{ personality }}\n".to_string()),
instructions_variables: Some(ModelInstructionsVariables {
@@ -681,7 +671,6 @@ async fn user_turn_personality_remote_model_template_includes_update_message() -
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: Some(ModelMessages {
instructions_template: Some("Base instructions\n{{ personality }}\n".to_string()),
instructions_variables: Some(ModelInstructionsVariables {
+3 -3
View File
@@ -153,7 +153,7 @@ async fn prompt_tools_are_consistent_across_requests() -> anyhow::Result<()> {
})
.build(&server)
.await?;
let base_instructions = thread_manager
let model_info = thread_manager
.get_models_manager()
.get_model_info(
config
@@ -162,8 +162,8 @@ async fn prompt_tools_are_consistent_across_requests() -> anyhow::Result<()> {
.expect("test config should have a model"),
&config.to_models_manager_config(),
)
.await
.base_instructions;
.await;
let base_instructions = model_info.get_model_instructions(config.personality);
codex
.submit(Op::UserInput {
+15 -25
View File
@@ -10,6 +10,7 @@ use codex_protocol::config_types::ReasoningSummary;
use codex_protocol::models::PermissionProfile;
use codex_protocol::openai_models::ConfigShellToolType;
use codex_protocol::openai_models::ModelInfo;
use codex_protocol::openai_models::ModelMessages;
use codex_protocol::openai_models::ModelPreset;
use codex_protocol::openai_models::ModelVisibility;
use codex_protocol::openai_models::ModelsResponse;
@@ -73,12 +74,10 @@ async fn remote_models_get_model_info_uses_longest_matching_prefix() -> Result<(
);
let specific = ModelInfo {
display_name: "GPT 5.3 Codex".to_string(),
base_instructions: "use specific prefix".to_string(),
..specific
};
let generic = ModelInfo {
display_name: "GPT 5.3".to_string(),
base_instructions: "use generic prefix".to_string(),
..generic
};
mount_models_once(
@@ -110,7 +109,7 @@ async fn remote_models_get_model_info_uses_longest_matching_prefix() -> Result<(
.await;
assert_eq!(model_info.slug, "gpt-5.3-codex-test");
assert_eq!(model_info.base_instructions, specific.base_instructions);
assert_eq!(model_info.display_name, specific.display_name);
Ok(())
}
@@ -483,7 +482,6 @@ async fn remote_models_remote_model_uses_unified_exec() -> Result<()> {
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -701,7 +699,7 @@ async fn remote_models_truncation_policy_with_tool_output_override() -> Result<(
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn remote_models_apply_remote_base_instructions() -> Result<()> {
async fn remote_models_apply_remote_instructions_template() -> Result<()> {
skip_if_no_network!(Ok(()));
skip_if_sandbox!(Ok(()));
@@ -712,7 +710,7 @@ async fn remote_models_apply_remote_base_instructions() -> Result<()> {
let model = "test-gpt-5-remote";
let remote_base = "Use the remote base instructions only.";
let remote_instructions = "Use the remote instructions template only.";
let remote_model = ModelInfo {
slug: model.to_string(),
display_name: "Parallel Remote".to_string(),
@@ -737,8 +735,10 @@ async fn remote_models_apply_remote_base_instructions() -> Result<()> {
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: remote_base.to_string(),
model_messages: None,
model_messages: Some(ModelMessages {
instructions_template: Some(remote_instructions.to_string()),
instructions_variables: None,
}),
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
default_reasoning_summary: ReasoningSummary::Auto,
@@ -777,13 +777,16 @@ async fn remote_models_apply_remote_base_instructions() -> Result<()> {
let mut builder = test_codex()
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_config(|config| {
config.model = Some("gpt-5.2".to_string());
.with_config(move |config| {
config
.features
.enable(codex_features::Feature::Personality)
.expect("test config should allow feature update");
config.model = Some(model.to_string());
});
let TestCodex {
codex,
cwd,
config,
thread_manager,
..
} = builder.build(&server).await?;
@@ -791,15 +794,6 @@ async fn remote_models_apply_remote_base_instructions() -> Result<()> {
let models_manager = thread_manager.get_models_manager();
wait_for_model_available(&models_manager, model).await;
core_test_support::submit_thread_settings(
&codex,
codex_protocol::protocol::ThreadSettingsOverrides {
model: Some(model.to_string()),
..Default::default()
},
)
.await?;
let cwd_path = cwd.abs();
let (sandbox_policy, permission_profile) =
turn_permission_fields(PermissionProfile::Disabled, cwd_path.as_path());
@@ -825,12 +819,9 @@ async fn remote_models_apply_remote_base_instructions() -> Result<()> {
wait_for_event(&codex, |event| matches!(event, EventMsg::TurnComplete(_))).await;
let base_model_info = models_manager
.get_model_info("gpt-5.2", &config.to_models_manager_config())
.await;
let body = response_mock.single_request().body_json();
let instructions = body["instructions"].as_str().unwrap();
assert_eq!(instructions, base_model_info.base_instructions);
assert_eq!(instructions, remote_instructions);
Ok(())
}
@@ -1232,7 +1223,6 @@ fn test_remote_model_with_policy(
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
-1
View File
@@ -1649,7 +1649,6 @@ async fn stdio_image_responses_are_sanitized_for_text_only_model() -> anyhow::Re
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -69,7 +69,6 @@ fn test_model_info(
service_tiers,
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
-1
View File
@@ -1372,7 +1372,6 @@ async fn view_image_tool_returns_unsupported_message_for_text_only_model() -> an
service_tiers: Vec::new(),
default_service_tier: None,
upgrade: None,
base_instructions: "base instructions".to_string(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
-1
View File
@@ -414,7 +414,6 @@ mod tests {
"supported_in_api": true,
"priority": 0,
"upgrade": null,
"base_instructions": "base instructions",
"supports_reasoning_summaries": false,
"support_verbosity": false,
"default_verbosity": null,
File diff suppressed because one or more lines are too long
@@ -46,7 +46,6 @@ fn remote_model_with_visibility(
"supported_in_api": true,
"priority": priority,
"upgrade": null,
"base_instructions": "base instructions",
"supports_reasoning_summaries": false,
"support_verbosity": false,
"default_verbosity": null,
+1 -5
View File
@@ -52,10 +52,7 @@ pub fn with_config_overrides(mut model: ModelInfo, config: &ModelsManagerConfig)
};
}
if let Some(base_instructions) = &config.base_instructions {
model.base_instructions = base_instructions.clone();
model.model_messages = None;
} else if !config.personality_enabled {
if config.base_instructions.is_some() || !config.personality_enabled {
model.model_messages = None;
}
@@ -80,7 +77,6 @@ pub fn model_info_from_slug(slug: &str) -> ModelInfo {
default_service_tier: None,
availability_nux: None,
upgrade: None,
base_instructions: BASE_INSTRUCTIONS.to_string(),
model_messages: local_personality_messages_for_slug(slug),
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -72,3 +72,34 @@ fn model_context_window_uses_model_value_without_override() {
assert_eq!(updated, model);
}
#[test]
fn base_instructions_override_disables_model_messages() {
let model = model_info_from_slug("gpt-5.2-codex");
let config = ModelsManagerConfig {
base_instructions: Some("custom instructions".to_string()),
personality_enabled: true,
..Default::default()
};
let updated = with_config_overrides(model.clone(), &config);
let mut expected = model;
expected.model_messages = None;
assert_eq!(updated, expected);
}
#[test]
fn disabled_personality_clears_model_messages() {
let model = model_info_from_slug("gpt-5.2-codex");
let config = ModelsManagerConfig {
personality_enabled: false,
..Default::default()
};
let updated = with_config_overrides(model.clone(), &config);
let mut expected = model;
expected.model_messages = None;
assert_eq!(updated, expected);
}
+28 -16
View File
@@ -21,7 +21,6 @@ use serde::de::DeserializeOwned;
use serde::de::Error;
use strum_macros::Display;
use strum_macros::EnumIter;
use tracing::warn;
use ts_rs::TS;
use crate::config_types::Personality;
@@ -370,7 +369,6 @@ pub struct ModelInfo {
pub default_service_tier: Option<String>,
pub availability_nux: Option<ModelAvailabilityNux>,
pub upgrade: Option<ModelInfoUpgrade>,
pub base_instructions: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model_messages: Option<ModelMessages>,
#[serde(default)]
@@ -466,21 +464,16 @@ impl ModelInfo {
.get_personality_message(personality)
.unwrap_or_default();
template.replace(PERSONALITY_PLACEHOLDER, personality_message.as_str())
} else if let Some(personality) = personality {
warn!(
model = %self.slug,
%personality,
"Model personality requested but model_messages is missing, falling back to base instructions."
);
self.base_instructions.clone()
} else {
self.base_instructions.clone()
String::new()
}
}
}
/// A strongly-typed template for assembling model instructions and developer messages. If
/// instructions_* is populated and valid, it will override base_instructions.
/// A strongly-typed template for assembling model instructions and developer messages.
///
/// When `instructions_template` is present, it is used even if `instructions_variables` is absent
/// or incomplete.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct ModelMessages {
pub instructions_template: Option<String>,
@@ -668,7 +661,6 @@ mod tests {
default_service_tier: None,
availability_nux: None,
upgrade: None,
base_instructions: "base".to_string(),
model_messages: spec,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -782,6 +774,18 @@ mod tests {
assert_eq!(instructions, "Hello friendly");
}
#[test]
fn get_model_instructions_uses_template_without_variables() {
let model = test_model(Some(ModelMessages {
instructions_template: Some("Hello {{ personality }}".to_string()),
instructions_variables: None,
}));
let instructions = model.get_model_instructions(Some(Personality::Friendly));
assert_eq!(instructions, "Hello ");
}
#[test]
fn get_model_instructions_always_strips_placeholder() {
let model = test_model(Some(ModelMessages {
@@ -836,7 +840,7 @@ mod tests {
}
#[test]
fn get_model_instructions_falls_back_when_template_is_missing() {
fn get_model_instructions_is_empty_when_template_is_missing() {
let model = test_model(Some(ModelMessages {
instructions_template: None,
instructions_variables: Some(ModelInstructionsVariables {
@@ -848,7 +852,16 @@ mod tests {
let instructions = model.get_model_instructions(Some(Personality::Friendly));
assert_eq!(instructions, "base");
assert_eq!(instructions, "");
}
#[test]
fn get_model_instructions_is_empty_when_model_messages_is_missing() {
let model = test_model(None);
let instructions = model.get_model_instructions(Some(Personality::Friendly));
assert_eq!(instructions, "");
}
#[test]
@@ -937,7 +950,6 @@ mod tests {
"supported_in_api": true,
"priority": 1,
"upgrade": null,
"base_instructions": "base",
"model_messages": null,
"supports_reasoning_summaries": false,
"default_reasoning_summary": "auto",
-1
View File
@@ -18,7 +18,6 @@ fn model_info() -> ModelInfo {
"priority": 1,
"availability_nux": null,
"upgrade": null,
"base_instructions": "base",
"model_messages": null,
"supports_reasoning_summaries": false,
"default_reasoning_summary": "auto",
-1
View File
@@ -25,7 +25,6 @@ fn model_with_shell_type(shell_type: ConfigShellToolType) -> ModelInfo {
default_service_tier: None,
availability_nux: None,
upgrade: None,
base_instructions: String::new(),
model_messages: None,
include_skills_usage_instructions: false,
supports_reasoning_summaries: false,
@@ -274,7 +274,6 @@ fn test_model_info(slug: &str, priority: i32, supports_fast_mode: bool) -> Model
"default_service_tier": null,
"availability_nux": null,
"upgrade": null,
"base_instructions": "base instructions",
"supports_reasoning_summaries": false,
"default_reasoning_summary": "none",
"support_verbosity": false,