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
@@ -168,6 +168,7 @@ impl ContextManager {
let personality = turn_context.personality.or(turn_context.config.personality);
let base_instructions = BaseInstructions {
text: model_info.get_model_instructions(personality),
provenance: None,
};
self.estimate_token_count_with_base_instructions(&base_instructions)
}
@@ -828,9 +828,11 @@ fn estimate_token_count_with_base_instructions_uses_provided_text() {
let history = create_history_with_items(vec![assistant_msg("hello from history")]);
let short_base = BaseInstructions {
text: "short".to_string(),
provenance: None,
};
let long_base = BaseInstructions {
text: "x".repeat(1_000),
provenance: None,
};
let short_estimate = history