mirror of
https://github.com/openai/codex.git
synced 2026-11-15 22:53:30 +00:00
Establish root turn identity for independent tasks and memory requests (#42900)
## Why Background and empty-input turns could lack a `root_turn_id`, and detached memory requests omitted turn identity entirely. Tasks without a root could also adopt one from coalesced mailbox input. ## What changed - Set `root_turn_id` to the task's turn ID at task start unless an inherited or recovered root is already present. - Stop assigning roots from mailbox input or steering an active turn. - Give detached memory requests a fresh UUID for both `turn_id` and `root_turn_id`, included in turn headers and client metadata while still omitting session and thread identity. ## Testing Extend assertions for background turns, empty input, goal continuations, manual compaction, and detached memory requests. Exercise mailbox coalescing with both independent and inherited roots to verify the task keeps its established root. GitOrigin-RevId: ee0f2f1b43542a9f5884f694c1d94341b476779c
This commit is contained in:
1 parent
c126b0d8ef
commit
d05e6d5f46
14 files changed
+105
-137
No files matched your search
@@ -3274,11 +3274,11 @@ async fn thread_goal_keeps_original_root_until_external_objective_edit() -> Resu
|
|||||||
);
|
);
|
||||||
responses::assert_root_turn(&reopened_request, Some(original_turn.turn.id.as_str()))?;
|
responses::assert_root_turn(&reopened_request, Some(original_turn.turn.id.as_str()))?;
|
||||||
let continuation_request = serde_json::from_slice::<serde_json::Value>(&requests[7])?;
|
let continuation_request = serde_json::from_slice::<serde_json::Value>(&requests[7])?;
|
||||||
assert_ne!(
|
let continuation_turn_id = continuation_request["client_metadata"]["turn_id"]
|
||||||
continuation_request["client_metadata"]["turn_id"].as_str(),
|
.as_str()
|
||||||
Some(edited_turn_id)
|
.expect("independent continuation turn ID");
|
||||||
);
|
assert_ne!(continuation_turn_id, edited_turn_id);
|
||||||
responses::assert_root_turn(&continuation_request, /*expected*/ None)?;
|
responses::assert_root_turn(&continuation_request, Some(continuation_turn_id))?;
|
||||||
responses::assert_parent_turn(&continuation_request, /*expected*/ None)?;
|
responses::assert_parent_turn(&continuation_request, /*expected*/ None)?;
|
||||||
|
|
||||||
server.shutdown().await;
|
server.shutdown().await;
|
||||||
@@ -3446,7 +3446,7 @@ async fn thread_goal_lifecycle_emits_analytics_and_clear_deletes_goal() -> Resul
|
|||||||
goal_request_body["client_metadata"]["turn_id"],
|
goal_request_body["client_metadata"]["turn_id"],
|
||||||
causal_turn_id
|
causal_turn_id
|
||||||
);
|
);
|
||||||
responses::assert_root_turn(&goal_request_body, /*expected*/ None)?;
|
responses::assert_root_turn(&goal_request_body, Some(causal_turn_id))?;
|
||||||
responses::assert_parent_turn(&goal_request_body, /*expected*/ None)?;
|
responses::assert_parent_turn(&goal_request_body, /*expected*/ None)?;
|
||||||
|
|
||||||
let clear_id = mcp
|
let clear_id = mcp
|
||||||
|
|||||||
@@ -386,9 +386,9 @@ async fn turn_start_with_empty_input_runs_model_request() -> Result<()> {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
(
|
(
|
||||||
event["event_params"]["turn_id"].as_str(),
|
event["event_params"]["turn_id"].as_str(),
|
||||||
event["event_params"].get("root_turn_id"),
|
event["event_params"]["root_turn_id"].as_str(),
|
||||||
),
|
),
|
||||||
(Some(turn.id.as_str()), Some(&Value::Null))
|
(Some(turn.id.as_str()), Some(turn.id.as_str()))
|
||||||
);
|
);
|
||||||
|
|
||||||
let requests = server
|
let requests = server
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ impl CodexResponsesRequestKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_turn_identity(self) -> bool {
|
fn has_thread_identity(self) -> bool {
|
||||||
!matches!(self, CodexResponsesRequestKind::Memory)
|
!matches!(self, CodexResponsesRequestKind::Memory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,20 +380,18 @@ impl CodexResponsesMetadata {
|
|||||||
let (request_kind, compaction) = request_kind.metadata();
|
let (request_kind, compaction) = request_kind.metadata();
|
||||||
(Some(request_kind), compaction)
|
(Some(request_kind), compaction)
|
||||||
});
|
});
|
||||||
let has_turn_identity =
|
let has_thread_identity =
|
||||||
request_kind.is_none_or(CodexResponsesRequestKind::has_turn_identity);
|
request_kind.is_none_or(CodexResponsesRequestKind::has_thread_identity);
|
||||||
let has_request_identity =
|
let has_request_identity =
|
||||||
request_kind.is_some_and(CodexResponsesRequestKind::has_turn_identity);
|
request_kind.is_some_and(CodexResponsesRequestKind::has_thread_identity);
|
||||||
CodexTurnMetadataPayload {
|
CodexTurnMetadataPayload {
|
||||||
installation_id: has_request_identity.then_some(self.installation_id.as_str()),
|
installation_id: has_request_identity.then_some(self.installation_id.as_str()),
|
||||||
session_id: has_turn_identity.then_some(self.session_id.as_str()),
|
session_id: has_thread_identity.then_some(self.session_id.as_str()),
|
||||||
thread_id: has_turn_identity.then_some(self.thread_id.as_str()),
|
thread_id: has_thread_identity.then_some(self.thread_id.as_str()),
|
||||||
agent_name: has_turn_identity
|
agent_name: has_thread_identity
|
||||||
.then_some(self.agent_name.as_deref())
|
.then_some(self.agent_name.as_deref())
|
||||||
.flatten(),
|
.flatten(),
|
||||||
turn_id: has_turn_identity
|
turn_id: self.turn_id.as_deref(),
|
||||||
.then_some(self.turn_id.as_deref())
|
|
||||||
.flatten(),
|
|
||||||
window_id: has_request_identity.then_some(self.window_id.as_str()),
|
window_id: has_request_identity.then_some(self.window_id.as_str()),
|
||||||
window_number: has_request_identity.then_some(self.window_number).flatten(),
|
window_number: has_request_identity.then_some(self.window_number).flatten(),
|
||||||
context_window_id: has_request_identity
|
context_window_id: has_request_identity
|
||||||
|
|||||||
@@ -292,14 +292,10 @@ impl InputQueue {
|
|||||||
&self,
|
&self,
|
||||||
active_turn: &Mutex<Option<ActiveTurn>>,
|
active_turn: &Mutex<Option<ActiveTurn>>,
|
||||||
) -> (Vec<TurnInput>, TurnStartOptions) {
|
) -> (Vec<TurnInput>, TurnStartOptions) {
|
||||||
let (pending_input, accepts_mailbox_delivery, active_turn_metadata) = {
|
let (pending_input, accepts_mailbox_delivery) = {
|
||||||
let mut active = active_turn.lock().await;
|
let mut active = active_turn.lock().await;
|
||||||
match active.as_mut() {
|
match active.as_mut() {
|
||||||
Some(active_turn) => {
|
Some(active_turn) => {
|
||||||
let active_turn_metadata = active_turn
|
|
||||||
.task
|
|
||||||
.as_ref()
|
|
||||||
.map(|task| Arc::clone(&task.turn_context.turn_metadata_state));
|
|
||||||
let mut turn_state = active_turn.turn_state.lock().await;
|
let mut turn_state = active_turn.turn_state.lock().await;
|
||||||
let accepts_mailbox_delivery =
|
let accepts_mailbox_delivery =
|
||||||
turn_state.accepts_mailbox_delivery_for_current_turn();
|
turn_state.accepts_mailbox_delivery_for_current_turn();
|
||||||
@@ -308,25 +304,15 @@ impl InputQueue {
|
|||||||
} else {
|
} else {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
};
|
};
|
||||||
(
|
(pending_input, accepts_mailbox_delivery)
|
||||||
pending_input,
|
|
||||||
accepts_mailbox_delivery,
|
|
||||||
active_turn_metadata,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
None => (Vec::new(), true, None),
|
None => (Vec::new(), true),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if !accepts_mailbox_delivery {
|
if !accepts_mailbox_delivery {
|
||||||
return (pending_input, TurnStartOptions::default());
|
return (pending_input, TurnStartOptions::default());
|
||||||
}
|
}
|
||||||
let (mailbox_items, start_options) = self.drain_mailbox_input_items().await;
|
let (mailbox_items, start_options) = self.drain_mailbox_input_items().await;
|
||||||
if let Some(active_turn_metadata) = active_turn_metadata
|
|
||||||
&& active_turn_metadata.root_turn_id().is_none()
|
|
||||||
&& let Some(root_turn_id) = start_options.root_turn_id.as_ref()
|
|
||||||
{
|
|
||||||
active_turn_metadata.set_root_turn_id(root_turn_id.clone());
|
|
||||||
}
|
|
||||||
if pending_input.is_empty() {
|
if pending_input.is_empty() {
|
||||||
(mailbox_items, start_options)
|
(mailbox_items, start_options)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -130,9 +130,6 @@ pub(super) async fn spawn_review_thread(
|
|||||||
auto_review_enabled,
|
auto_review_enabled,
|
||||||
&model_info,
|
&model_info,
|
||||||
));
|
));
|
||||||
if turn_metadata_state.can_start_root_turn(&session_source) {
|
|
||||||
turn_metadata_state.set_root_turn_id(review_turn_id.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
let extension_data = Arc::new(codex_extension_api::ExtensionData::new(
|
let extension_data = Arc::new(codex_extension_api::ExtensionData::new(
|
||||||
review_turn_id.clone(),
|
review_turn_id.clone(),
|
||||||
|
|||||||
@@ -12053,20 +12053,14 @@ async fn trigger_turn_mailbox_mail_waits_for_next_turn_after_answer_boundary() {
|
|||||||
assert!(sess.input_queue.has_trigger_turn_mailbox_items().await);
|
assert!(sess.input_queue.has_trigger_turn_mailbox_items().await);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case(None; "independent root")]
|
||||||
|
#[test_case(Some("root-a"); "inherited root")]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn active_turn_keeps_first_root_when_mail_coalesces() {
|
async fn active_turn_keeps_first_root_when_mail_coalesces(inherited_root: Option<&str>) {
|
||||||
let (sess, tc, _rx) = make_session_and_context_with_rx().await;
|
let (sess, tc, _rx) = make_session_and_context_with_rx().await;
|
||||||
tc.turn_metadata_state
|
if let Some(root) = inherited_root {
|
||||||
.set_root_turn_id("root-a".to_string());
|
tc.turn_metadata_state.set_root_turn_id(root.to_string());
|
||||||
sess.spawn_task(
|
}
|
||||||
Arc::clone(&tc),
|
|
||||||
Vec::new(),
|
|
||||||
NeverEndingTask {
|
|
||||||
kind: TaskKind::Regular,
|
|
||||||
listen_to_cancellation_token: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
let first = InterAgentCommunication::new(
|
let first = InterAgentCommunication::new(
|
||||||
AgentPath::try_from("/root/worker_a").expect("worker path should parse"),
|
AgentPath::try_from("/root/worker_a").expect("worker path should parse"),
|
||||||
AgentPath::root(),
|
AgentPath::root(),
|
||||||
@@ -12081,10 +12075,13 @@ async fn active_turn_keeps_first_root_when_mail_coalesces() {
|
|||||||
"second".to_string(),
|
"second".to_string(),
|
||||||
/*trigger_turn*/ true,
|
/*trigger_turn*/ true,
|
||||||
);
|
);
|
||||||
for (communication, parent_turn_id, root_turn_id) in [
|
for (index, (communication, parent_turn_id, root_turn_id)) in [
|
||||||
(first.clone(), "parent-a", "root-a"),
|
(first.clone(), "parent-a", "root-a"),
|
||||||
(second.clone(), "parent-b", "root-b"),
|
(second.clone(), "parent-b", "root-b"),
|
||||||
] {
|
]
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
sess.input_queue
|
sess.input_queue
|
||||||
.enqueue_mailbox_communication(
|
.enqueue_mailbox_communication(
|
||||||
communication,
|
communication,
|
||||||
@@ -12095,6 +12092,19 @@ async fn active_turn_keeps_first_root_when_mail_coalesces() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
if index == 0 {
|
||||||
|
// The first message is already queued when this independent task
|
||||||
|
// starts; the second arrives after its root is established.
|
||||||
|
sess.spawn_task(
|
||||||
|
Arc::clone(&tc),
|
||||||
|
Vec::new(),
|
||||||
|
NeverEndingTask {
|
||||||
|
kind: TaskKind::Regular,
|
||||||
|
listen_to_cancellation_token: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -12106,7 +12116,7 @@ async fn active_turn_keeps_first_root_when_mail_coalesces() {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tc.turn_metadata_state.root_turn_id().as_deref(),
|
tc.turn_metadata_state.root_turn_id().as_deref(),
|
||||||
Some("root-a")
|
Some(inherited_root.unwrap_or(&tc.sub_id))
|
||||||
);
|
);
|
||||||
assert!(!sess.input_queue.has_pending_mailbox_items().await);
|
assert!(!sess.input_queue.has_pending_mailbox_items().await);
|
||||||
|
|
||||||
|
|||||||
@@ -262,11 +262,6 @@ async fn start_or_steer(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let can_start_root_turn = start.parent_turn_id.is_none() && start.root_turn_id.is_none();
|
|
||||||
let incoming_root_turn_id = start
|
|
||||||
.parent_turn_id
|
|
||||||
.as_ref()
|
|
||||||
.map(|_| start.root_turn_id.clone());
|
|
||||||
let settings = PreparedTurnInputSettings::prepare(session, thread_settings, start).await?;
|
let settings = PreparedTurnInputSettings::prepare(session, thread_settings, start).await?;
|
||||||
match session
|
match session
|
||||||
.steer_input(
|
.steer_input(
|
||||||
@@ -275,7 +270,6 @@ async fn start_or_steer(
|
|||||||
/*expected_turn_id*/ None,
|
/*expected_turn_id*/ None,
|
||||||
settings.required_active_final_output_json_schema(),
|
settings.required_active_final_output_json_schema(),
|
||||||
responsesapi_client_metadata.clone(),
|
responsesapi_client_metadata.clone(),
|
||||||
incoming_root_turn_id,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -290,16 +284,6 @@ async fn start_or_steer(
|
|||||||
else {
|
else {
|
||||||
unreachable!("explicit user input can enter Plan mode");
|
unreachable!("explicit user input can enter Plan mode");
|
||||||
};
|
};
|
||||||
if can_start_root_turn
|
|
||||||
&& has_explicit_input
|
|
||||||
&& turn_context
|
|
||||||
.turn_metadata_state
|
|
||||||
.can_start_root_turn(&turn_context.session_source)
|
|
||||||
{
|
|
||||||
turn_context
|
|
||||||
.turn_metadata_state
|
|
||||||
.set_root_turn_id(submission_id.clone());
|
|
||||||
}
|
|
||||||
if let Some(responsesapi_client_metadata) = responsesapi_client_metadata {
|
if let Some(responsesapi_client_metadata) = responsesapi_client_metadata {
|
||||||
turn_context
|
turn_context
|
||||||
.turn_metadata_state
|
.turn_metadata_state
|
||||||
@@ -340,7 +324,6 @@ async fn start_if_idle(
|
|||||||
responsesapi_client_metadata,
|
responsesapi_client_metadata,
|
||||||
..
|
..
|
||||||
} = request;
|
} = request;
|
||||||
let can_start_root_turn = start.parent_turn_id.is_none() && start.root_turn_id.is_none();
|
|
||||||
if session.input_queue.has_trigger_turn_mailbox_items().await {
|
if session.input_queue.has_trigger_turn_mailbox_items().await {
|
||||||
return Ok(TurnInputSubmission::NotSubmitted {
|
return Ok(TurnInputSubmission::NotSubmitted {
|
||||||
reason: NotSubmittedReason::PendingTriggerTurn,
|
reason: NotSubmittedReason::PendingTriggerTurn,
|
||||||
@@ -403,16 +386,6 @@ async fn start_if_idle(
|
|||||||
.turn_metadata_state
|
.turn_metadata_state
|
||||||
.set_responsesapi_client_metadata(responsesapi_client_metadata);
|
.set_responsesapi_client_metadata(responsesapi_client_metadata);
|
||||||
}
|
}
|
||||||
if kind == TurnStartKind::User
|
|
||||||
&& can_start_root_turn
|
|
||||||
&& turn_context
|
|
||||||
.turn_metadata_state
|
|
||||||
.can_start_root_turn(&turn_context.session_source)
|
|
||||||
{
|
|
||||||
turn_context
|
|
||||||
.turn_metadata_state
|
|
||||||
.set_root_turn_id(submission_id.clone());
|
|
||||||
}
|
|
||||||
session
|
session
|
||||||
.maybe_emit_model_warnings_for_turn(turn_context.as_ref())
|
.maybe_emit_model_warnings_for_turn(turn_context.as_ref())
|
||||||
.await;
|
.await;
|
||||||
@@ -469,10 +442,6 @@ async fn steer(
|
|||||||
"only user input can steer a turn".to_string(),
|
"only user input can steer a turn".to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let incoming_root_turn_id = start
|
|
||||||
.parent_turn_id
|
|
||||||
.as_ref()
|
|
||||||
.map(|_| start.root_turn_id.clone());
|
|
||||||
let settings = PreparedTurnInputSettings::prepare(session, thread_settings, start).await?;
|
let settings = PreparedTurnInputSettings::prepare(session, thread_settings, start).await?;
|
||||||
match session
|
match session
|
||||||
.steer_input(
|
.steer_input(
|
||||||
@@ -481,7 +450,6 @@ async fn steer(
|
|||||||
Some(expected_turn_id.as_str()),
|
Some(expected_turn_id.as_str()),
|
||||||
settings.required_active_final_output_json_schema(),
|
settings.required_active_final_output_json_schema(),
|
||||||
responsesapi_client_metadata,
|
responsesapi_client_metadata,
|
||||||
incoming_root_turn_id,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -557,7 +525,6 @@ impl Session {
|
|||||||
expected_turn_id: Option<&str>,
|
expected_turn_id: Option<&str>,
|
||||||
required_final_output_json_schema: Option<&Value>,
|
required_final_output_json_schema: Option<&Value>,
|
||||||
responsesapi_client_metadata: Option<HashMap<String, String>>,
|
responsesapi_client_metadata: Option<HashMap<String, String>>,
|
||||||
incoming_root_turn_id: Option<Option<String>>,
|
|
||||||
) -> Result<String, NotSubmittedReason> {
|
) -> Result<String, NotSubmittedReason> {
|
||||||
let mut active = self.active_turn.lock().await;
|
let mut active = self.active_turn.lock().await;
|
||||||
let Some(active_turn) = active.as_mut() else {
|
let Some(active_turn) = active.as_mut() else {
|
||||||
@@ -627,18 +594,6 @@ impl Session {
|
|||||||
input => pending_turn_input(self, input.clone()).await,
|
input => pending_turn_input(self, input.clone()).await,
|
||||||
};
|
};
|
||||||
pending_input.push(input);
|
pending_input.push(input);
|
||||||
if active_task
|
|
||||||
.turn_context
|
|
||||||
.turn_metadata_state
|
|
||||||
.root_turn_id()
|
|
||||||
.is_none()
|
|
||||||
&& let Some(Some(incoming_root_turn_id)) = incoming_root_turn_id
|
|
||||||
{
|
|
||||||
active_task
|
|
||||||
.turn_context
|
|
||||||
.turn_metadata_state
|
|
||||||
.set_root_turn_id(incoming_root_turn_id);
|
|
||||||
}
|
|
||||||
self.input_queue
|
self.input_queue
|
||||||
.extend_pending_input_and_accept_mailbox_delivery_for_turn_state(
|
.extend_pending_input_and_accept_mailbox_delivery_for_turn_state(
|
||||||
active_turn.turn_state.as_ref(),
|
active_turn.turn_state.as_ref(),
|
||||||
|
|||||||
@@ -285,6 +285,11 @@ impl Session {
|
|||||||
input: Vec<TurnInput>,
|
input: Vec<TurnInput>,
|
||||||
task: T,
|
task: T,
|
||||||
) {
|
) {
|
||||||
|
// Inherited or recovered roots are applied before task start. Otherwise this
|
||||||
|
// task owns its turn, including background work. Later mail cannot change it.
|
||||||
|
turn_context
|
||||||
|
.turn_metadata_state
|
||||||
|
.set_root_turn_id(turn_context.sub_id.clone());
|
||||||
let task: Arc<dyn AnySessionTask> = Arc::new(task);
|
let task: Arc<dyn AnySessionTask> = Arc::new(task);
|
||||||
let task_kind = task.kind();
|
let task_kind = task.kind();
|
||||||
let span_name = task.span_name();
|
let span_name = task.span_name();
|
||||||
@@ -307,14 +312,7 @@ impl Session {
|
|||||||
.await
|
.await
|
||||||
.clear_turn(&turn_context.sub_id);
|
.clear_turn(&turn_context.sub_id);
|
||||||
|
|
||||||
let (pending_items, start_options) = self.input_queue.drain_mailbox_input_items().await;
|
let (pending_items, _) = self.input_queue.drain_mailbox_input_items().await;
|
||||||
if turn_context.turn_metadata_state.root_turn_id().is_none()
|
|
||||||
&& let Some(root_turn_id) = start_options.root_turn_id
|
|
||||||
{
|
|
||||||
turn_context
|
|
||||||
.turn_metadata_state
|
|
||||||
.set_root_turn_id(root_turn_id);
|
|
||||||
}
|
|
||||||
let turn_state = {
|
let turn_state = {
|
||||||
let mut active = self.active_turn.lock().await;
|
let mut active = self.active_turn.lock().await;
|
||||||
let turn = active.get_or_insert_with(ActiveTurn::default);
|
let turn = active.get_or_insert_with(ActiveTurn::default);
|
||||||
|
|||||||
@@ -93,7 +93,10 @@ pub async fn detached_memory_responses_metadata(
|
|||||||
permission_profile: &PermissionProfile,
|
permission_profile: &PermissionProfile,
|
||||||
sandbox: Option<&str>,
|
sandbox: Option<&str>,
|
||||||
) -> CodexResponsesMetadata {
|
) -> CodexResponsesMetadata {
|
||||||
|
let turn_id = uuid::Uuid::now_v7().to_string();
|
||||||
let mut metadata = CodexResponsesMetadata {
|
let mut metadata = CodexResponsesMetadata {
|
||||||
|
turn_id: Some(turn_id.clone()),
|
||||||
|
root_turn_id: Some(turn_id),
|
||||||
request_kind: Some(CodexResponsesRequestKind::Memory),
|
request_kind: Some(CodexResponsesRequestKind::Memory),
|
||||||
thread_source: Some(ThreadSource::MemoryConsolidation),
|
thread_source: Some(ThreadSource::MemoryConsolidation),
|
||||||
subagent_header: subagent_header_value(session_source),
|
subagent_header: subagent_header_value(session_source),
|
||||||
@@ -340,24 +343,6 @@ impl TurnMetadataState {
|
|||||||
self.root_turn_id.get().cloned()
|
self.root_turn_id.get().cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn can_start_root_turn(&self, session_source: &SessionSource) -> bool {
|
|
||||||
if session_source.is_non_root_agent() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
match &self.thread_source {
|
|
||||||
// Desktop create/fork/send lacks trusted app-server provenance; fail closed.
|
|
||||||
Some(
|
|
||||||
ThreadSource::Subagent
|
|
||||||
| ThreadSource::GuardianReview
|
|
||||||
| ThreadSource::MemoryConsolidation,
|
|
||||||
) => false,
|
|
||||||
Some(ThreadSource::Feature(feature)) => {
|
|
||||||
!matches!(feature.as_str(), "system" | "title") && !feature.starts_with("ambient")
|
|
||||||
}
|
|
||||||
Some(ThreadSource::User) | None => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_responsesapi_client_metadata(
|
pub(crate) fn set_responsesapi_client_metadata(
|
||||||
&self,
|
&self,
|
||||||
responsesapi_client_metadata: HashMap<String, String>,
|
responsesapi_client_metadata: HashMap<String, String>,
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ async fn wait_for_git_enrichment(state: &TurnMetadataState) -> Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn detached_memory_responses_metadata_omits_turn_identity() {
|
async fn detached_memory_responses_metadata_starts_an_independent_root_turn() {
|
||||||
let (_temp_dir, repo_path) = create_clean_git_repo("repo-東京").await;
|
let (_temp_dir, repo_path) = create_clean_git_repo("repo-東京").await;
|
||||||
|
|
||||||
let thread_manager = crate::ThreadManager::with_models_provider_for_tests(
|
let thread_manager = crate::ThreadManager::with_models_provider_for_tests(
|
||||||
@@ -147,7 +147,7 @@ async fn detached_memory_responses_metadata_omits_turn_identity() {
|
|||||||
crate::config::test_config().await.model_provider,
|
crate::config::test_config().await.model_provider,
|
||||||
);
|
);
|
||||||
|
|
||||||
let header = detached_memory_responses_metadata(
|
let metadata = detached_memory_responses_metadata(
|
||||||
&thread_manager,
|
&thread_manager,
|
||||||
String::new(),
|
String::new(),
|
||||||
String::new(),
|
String::new(),
|
||||||
@@ -158,9 +158,8 @@ async fn detached_memory_responses_metadata_omits_turn_identity() {
|
|||||||
&PermissionProfile::read_only(),
|
&PermissionProfile::read_only(),
|
||||||
Some("none"),
|
Some("none"),
|
||||||
)
|
)
|
||||||
.await
|
.await;
|
||||||
.turn_metadata_json()
|
let header = metadata.turn_metadata_json().expect("header");
|
||||||
.expect("header");
|
|
||||||
assert!(header.is_ascii());
|
assert!(header.is_ascii());
|
||||||
assert!(!header.contains("東京"));
|
assert!(!header.contains("東京"));
|
||||||
let parsed: Value = serde_json::from_str(&header).expect("valid json");
|
let parsed: Value = serde_json::from_str(&header).expect("valid json");
|
||||||
@@ -173,8 +172,18 @@ async fn detached_memory_responses_metadata_omits_turn_identity() {
|
|||||||
assert!(parsed.get("session_id").is_none());
|
assert!(parsed.get("session_id").is_none());
|
||||||
assert!(parsed.get("thread_id").is_none());
|
assert!(parsed.get("thread_id").is_none());
|
||||||
assert!(parsed.get("forked_from_thread_id").is_none());
|
assert!(parsed.get("forked_from_thread_id").is_none());
|
||||||
assert!(parsed.get("turn_id").is_none());
|
let turn_id = parsed["turn_id"].as_str().expect("memory turn ID");
|
||||||
assert!(parsed.get(ROOT_TURN_ID_KEY).is_none());
|
uuid::Uuid::parse_str(turn_id).expect("memory turn ID is a UUID");
|
||||||
|
assert_eq!(parsed[ROOT_TURN_ID_KEY], parsed["turn_id"]);
|
||||||
|
let client_metadata = metadata.client_metadata();
|
||||||
|
assert_eq!(
|
||||||
|
client_metadata.get("turn_id").map(String::as_str),
|
||||||
|
Some(turn_id)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
client_metadata.get(ROOT_TURN_ID_KEY).map(String::as_str),
|
||||||
|
Some(turn_id)
|
||||||
|
);
|
||||||
assert!(parsed.get(WINDOW_ID_KEY).is_none());
|
assert!(parsed.get(WINDOW_ID_KEY).is_none());
|
||||||
|
|
||||||
let expected_repo_path = repo_path.to_string_lossy().into_owned();
|
let expected_repo_path = repo_path.to_string_lossy().into_owned();
|
||||||
@@ -221,10 +230,14 @@ async fn detached_memory_responses_metadata_omits_empty_workspace_metadata() {
|
|||||||
.turn_metadata_json()
|
.turn_metadata_json()
|
||||||
.expect("detached memory should emit its request kind");
|
.expect("detached memory should emit its request kind");
|
||||||
let parsed: Value = serde_json::from_str(&header).expect("valid json");
|
let parsed: Value = serde_json::from_str(&header).expect("valid json");
|
||||||
|
let turn_id = parsed["turn_id"].as_str().expect("memory turn ID");
|
||||||
|
uuid::Uuid::parse_str(turn_id).expect("memory turn ID is a UUID");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parsed,
|
parsed,
|
||||||
serde_json::json!({
|
serde_json::json!({
|
||||||
|
"turn_id": turn_id,
|
||||||
|
"root_turn_id": turn_id,
|
||||||
"request_kind": "memory",
|
"request_kind": "memory",
|
||||||
"sandbox_mode": "read-only",
|
"sandbox_mode": "read-only",
|
||||||
"thread_source": "memory_consolidation",
|
"thread_source": "memory_consolidation",
|
||||||
|
|||||||
@@ -1259,7 +1259,7 @@ async fn assert_remote_manual_compact_request_parity(
|
|||||||
.await?;
|
.await?;
|
||||||
wait_for_turn_complete(&codex).await;
|
wait_for_turn_complete(&codex).await;
|
||||||
|
|
||||||
codex.submit(Op::Compact).await?;
|
let compact_turn_id = codex.submit(Op::Compact).await?;
|
||||||
wait_for_turn_complete(&codex).await;
|
wait_for_turn_complete(&codex).await;
|
||||||
|
|
||||||
let response_requests = responses_mock.requests();
|
let response_requests = responses_mock.requests();
|
||||||
@@ -1280,6 +1280,13 @@ async fn assert_remote_manual_compact_request_parity(
|
|||||||
let compact_request = compact_mock.single_request();
|
let compact_request = compact_mock.single_request();
|
||||||
let normal_body = normal_request.body_json();
|
let normal_body = normal_request.body_json();
|
||||||
let compact_body = compact_request.body_json();
|
let compact_body = compact_request.body_json();
|
||||||
|
let compact_metadata: Value = serde_json::from_str(
|
||||||
|
&compact_request
|
||||||
|
.header("x-codex-turn-metadata")
|
||||||
|
.expect("compaction turn metadata"),
|
||||||
|
)?;
|
||||||
|
assert_eq!(compact_metadata["turn_id"], compact_turn_id);
|
||||||
|
assert_eq!(compact_metadata["root_turn_id"], compact_turn_id);
|
||||||
let expected_routing_hint = |body: &Value| {
|
let expected_routing_hint = |body: &Value| {
|
||||||
if !uses_codex_backend {
|
if !uses_codex_backend {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
@@ -329,6 +329,9 @@ async fn guardian_prewarm_and_review_skip_redundant_git_enrichment() -> Result<(
|
|||||||
|
|
||||||
#[test_case("system"; "system background thread")]
|
#[test_case("system"; "system background thread")]
|
||||||
#[test_case("ambient_background"; "ambient background thread")]
|
#[test_case("ambient_background"; "ambient background thread")]
|
||||||
|
#[test_case("ambient_suggestions"; "ambient suggestions")]
|
||||||
|
#[test_case("ambient_suggestion_safety"; "ambient suggestion safety")]
|
||||||
|
#[test_case("title"; "title background thread")]
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn ephemeral_system_thread_prewarm_skips_and_turn_observes_fresh_state(
|
async fn ephemeral_system_thread_prewarm_skips_and_turn_observes_fresh_state(
|
||||||
thread_source: &str,
|
thread_source: &str,
|
||||||
@@ -388,7 +391,7 @@ async fn ephemeral_system_thread_prewarm_skips_and_turn_observes_fresh_state(
|
|||||||
assert!(turn_metadata(&prewarm)?.get("workspaces").is_none());
|
assert!(turn_metadata(&prewarm)?.get("workspaces").is_none());
|
||||||
|
|
||||||
std::fs::write(repo.path().join("untracked.txt"), "dirty\n")?;
|
std::fs::write(repo.path().join("untracked.txt"), "dirty\n")?;
|
||||||
system_thread
|
let submission = system_thread
|
||||||
.thread
|
.thread
|
||||||
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
|
||||||
text: "generate a thread title".into(),
|
text: "generate a thread title".into(),
|
||||||
@@ -405,7 +408,10 @@ async fn ephemeral_system_thread_prewarm_skips_and_turn_observes_fresh_state(
|
|||||||
.and_then(|connection| connection.get(2))
|
.and_then(|connection| connection.get(2))
|
||||||
.context("system turn follow-up request")?
|
.context("system turn follow-up request")?
|
||||||
.body_json();
|
.body_json();
|
||||||
assert_root_turn(&turn, /*expected*/ None)?;
|
let codex_core::TurnInputSubmission::Started { turn_id } = submission else {
|
||||||
|
panic!("background input should start a turn");
|
||||||
|
};
|
||||||
|
assert_root_turn(&turn, Some(&turn_id))?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
turn_metadata(&turn)?["workspaces"],
|
turn_metadata(&turn)?["workspaces"],
|
||||||
expected_workspace(repo.path(), &head, /*has_changes*/ true)
|
expected_workspace(repo.path(), &head, /*has_changes*/ true)
|
||||||
|
|||||||
@@ -86,12 +86,14 @@ async fn idle_response_items_include_pending_mailbox_in_first_request() -> anyho
|
|||||||
responses::user_message_item("automatic response item"),
|
responses::user_message_item("automatic response item"),
|
||||||
)))
|
)))
|
||||||
.await?;
|
.await?;
|
||||||
assert!(matches!(submission, StartIfIdleSubmission::Started { .. }));
|
let StartIfIdleSubmission::Started { turn_id } = submission else {
|
||||||
|
panic!("automatic input should start a turn");
|
||||||
|
};
|
||||||
wait_for_turn_complete(test.codex.as_ref()).await;
|
wait_for_turn_complete(test.codex.as_ref()).await;
|
||||||
|
|
||||||
let request = response.single_request();
|
let request = response.single_request();
|
||||||
let request_body = request.body_json();
|
let request_body = request.body_json();
|
||||||
responses::assert_root_turn(&request_body, /*expected*/ None)?;
|
responses::assert_root_turn(&request_body, Some(&turn_id))?;
|
||||||
responses::assert_parent_turn(&request_body, /*expected*/ None)?;
|
responses::assert_parent_turn(&request_body, /*expected*/ None)?;
|
||||||
let user_messages = request.message_input_texts("user");
|
let user_messages = request.message_input_texts("user");
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -670,7 +670,18 @@ async fn memories_startup_phase1_uses_live_thread_service_tier_and_detached_meta
|
|||||||
assert_eq!(metadata["sandbox_mode"].as_str(), Some("workspace-write"));
|
assert_eq!(metadata["sandbox_mode"].as_str(), Some("workspace-write"));
|
||||||
assert!(metadata.get("session_id").is_none());
|
assert!(metadata.get("session_id").is_none());
|
||||||
assert!(metadata.get("thread_id").is_none());
|
assert!(metadata.get("thread_id").is_none());
|
||||||
assert!(metadata.get("turn_id").is_none());
|
let turn_id = metadata["turn_id"].as_str().expect("memory turn ID");
|
||||||
|
uuid::Uuid::parse_str(turn_id).expect("memory turn ID is a UUID");
|
||||||
|
assert_eq!(metadata["root_turn_id"], metadata["turn_id"]);
|
||||||
|
let request_body = request.body_json();
|
||||||
|
assert_eq!(
|
||||||
|
request_body["client_metadata"]["turn_id"],
|
||||||
|
metadata["turn_id"]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
request_body["client_metadata"]["root_turn_id"],
|
||||||
|
metadata["root_turn_id"]
|
||||||
|
);
|
||||||
assert!(metadata.get("window_id").is_none());
|
assert!(metadata.get("window_id").is_none());
|
||||||
assert!(metadata.get("workspaces").is_some());
|
assert!(metadata.get("workspaces").is_some());
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user