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
2026-08-07 14:08:13 +00:00
committed by copyberry
parent e58d9ef447
commit 964a227d8c
29 changed files with 324 additions and 35 deletions
+21 -2
View File
@@ -120,6 +120,7 @@ use codex_protocol::ThreadId;
use codex_protocol::approvals::GuardianAssessmentEvent;
use codex_protocol::config_types::SERVICE_TIER_DEFAULT_REQUEST_VALUE;
use codex_protocol::models::ActivePermissionProfile;
use codex_protocol::models::BaseInstructionsProvenance;
use codex_protocol::models::PermissionProfile;
use codex_protocol::models::ResponseItem;
use codex_protocol::openai_models::ModelAvailabilityNux;
@@ -1808,7 +1809,12 @@ fn thread_fork_params_from_config(
sandbox,
permissions,
config: config_request_overrides_from_config(&config),
base_instructions: config.base_instructions.clone(),
base_instructions: config.base_instructions.clone().filter(|_| {
!matches!(
config.base_instructions_provenance,
Some(BaseInstructionsProvenance::Model { .. })
)
}),
developer_instructions: with_terminal_visualization_instructions(
&config,
config.developer_instructions.clone(),
@@ -2918,11 +2924,12 @@ mod tests {
let temp_dir = tempfile::tempdir().expect("tempdir");
let mut config = build_config(&temp_dir).await;
config.base_instructions = Some("Base override.".to_string());
config.base_instructions_provenance = Some(BaseInstructionsProvenance::Custom);
config.developer_instructions = Some("Developer override.".to_string());
let thread_id = ThreadId::new();
let params = thread_fork_params_from_config(
config,
config.clone(),
thread_id,
ThreadParamsMode::Embedded,
/*remote_cwd_override*/ None,
@@ -2933,6 +2940,18 @@ mod tests {
params.developer_instructions.as_deref(),
Some("Developer override.")
);
config.base_instructions_provenance = Some(BaseInstructionsProvenance::Model {
model: "gpt-5.2".to_string(),
});
let params = thread_fork_params_from_config(
config,
thread_id,
ThreadParamsMode::Remote,
/*remote_cwd_override*/ None,
);
assert_eq!(params.base_instructions, None);
}
#[tokio::test]