mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Route response item IDs through a shared generator (#59312)
## What changed Introduce `ItemIdGenerator` and pass the runtime-owned generator through sessions, model clients, history, hooks, tool outputs, and memory requests. Keep UUIDv7 generation as the default and replace direct calls to `ResponseItemId::new` with the shared callable. Preserve existing item IDs and backfill missing or empty IDs through the same generator, including forked history before reconstruction and persistence. ## Testing Extend coverage for UUIDv7 IDs on user messages, agent messages, and additional tools, and assert that forked model context matches the backfilled items persisted to history. GitOrigin-RevId: 0dd9ccf0f46f0f1005a6acfc740133b03ce82259
This commit is contained in:
committed by
copyberry
parent
f2b94ef8b5
commit
d84c872464
@@ -6,6 +6,7 @@ use codex_history::InitialHistory;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::ThreadHistoryMode;
|
||||
use codex_protocol::protocol::TokenUsage;
|
||||
use codex_protocol_test_support::uuid_v7_item_id_generator_for_test;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use test_case::test_case;
|
||||
@@ -37,6 +38,7 @@ async fn guardian_checkpoint_preserves_live_context_without_storage(
|
||||
state.history = ContextManager::for_session(
|
||||
/*root_capabilities_restricted*/ false,
|
||||
&crate::config::ManagedFeatures::from(codex_features::Features::with_defaults()),
|
||||
uuid_v7_item_id_generator_for_test(),
|
||||
);
|
||||
state
|
||||
.history
|
||||
@@ -108,6 +110,7 @@ async fn guardian_checkpoint_preserves_live_context_without_storage(
|
||||
fork.state.lock().await.history = ContextManager::for_session(
|
||||
/*root_capabilities_restricted*/ false,
|
||||
&crate::config::ManagedFeatures::from(codex_features::Features::with_defaults()),
|
||||
uuid_v7_item_id_generator_for_test(),
|
||||
);
|
||||
fork.record_initial_history(InitialHistory::Forked(items))
|
||||
.await;
|
||||
|
||||
@@ -184,11 +184,9 @@ impl Session {
|
||||
image_preparations.extend(prepared_images);
|
||||
|
||||
let mut metadata = envelope.metadata;
|
||||
annotated_items.extend(prepared_items.into_owned().into_iter().map(|item| {
|
||||
ResponseItemEnvelope {
|
||||
item,
|
||||
metadata: metadata.take(),
|
||||
}
|
||||
annotated_items.extend(prepared_items.into_iter().map(|item| ResponseItemEnvelope {
|
||||
item,
|
||||
metadata: metadata.take(),
|
||||
}));
|
||||
}
|
||||
(annotated_items, image_preparations)
|
||||
|
||||
@@ -3,7 +3,6 @@ pub(crate) mod startup;
|
||||
use crate::PromptCacheKey;
|
||||
use crate::WithTurnExtensionData;
|
||||
use crate::runtime_auth::RuntimeAuthSlot;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Debug;
|
||||
@@ -583,6 +582,17 @@ pub(crate) const SUBMISSION_CHANNEL_CAPACITY: usize = 512;
|
||||
const CYBER_VERIFY_URL: &str = "https://chatgpt.com/cyber";
|
||||
const CYBER_SAFETY_URL: &str = "https://developers.openai.com/codex/concepts/cyber-safety";
|
||||
|
||||
pub(crate) fn assign_missing_item_id(
|
||||
item: &mut ResponseItem,
|
||||
item_id_generator: &codex_protocol::ItemIdGenerator,
|
||||
) {
|
||||
if item.id().is_none_or(|id| id.is_empty())
|
||||
&& let Some(prefix) = item.id_prefix()
|
||||
{
|
||||
item.set_id(Some(item_id_generator(prefix)));
|
||||
}
|
||||
}
|
||||
|
||||
impl Session {
|
||||
/// Spawn and initialize a new session.
|
||||
/// Hide the concrete startup future from callers while keeping initialization lazy.
|
||||
@@ -1821,7 +1831,11 @@ impl Session {
|
||||
}
|
||||
InitialHistory::Forked(mut rollout_items) => {
|
||||
let turn_context = self.new_default_turn().await;
|
||||
Self::assign_missing_rollout_response_item_ids(&mut rollout_items);
|
||||
for record in &mut rollout_items {
|
||||
if let RolloutItem::ResponseItem(envelope) = record {
|
||||
self.assign_missing_response_item_id(&mut envelope.item);
|
||||
}
|
||||
}
|
||||
self.apply_rollout_reconstruction(&turn_context, &rollout_items)
|
||||
.await;
|
||||
|
||||
@@ -3822,12 +3836,12 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Prepares media using the originating model and preserves existing item identity.
|
||||
pub(crate) async fn prepare_conversation_items_for_history<'a>(
|
||||
pub(crate) async fn prepare_conversation_items_for_history(
|
||||
&self,
|
||||
turn_context: &TurnContext,
|
||||
model_info: &ModelInfo,
|
||||
items: &'a [ResponseItem],
|
||||
) -> (Cow<'a, [ResponseItem]>, Vec<ImagePreparationMetadata>) {
|
||||
items: &[ResponseItem],
|
||||
) -> (Vec<ResponseItem>, Vec<ImagePreparationMetadata>) {
|
||||
let mut items = items.to_vec();
|
||||
let image_preparation_mode =
|
||||
if unified_image_budget_enabled(&turn_context.config.features, model_info) {
|
||||
@@ -3858,44 +3872,13 @@ impl Session {
|
||||
// Most response items get their passthrough turn ID at the durable history boundary.
|
||||
for item in &mut items {
|
||||
Self::stamp_response_item_for_history(item, &turn_context.sub_id);
|
||||
self.assign_missing_response_item_id(item);
|
||||
}
|
||||
let items = Cow::Owned(items);
|
||||
(
|
||||
Self::assign_missing_response_item_ids(items),
|
||||
image_preparations,
|
||||
)
|
||||
(items, image_preparations)
|
||||
}
|
||||
|
||||
fn assign_missing_response_item_ids(items: Cow<'_, [ResponseItem]>) -> Cow<'_, [ResponseItem]> {
|
||||
if items
|
||||
.iter()
|
||||
.all(|item| item.id().is_some_and(|id| !id.is_empty()))
|
||||
{
|
||||
return items;
|
||||
}
|
||||
let mut items = items;
|
||||
for item in items.to_mut() {
|
||||
Self::assign_missing_response_item_id(item);
|
||||
}
|
||||
items
|
||||
}
|
||||
|
||||
pub(crate) fn assign_missing_response_item_id(item: &mut ResponseItem) {
|
||||
if item.id().is_some_and(|id| !id.is_empty()) {
|
||||
return;
|
||||
}
|
||||
let Some(prefix) = item.id_prefix() else {
|
||||
return;
|
||||
};
|
||||
item.set_id(Some(ResponseItemId::new(prefix)));
|
||||
}
|
||||
|
||||
fn assign_missing_rollout_response_item_ids(items: &mut [RolloutItem]) {
|
||||
for item in items {
|
||||
if let RolloutItem::ResponseItem(response_item) = item {
|
||||
Self::assign_missing_response_item_id(&mut response_item.item);
|
||||
}
|
||||
}
|
||||
pub(crate) fn assign_missing_response_item_id(&self, item: &mut ResponseItem) {
|
||||
assign_missing_item_id(item, &self.item_id_generator);
|
||||
}
|
||||
|
||||
pub(crate) fn response_item_from_user_input(&self, input: Vec<UserInput>) -> ResponseItem {
|
||||
@@ -3955,11 +3938,7 @@ impl Session {
|
||||
let (items, image_preparations) = self
|
||||
.prepare_conversation_items_for_history(turn_context, model_info, items)
|
||||
.await;
|
||||
let items = items
|
||||
.into_owned()
|
||||
.into_iter()
|
||||
.map(ResponseItemEnvelope::new)
|
||||
.collect();
|
||||
let items = items.into_iter().map(ResponseItemEnvelope::new).collect();
|
||||
self.record_prepared_conversation_items(
|
||||
turn_context,
|
||||
model_info,
|
||||
@@ -4541,7 +4520,6 @@ impl Session {
|
||||
std::slice::from_ref(&response_item),
|
||||
)
|
||||
.await;
|
||||
let items = items.as_ref();
|
||||
let mut response_item = ResponseItemEnvelope::new(items[0].clone());
|
||||
// A send confirmed after the pending snapshot must not reach the rollout
|
||||
// before this boundary; older readers assign deliveries by physical order.
|
||||
@@ -4569,7 +4547,7 @@ impl Session {
|
||||
}
|
||||
{
|
||||
let mut state = self.state.lock().await;
|
||||
state.current_time_reminder.note_recorded_items(items);
|
||||
state.current_time_reminder.note_recorded_items(&items);
|
||||
state.history.record_annotated_items(
|
||||
std::slice::from_mut(&mut response_item),
|
||||
model_info.truncation_policy.into(),
|
||||
@@ -4586,7 +4564,7 @@ impl Session {
|
||||
])
|
||||
.await;
|
||||
drop(boundary);
|
||||
self.send_raw_response_items(turn_context, items).await;
|
||||
self.send_raw_response_items(turn_context, &items).await;
|
||||
}
|
||||
|
||||
async fn maybe_warn_on_server_model_mismatch(
|
||||
@@ -4771,7 +4749,7 @@ impl Session {
|
||||
}
|
||||
};
|
||||
for envelope in &mut items {
|
||||
Self::assign_missing_response_item_id(&mut envelope.item);
|
||||
self.assign_missing_response_item_id(&mut envelope.item);
|
||||
}
|
||||
// Goal edits are published outside the running task. Keep edits accepted after
|
||||
// the compaction input snapshot, in their original order, after its replacement.
|
||||
|
||||
@@ -93,7 +93,7 @@ impl Session {
|
||||
let _guard = thread_settings::acquire_persistence_lock(self).await;
|
||||
let mut item = ContextualUserFragment::into(update);
|
||||
Self::stamp_response_item_for_history(&mut item, &context.sub_id);
|
||||
Self::assign_missing_response_item_id(&mut item);
|
||||
self.assign_missing_response_item_id(&mut item);
|
||||
let mut item = ResponseItemEnvelope {
|
||||
item,
|
||||
metadata: Some(CodexHarnessMetadata {
|
||||
|
||||
@@ -199,6 +199,7 @@ impl Session {
|
||||
ContextManager::for_session(
|
||||
turn_context.root_capabilities_restricted,
|
||||
&turn_context.config.features,
|
||||
std::sync::Arc::clone(&self.item_id_generator),
|
||||
),
|
||||
turn_context.model_info().truncation_policy.into(),
|
||||
)
|
||||
|
||||
@@ -21,6 +21,7 @@ use codex_protocol::protocol::ThreadRolledBackEvent;
|
||||
use codex_protocol::protocol::WorldStateItem;
|
||||
use codex_protocol::security_risk::SecurityRiskScore;
|
||||
use codex_protocol::turn_input::CyberAccessProgram;
|
||||
use codex_protocol_test_support::uuid_v7_item_id_generator_for_test;
|
||||
use codex_rollout::ModelContextScan;
|
||||
use codex_rollout::ModelContextScanProgress;
|
||||
use core_test_support::responses::strip_metadata_from_items;
|
||||
@@ -128,6 +129,7 @@ async fn sender_context_follows_its_delivery_through_checkpoint_and_rollback() {
|
||||
let mut live = ContextManager::for_session(
|
||||
/*root_capabilities_restricted*/ false,
|
||||
&crate::config::ManagedFeatures::from(codex_features::Features::with_defaults()),
|
||||
uuid_v7_item_id_generator_for_test(),
|
||||
);
|
||||
let mut items = Vec::new();
|
||||
let mut snapshots = Vec::new();
|
||||
@@ -2024,8 +2026,9 @@ async fn reconstruct_history_legacy_compaction_without_replacement_history_does_
|
||||
complete: false,
|
||||
},
|
||||
codex_history::RetainedInputSource::Local(None),
|
||||
&uuid_v7_item_id_generator_for_test(),
|
||||
);
|
||||
retained.record(&answer);
|
||||
retained.record(&answer, &uuid_v7_item_id_generator_for_test());
|
||||
let rollout_items = vec![
|
||||
RolloutItem::ResponseItem(user_message("before compact").into()),
|
||||
RolloutItem::ResponseItem(assistant_message("assistant reply").into()),
|
||||
|
||||
@@ -33,6 +33,7 @@ use codex_http_client::RouteAwareClientPool;
|
||||
use codex_login::auth::AgentIdentityAuthPolicy;
|
||||
use codex_model_provider::SharedModelProvider;
|
||||
use codex_prompts::render_model_instructions;
|
||||
use codex_protocol::ItemIdGenerator;
|
||||
use codex_protocol::SessionId;
|
||||
use codex_protocol::capabilities::SelectedCapabilityRoot;
|
||||
use codex_protocol::config_types::ShellEnvironmentPolicy;
|
||||
@@ -63,6 +64,7 @@ type McpToolApprovalMetadataMap =
|
||||
/// A session has at most 1 running task at a time, and can be interrupted by user input.
|
||||
pub(crate) struct Session {
|
||||
pub(crate) thread_id: ThreadId,
|
||||
pub(crate) item_id_generator: ItemIdGenerator,
|
||||
pub(crate) agent_runtime: AgentRuntimeServices,
|
||||
pub(crate) installation_id: String,
|
||||
pub(super) tx_event: Sender<Event>,
|
||||
@@ -708,6 +710,10 @@ async fn warm_plugins_and_skills_for_session_init(
|
||||
}
|
||||
|
||||
impl Session {
|
||||
pub(crate) fn new_item_id_generator() -> ItemIdGenerator {
|
||||
Arc::new(|prefix| ResponseItemId::with_suffix(prefix, uuid::Uuid::now_v7()))
|
||||
}
|
||||
|
||||
pub(super) async fn effective_thread_config_snapshot(
|
||||
&self,
|
||||
configuration: &SessionConfiguration,
|
||||
@@ -964,8 +970,13 @@ impl Session {
|
||||
session_configuration.thread_source.as_ref(),
|
||||
Some(ThreadSource::Subagent | ThreadSource::GuardianReview)
|
||||
);
|
||||
let item_id_generator = Arc::clone(&agent_control.runtime().item_id_generator);
|
||||
if let InitialHistory::Forked(items) = &mut initial_history {
|
||||
Self::assign_missing_rollout_response_item_ids(items);
|
||||
for record in items {
|
||||
if let RolloutItem::ResponseItem(item) = record {
|
||||
assign_missing_item_id(&mut item.item, &item_id_generator);
|
||||
}
|
||||
}
|
||||
}
|
||||
let multi_agent_version = multi_agent_version.map(OnceLock::from).unwrap_or_default();
|
||||
let initial_multi_agent_version = multi_agent_version.get().copied();
|
||||
@@ -1624,6 +1635,7 @@ impl Session {
|
||||
ContextManager::for_session(
|
||||
session_configuration.root_capabilities_restricted,
|
||||
&config.features,
|
||||
Arc::clone(&item_id_generator),
|
||||
),
|
||||
);
|
||||
if matches!(initial_history, InitialHistory::Resumed(_)) {
|
||||
@@ -1832,6 +1844,7 @@ impl Session {
|
||||
AgentIdentityAuthPolicy::JwtOnly
|
||||
},
|
||||
thread_id,
|
||||
Arc::clone(&item_id_generator),
|
||||
session_configuration.session_source.clone(),
|
||||
session_configuration.originator.clone(),
|
||||
config.model_verbosity,
|
||||
@@ -1953,6 +1966,7 @@ impl Session {
|
||||
let (mcp_prewarm_tx, mcp_prewarm_rx) = async_channel::bounded(1);
|
||||
let sess = Arc::new(Session {
|
||||
thread_id,
|
||||
item_id_generator,
|
||||
agent_runtime,
|
||||
installation_id,
|
||||
tx_event: tx_event.clone(),
|
||||
|
||||
@@ -357,11 +357,13 @@ fn user_message(text: &str) -> ResponseItem {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assign_missing_response_item_ids_assigns_agent_message_ids() {
|
||||
let items = Cow::Owned(vec![
|
||||
#[tokio::test]
|
||||
async fn default_turn_context_assigns_missing_response_item_ids() {
|
||||
let (session, turn_context) = make_session_and_context().await;
|
||||
let items = [
|
||||
user_message("hello"),
|
||||
ResponseItem::AgentMessage {
|
||||
id: None,
|
||||
id: Some(ResponseItemId::from_server(String::new())),
|
||||
author: "worker".to_string(),
|
||||
recipient: "root".to_string(),
|
||||
content: vec![AgentMessageInputContent::InputText {
|
||||
@@ -369,46 +371,21 @@ fn assign_missing_response_item_ids_assigns_agent_message_ids() {
|
||||
}],
|
||||
internal_chat_message_metadata_passthrough: None,
|
||||
},
|
||||
user_message("hello"),
|
||||
]);
|
||||
|
||||
let items = Session::assign_missing_response_item_ids(items);
|
||||
|
||||
assert!(items[0].id().is_some_and(|id| id.starts_with("amsg_")));
|
||||
assert!(items[1].id().is_some_and(|id| id.starts_with("msg_")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assign_missing_response_item_ids_assigns_additional_tools_ids() {
|
||||
let items = Cow::Owned(vec![ResponseItem::AdditionalTools {
|
||||
id: None,
|
||||
role: "developer".to_string(),
|
||||
tools: Arc::from([]),
|
||||
}]);
|
||||
|
||||
let items = Session::assign_missing_response_item_ids(items);
|
||||
|
||||
assert!(items[0].id().is_some_and(|id| id.starts_with("at_")));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn default_turn_context_assigns_missing_response_item_ids() {
|
||||
let (session, turn_context) = make_session_and_context().await;
|
||||
let response_item = user_message("hello");
|
||||
|
||||
ResponseItem::AdditionalTools {
|
||||
id: None,
|
||||
role: "developer".to_string(),
|
||||
tools: Arc::from([]),
|
||||
},
|
||||
];
|
||||
let (items, _) = session
|
||||
.prepare_conversation_items_for_history(
|
||||
&turn_context,
|
||||
turn_context.model_info(),
|
||||
std::slice::from_ref(&response_item),
|
||||
)
|
||||
.prepare_conversation_items_for_history(&turn_context, turn_context.model_info(), &items)
|
||||
.await;
|
||||
|
||||
assert!(
|
||||
items[0]
|
||||
.id()
|
||||
.is_some_and(|item_id| item_id.starts_with("msg_"))
|
||||
);
|
||||
assert_eq!(items.len(), 3);
|
||||
for (item, prefix) in items.iter().zip(["msg_", "amsg_", "at_"]) {
|
||||
let suffix = item.id().unwrap().strip_prefix(prefix).unwrap();
|
||||
assert_eq!(Uuid::parse_str(suffix).unwrap().get_version_num(), 7);
|
||||
}
|
||||
}
|
||||
|
||||
fn assistant_message(text: &str) -> ResponseItem {
|
||||
@@ -915,6 +892,7 @@ fn test_model_client_session() -> crate::client::ModelClientSession {
|
||||
),
|
||||
AgentIdentityAuthPolicy::JwtOnly,
|
||||
thread_id,
|
||||
codex_protocol_test_support::uuid_v7_item_id_generator_for_test(),
|
||||
codex_protocol::protocol::SessionSource::Exec,
|
||||
"test_originator".to_string(),
|
||||
/*model_verbosity*/ None,
|
||||
@@ -2627,12 +2605,14 @@ async fn record_conversation_items_stamps_missing_turn_id_and_preserves_existing
|
||||
#[tokio::test]
|
||||
async fn record_response_item_and_emit_turn_item_emits_hook_prompt_lifecycle() {
|
||||
let (session, turn_context, rx) = make_session_and_context_with_rx().await;
|
||||
let response_item = build_hook_prompt_message(&[HookPromptFragment::from_single_hook(
|
||||
"Retry with tests.",
|
||||
"hook-run-1",
|
||||
)])
|
||||
let response_item = build_hook_prompt_message(
|
||||
&[HookPromptFragment::from_single_hook(
|
||||
"Retry with tests.",
|
||||
"hook-run-1",
|
||||
)],
|
||||
&session.item_id_generator,
|
||||
)
|
||||
.expect("hook prompt message");
|
||||
let response_item_id = response_item.id().expect("hook prompt id").to_string();
|
||||
|
||||
session
|
||||
.record_response_item_and_emit_turn_item(
|
||||
@@ -2643,7 +2623,11 @@ async fn record_response_item_and_emit_turn_item_emits_hook_prompt_lifecycle() {
|
||||
.await;
|
||||
|
||||
let raw_response = rx.recv().await.expect("raw response item event");
|
||||
assert!(matches!(raw_response.msg, EventMsg::RawResponseItem(_)));
|
||||
let EventMsg::RawResponseItem(raw) = raw_response.msg else {
|
||||
panic!("expected raw hook prompt");
|
||||
};
|
||||
let response_item_id = raw.item.id().expect("hook prompt id").to_string();
|
||||
assert!(response_item_id.starts_with("msg_"));
|
||||
|
||||
let started = rx.recv().await.expect("started hook prompt event");
|
||||
assert!(matches!(
|
||||
@@ -6937,6 +6921,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
config.model_provider.clone(),
|
||||
);
|
||||
let agent_control = LocalAgentControl::default();
|
||||
let item_id_generator = Arc::clone(&agent_control.runtime.item_id_generator);
|
||||
let exec_policy = Arc::new(ExecPolicyManager::default());
|
||||
let (agent_status_tx, _agent_status_rx) = watch::channel(AgentStatus::PendingInit);
|
||||
let model = get_model_offline_for_tests(config.model.as_deref());
|
||||
@@ -7010,6 +6995,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
state.history = ContextManager::for_session(
|
||||
session_configuration.root_capabilities_restricted,
|
||||
&config.features,
|
||||
Arc::clone(&item_id_generator),
|
||||
);
|
||||
let (environment_manager, resolved_environments) =
|
||||
resolved_environments_for_configuration(&session_configuration, &default_environments)
|
||||
@@ -7122,6 +7108,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
),
|
||||
AgentIdentityAuthPolicy::JwtOnly,
|
||||
thread_id,
|
||||
Arc::clone(&item_id_generator),
|
||||
session_configuration.session_source.clone(),
|
||||
session_configuration.originator.clone(),
|
||||
config.model_verbosity,
|
||||
@@ -7153,6 +7140,7 @@ pub(crate) async fn make_session_and_context() -> (Session, TurnContext) {
|
||||
|
||||
let session = Session {
|
||||
thread_id,
|
||||
item_id_generator,
|
||||
agent_runtime: crate::agent::host::AgentRuntimeServices::Controller,
|
||||
installation_id: "11111111-1111-4111-8111-111111111111".to_string(),
|
||||
tx_event,
|
||||
@@ -9276,6 +9264,7 @@ where
|
||||
config.model_provider.clone(),
|
||||
);
|
||||
let agent_control = LocalAgentControl::default();
|
||||
let item_id_generator = Arc::clone(&agent_control.runtime.item_id_generator);
|
||||
let exec_policy = Arc::new(ExecPolicyManager::default());
|
||||
let (agent_status_tx, _agent_status_rx) = watch::channel(AgentStatus::PendingInit);
|
||||
let model = get_model_offline_for_tests(config.model.as_deref());
|
||||
@@ -9349,6 +9338,7 @@ where
|
||||
state.history = ContextManager::for_session(
|
||||
session_configuration.root_capabilities_restricted,
|
||||
&config.features,
|
||||
Arc::clone(&item_id_generator),
|
||||
);
|
||||
let (environment_manager, resolved_turn_environments) =
|
||||
resolved_environments_for_configuration(&session_configuration, &default_environments)
|
||||
@@ -9460,6 +9450,7 @@ where
|
||||
),
|
||||
AgentIdentityAuthPolicy::JwtOnly,
|
||||
thread_id,
|
||||
Arc::clone(&item_id_generator),
|
||||
session_configuration.session_source.clone(),
|
||||
session_configuration.originator.clone(),
|
||||
config.model_verbosity,
|
||||
@@ -9491,6 +9482,7 @@ where
|
||||
|
||||
let session = Arc::new(Session {
|
||||
thread_id,
|
||||
item_id_generator,
|
||||
agent_runtime: crate::agent::host::AgentRuntimeServices::Controller,
|
||||
installation_id: "11111111-1111-4111-8111-111111111111".to_string(),
|
||||
tx_event,
|
||||
@@ -13530,7 +13522,7 @@ async fn sample_rollout(
|
||||
_turn_context: &TurnContext,
|
||||
) -> (Vec<RolloutItem>, Vec<ResponseItem>) {
|
||||
let mut rollout_items = Vec::new();
|
||||
let mut live_history = ContextManager::new();
|
||||
let mut live_history = ContextManager::default();
|
||||
|
||||
// Use the same turn_context source as record_initial_history so model_info matches reconstruction.
|
||||
let reconstruction_turn = session.new_default_turn().await;
|
||||
|
||||
@@ -775,9 +775,10 @@ pub(crate) async fn run_turn(
|
||||
));
|
||||
}
|
||||
if stop_outcome.should_block {
|
||||
if let Some(hook_prompt_message) =
|
||||
build_hook_prompt_message(&stop_outcome.continuation_fragments)
|
||||
{
|
||||
if let Some(hook_prompt_message) = build_hook_prompt_message(
|
||||
&stop_outcome.continuation_fragments,
|
||||
&sess.item_id_generator,
|
||||
) {
|
||||
sess.record_response_item_and_emit_turn_item(
|
||||
&turn_context,
|
||||
&step_context.settings.model_info,
|
||||
@@ -2805,21 +2806,6 @@ async fn drain_in_flight(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn assign_missing_streamed_response_item_id(
|
||||
item: &mut ResponseItem,
|
||||
active_item: Option<&TurnItem>,
|
||||
) {
|
||||
if item.id().is_some_and(|id| !id.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let active_item_id = active_item
|
||||
.map(|item| ResponseItemId::from_server(item.id()))
|
||||
.filter(|item_id| !item_id.is_empty());
|
||||
item.set_id(active_item_id);
|
||||
Session::assign_missing_response_item_id(item);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[instrument(level = "trace",
|
||||
skip_all,
|
||||
@@ -3124,7 +3110,12 @@ async fn try_run_sampling_request(
|
||||
authorization: authorization.clone(),
|
||||
})
|
||||
});
|
||||
assign_missing_streamed_response_item_id(&mut item, active_item.as_ref());
|
||||
if item.id().is_none_or(|id| id.is_empty())
|
||||
&& let Some(active_item) = &active_item
|
||||
{
|
||||
item.set_id(Some(ResponseItemId::from_server(active_item.id())));
|
||||
}
|
||||
sess.assign_missing_response_item_id(&mut item);
|
||||
sess.reserve_assistant_message_order(&turn_context, &item)
|
||||
.await;
|
||||
if analytics_tool_call_ids.len() < MAX_ANALYTICS_TOOL_CALL_IDS_PER_RESPONSE {
|
||||
@@ -3283,7 +3274,7 @@ async fn try_run_sampling_request(
|
||||
}
|
||||
}
|
||||
ResponseEvent::OutputItemAdded(mut item) => {
|
||||
assign_missing_streamed_response_item_id(&mut item, /*active_item*/ None);
|
||||
sess.assign_missing_response_item_id(&mut item);
|
||||
sess.reserve_assistant_message_order(&turn_context, &item)
|
||||
.await;
|
||||
if !*draining_for_mailbox
|
||||
|
||||
@@ -1018,7 +1018,7 @@ async fn capture_sender_user_messages(
|
||||
if !matches!(item, ResponseItem::FunctionCallOutput { call_id: None, .. }) {
|
||||
return None;
|
||||
}
|
||||
Session::assign_missing_response_item_id(item);
|
||||
session.assign_missing_response_item_id(item);
|
||||
session
|
||||
.services
|
||||
.local_agent_runtime
|
||||
|
||||
Reference in New Issue
Block a user