mirror of
https://github.com/openai/codex.git
synced 2026-06-01 19:02:59 +00:00
Revert "Revert "Update models.json"" (#11256)
Reverts openai/codex#11255
This commit is contained in:
@@ -5350,8 +5350,9 @@ mod tests {
|
||||
let (session, turn_context) = make_session_and_context().await;
|
||||
let (rollout_items, expected) = sample_rollout(&session, &turn_context).await;
|
||||
|
||||
let reconstruction_turn = session.new_default_turn().await;
|
||||
let reconstructed = session
|
||||
.reconstruct_history_from_rollout(&turn_context, &rollout_items)
|
||||
.reconstruct_history_from_rollout(reconstruction_turn.as_ref(), &rollout_items)
|
||||
.await;
|
||||
|
||||
assert_eq!(expected, reconstructed);
|
||||
@@ -5562,7 +5563,12 @@ mod tests {
|
||||
.record_initial_history(InitialHistory::Forked(rollout_items))
|
||||
.await;
|
||||
|
||||
expected.extend(session.build_initial_context(&turn_context).await);
|
||||
let reconstruction_turn = session.new_default_turn().await;
|
||||
expected.extend(
|
||||
session
|
||||
.build_initial_context(reconstruction_turn.as_ref())
|
||||
.await,
|
||||
);
|
||||
let history = session.state.lock().await.clone_history();
|
||||
assert_eq!(expected, history.raw_items());
|
||||
}
|
||||
@@ -6089,6 +6095,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
// todo: use online model info
|
||||
pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
let (tx_event, _rx_event) = async_channel::unbounded();
|
||||
let codex_home = tempfile::tempdir().expect("create temp dir");
|
||||
@@ -6776,16 +6783,50 @@ mod tests {
|
||||
|
||||
async fn sample_rollout(
|
||||
session: &Session,
|
||||
turn_context: &TurnContext,
|
||||
_turn_context: &TurnContext,
|
||||
) -> (Vec<RolloutItem>, Vec<ResponseItem>) {
|
||||
let mut rollout_items = Vec::new();
|
||||
let mut live_history = ContextManager::new();
|
||||
|
||||
let initial_context = session.build_initial_context(turn_context).await;
|
||||
// Use the same turn_context source as record_initial_history so model_info (and thus
|
||||
// personality_spec) matches reconstruction.
|
||||
let reconstruction_turn = session.new_default_turn().await;
|
||||
let mut initial_context = session
|
||||
.build_initial_context(reconstruction_turn.as_ref())
|
||||
.await;
|
||||
// Ensure personality_spec is present when Personality is enabled, so expected matches
|
||||
// what reconstruction produces (build_initial_context may omit it when baked into model).
|
||||
if !initial_context.iter().any(|m| {
|
||||
matches!(m, ResponseItem::Message { role, content, .. }
|
||||
if role == "developer"
|
||||
&& content.iter().any(|c| {
|
||||
matches!(c, ContentItem::InputText { text } if text.contains("<personality_spec>"))
|
||||
}))
|
||||
})
|
||||
&& let Some(p) = reconstruction_turn.personality
|
||||
&& session.features.enabled(Feature::Personality)
|
||||
&& let Some(personality_message) = reconstruction_turn
|
||||
.model_info
|
||||
.model_messages
|
||||
.as_ref()
|
||||
.and_then(|m| m.get_personality_message(Some(p)).filter(|s| !s.is_empty()))
|
||||
{
|
||||
let msg =
|
||||
DeveloperInstructions::personality_spec_message(personality_message).into();
|
||||
let insert_at = initial_context
|
||||
.iter()
|
||||
.position(|m| matches!(m, ResponseItem::Message { role, .. } if role == "developer"))
|
||||
.map(|i| i + 1)
|
||||
.unwrap_or(0);
|
||||
initial_context.insert(insert_at, msg);
|
||||
}
|
||||
for item in &initial_context {
|
||||
rollout_items.push(RolloutItem::ResponseItem(item.clone()));
|
||||
}
|
||||
live_history.record_items(initial_context.iter(), turn_context.truncation_policy);
|
||||
live_history.record_items(
|
||||
initial_context.iter(),
|
||||
reconstruction_turn.truncation_policy,
|
||||
);
|
||||
|
||||
let user1 = ResponseItem::Message {
|
||||
id: None,
|
||||
@@ -6796,7 +6837,10 @@ mod tests {
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
};
|
||||
live_history.record_items(std::iter::once(&user1), turn_context.truncation_policy);
|
||||
live_history.record_items(
|
||||
std::iter::once(&user1),
|
||||
reconstruction_turn.truncation_policy,
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(user1.clone()));
|
||||
|
||||
let assistant1 = ResponseItem::Message {
|
||||
@@ -6808,17 +6852,17 @@ mod tests {
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
};
|
||||
live_history.record_items(std::iter::once(&assistant1), turn_context.truncation_policy);
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant1),
|
||||
reconstruction_turn.truncation_policy,
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(assistant1.clone()));
|
||||
|
||||
let summary1 = "summary one";
|
||||
let snapshot1 = live_history.clone().for_prompt();
|
||||
let user_messages1 = collect_user_messages(&snapshot1);
|
||||
let rebuilt1 = compact::build_compacted_history(
|
||||
session.build_initial_context(turn_context).await,
|
||||
&user_messages1,
|
||||
summary1,
|
||||
);
|
||||
let rebuilt1 =
|
||||
compact::build_compacted_history(initial_context.clone(), &user_messages1, summary1);
|
||||
live_history.replace(rebuilt1);
|
||||
rollout_items.push(RolloutItem::Compacted(CompactedItem {
|
||||
message: summary1.to_string(),
|
||||
@@ -6834,7 +6878,10 @@ mod tests {
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
};
|
||||
live_history.record_items(std::iter::once(&user2), turn_context.truncation_policy);
|
||||
live_history.record_items(
|
||||
std::iter::once(&user2),
|
||||
reconstruction_turn.truncation_policy,
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(user2.clone()));
|
||||
|
||||
let assistant2 = ResponseItem::Message {
|
||||
@@ -6846,17 +6893,17 @@ mod tests {
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
};
|
||||
live_history.record_items(std::iter::once(&assistant2), turn_context.truncation_policy);
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant2),
|
||||
reconstruction_turn.truncation_policy,
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(assistant2.clone()));
|
||||
|
||||
let summary2 = "summary two";
|
||||
let snapshot2 = live_history.clone().for_prompt();
|
||||
let user_messages2 = collect_user_messages(&snapshot2);
|
||||
let rebuilt2 = compact::build_compacted_history(
|
||||
session.build_initial_context(turn_context).await,
|
||||
&user_messages2,
|
||||
summary2,
|
||||
);
|
||||
let rebuilt2 =
|
||||
compact::build_compacted_history(initial_context.clone(), &user_messages2, summary2);
|
||||
live_history.replace(rebuilt2);
|
||||
rollout_items.push(RolloutItem::Compacted(CompactedItem {
|
||||
message: summary2.to_string(),
|
||||
@@ -6872,7 +6919,10 @@ mod tests {
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
};
|
||||
live_history.record_items(std::iter::once(&user3), turn_context.truncation_policy);
|
||||
live_history.record_items(
|
||||
std::iter::once(&user3),
|
||||
reconstruction_turn.truncation_policy,
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(user3));
|
||||
|
||||
let assistant3 = ResponseItem::Message {
|
||||
@@ -6884,7 +6934,10 @@ mod tests {
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
};
|
||||
live_history.record_items(std::iter::once(&assistant3), turn_context.truncation_policy);
|
||||
live_history.record_items(
|
||||
std::iter::once(&assistant3),
|
||||
reconstruction_turn.truncation_policy,
|
||||
);
|
||||
rollout_items.push(RolloutItem::ResponseItem(assistant3));
|
||||
|
||||
(rollout_items, live_history.for_prompt())
|
||||
|
||||
Reference in New Issue
Block a user