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:
jif authored and copyberry committed 2026-08-07 14:08:13 +00:00
1 parent e58d9ef447
commit 964a227d8c
29 files changed
+324 -35

No files matched your search

+67
View File
@@ -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]