mirror of
https://github.com/openai/codex.git
synced 2026-11-09 20:50:33 +00:00
Use the originating model when recording conversation history (#44243)
## Why History recording used the model captured at turn start, so switching models within a turn could apply stale image preparation and tool-output truncation rules. ## What changed Pass explicit model metadata through conversation recording. Record model responses and tool results using their originating step's settings, and capture the current model for pending input recorded during startup interruption or task completion. ## Testing Add regression coverage for tool results across a model switch, explicit model selection for plain and annotated history, and image input retained during interruption and completion. Extend model-switching tests to verify that prepared media and item identity survive switching back to a multimodal model in live, resumed, and forked threads. GitOrigin-RevId: 5bc750c30c334acb9b802cb80fdea01daffa84a1
This commit is contained in:
@@ -5,6 +5,7 @@ use codex_features::Feature;
|
||||
use codex_history::CodexHarnessMetadata;
|
||||
use codex_history::ResponseItemEnvelope;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::ModelInfo;
|
||||
|
||||
impl Session {
|
||||
/// Returns the input if there is no active turn to inject into.
|
||||
@@ -92,7 +93,7 @@ impl Session {
|
||||
return;
|
||||
}
|
||||
drop(active);
|
||||
self.record_annotated_conversation_items(turn_context, items)
|
||||
self.record_annotated_conversation_items(turn_context, turn_context.model_info(), items)
|
||||
.await;
|
||||
}
|
||||
|
||||
@@ -110,6 +111,7 @@ impl Session {
|
||||
pub(crate) async fn record_annotated_conversation_items(
|
||||
&self,
|
||||
turn_context: &TurnContext,
|
||||
model_info: &ModelInfo,
|
||||
items: Vec<ResponseItemEnvelope>,
|
||||
) {
|
||||
if items.iter().all(|item| item.metadata.is_none()) {
|
||||
@@ -117,7 +119,8 @@ impl Session {
|
||||
.into_iter()
|
||||
.map(ResponseItemEnvelope::into_item)
|
||||
.collect::<Vec<_>>();
|
||||
self.record_conversation_items(turn_context, &items).await;
|
||||
self.record_conversation_items(turn_context, model_info, &items)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -126,6 +129,7 @@ impl Session {
|
||||
for envelope in items {
|
||||
let (prepared_items, prepared_images) = self.prepare_conversation_items_for_history(
|
||||
turn_context,
|
||||
model_info,
|
||||
std::slice::from_ref(&envelope.item),
|
||||
);
|
||||
image_preparations.extend(prepared_images);
|
||||
@@ -138,8 +142,13 @@ impl Session {
|
||||
}
|
||||
}));
|
||||
}
|
||||
self.record_prepared_conversation_items(turn_context, annotated_items, image_preparations)
|
||||
.await;
|
||||
self.record_prepared_conversation_items(
|
||||
turn_context,
|
||||
model_info,
|
||||
annotated_items,
|
||||
image_preparations,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Injects items into active work, or records them without starting a turn.
|
||||
@@ -159,7 +168,8 @@ impl Session {
|
||||
default_turn_context.as_ref()
|
||||
}
|
||||
};
|
||||
self.record_conversation_items(turn_context, &items).await;
|
||||
self.record_conversation_items(turn_context, turn_context.model_info(), &items)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user