mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Preserve base instruction provenance across sessions (#37446)
## Why Persisted base instructions need to retain whether they were explicitly customized or generated from a model template. Without that distinction, forks and config-lock replays can treat model-generated instructions as custom and keep the wrong template after a model or personality change. ## What changed - Record custom or model provenance with base instructions in rollouts and config locks. - Preserve custom instructions across model changes, while allowing model-generated instructions to follow the selected model and personality. - Keep legacy rollouts without provenance compatible and propagate provenance through forks and spawned agents. ## Testing - Cover provenance serialization and legacy rollout decoding. - Cover role personality changes, forked model changes, config-lock replay, and multi-agent configuration. GitOrigin-RevId: 801c26559835f558027ce5112700c0cd31fcb21b
This commit is contained in:
@@ -18,6 +18,8 @@ use codex_config::ConfigLayerStack;
|
||||
use codex_config::config_toml::ConfigToml;
|
||||
use codex_config::loader::resolve_relative_paths_in_config_toml;
|
||||
use codex_exec_server::LOCAL_FS;
|
||||
use codex_features::Feature;
|
||||
use codex_protocol::models::BaseInstructionsProvenance;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::BTreeSet;
|
||||
use std::path::Path;
|
||||
@@ -175,6 +177,8 @@ mod reload {
|
||||
let preserve_current_model = role_layer_toml.get("model").is_none();
|
||||
let preserve_current_reasoning_effort =
|
||||
role_layer_toml.get("model_reasoning_effort").is_none();
|
||||
let preserve_current_base_instructions = role_layer_toml.get("instructions").is_none()
|
||||
&& role_layer_toml.get("model_instructions_file").is_none();
|
||||
let mut overrides = reload_overrides(
|
||||
config,
|
||||
preserve_current_model,
|
||||
@@ -206,6 +210,24 @@ mod reload {
|
||||
.model_reasoning_effort
|
||||
.clone_from(&config.model_reasoning_effort);
|
||||
}
|
||||
if preserve_current_base_instructions {
|
||||
let personality_changed = config.personality != next_config.personality
|
||||
|| config.features.enabled(Feature::Personality)
|
||||
!= next_config.features.enabled(Feature::Personality);
|
||||
if personality_changed
|
||||
&& matches!(
|
||||
config.base_instructions_provenance,
|
||||
Some(BaseInstructionsProvenance::Model { .. })
|
||||
)
|
||||
{
|
||||
next_config.base_instructions = None;
|
||||
next_config.base_instructions_provenance = None;
|
||||
} else {
|
||||
next_config.base_instructions = config.base_instructions.clone();
|
||||
next_config.base_instructions_provenance =
|
||||
config.base_instructions_provenance.clone();
|
||||
}
|
||||
}
|
||||
Ok(next_config)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::config::ConfigBuilder;
|
||||
use crate::plugins::plugins_manager_for_config;
|
||||
use crate::skills_load_input_from_config;
|
||||
use codex_protocol::config_types::ServiceTier;
|
||||
use codex_protocol::models::BaseInstructionsProvenance;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -179,6 +180,12 @@ async fn apply_role_preserves_unspecified_keys() {
|
||||
|
||||
config.model = Some("spawn-model".to_string());
|
||||
config.model_reasoning_effort = Some(ReasoningEffort::Low);
|
||||
config.base_instructions = Some("inherited model instructions".to_string());
|
||||
config.base_instructions_provenance = Some(BaseInstructionsProvenance::Model {
|
||||
model: "parent-model".to_string(),
|
||||
});
|
||||
let base_instructions = config.base_instructions.clone();
|
||||
let provenance = config.base_instructions_provenance.clone();
|
||||
|
||||
apply_role_to_config(&mut config, Some("custom"))
|
||||
.await
|
||||
@@ -197,6 +204,66 @@ async fn apply_role_preserves_unspecified_keys() {
|
||||
Some(PathBuf::from("/tmp/codex-execve-wrapper"))
|
||||
);
|
||||
assert!(config.psp);
|
||||
assert_eq!(config.base_instructions, base_instructions);
|
||||
assert_eq!(config.base_instructions_provenance, provenance);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn apply_role_regenerates_model_instructions_when_personality_changes() {
|
||||
for (role_contents, provenance) in [
|
||||
(
|
||||
"personality = \"none\"",
|
||||
BaseInstructionsProvenance::Model {
|
||||
model: "parent-model".to_string(),
|
||||
},
|
||||
),
|
||||
(
|
||||
"[features]\npersonality = false",
|
||||
BaseInstructionsProvenance::Model {
|
||||
model: "parent-model".to_string(),
|
||||
},
|
||||
),
|
||||
("personality = \"none\"", BaseInstructionsProvenance::Custom),
|
||||
] {
|
||||
let (home, mut config) = test_config_with_cli_overrides(vec![
|
||||
(
|
||||
"personality".to_string(),
|
||||
TomlValue::String("friendly".to_string()),
|
||||
),
|
||||
("features.personality".to_string(), TomlValue::Boolean(true)),
|
||||
])
|
||||
.await;
|
||||
let role_path = write_role_config(&home, "personality-role.toml", role_contents).await;
|
||||
config.agent_roles.insert(
|
||||
"custom".to_string(),
|
||||
AgentRoleConfig {
|
||||
description: None,
|
||||
config_file: Some(role_path),
|
||||
nickname_candidates: None,
|
||||
},
|
||||
);
|
||||
config.base_instructions = Some("inherited instructions".to_string());
|
||||
config.base_instructions_provenance = Some(provenance.clone());
|
||||
|
||||
apply_role_to_config(&mut config, Some("custom"))
|
||||
.await
|
||||
.expect("custom role should apply");
|
||||
|
||||
let expected = match provenance {
|
||||
BaseInstructionsProvenance::Model { .. } => (None, None),
|
||||
BaseInstructionsProvenance::Custom => (
|
||||
Some("inherited instructions".to_string()),
|
||||
Some(BaseInstructionsProvenance::Custom),
|
||||
),
|
||||
};
|
||||
assert_eq!(
|
||||
(
|
||||
config.base_instructions,
|
||||
config.base_instructions_provenance
|
||||
),
|
||||
expected
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user