mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
analytics: add parent turn id to thread init events
This commit is contained in:
@@ -1318,6 +1318,7 @@ fn thread_initialized_event_serializes_expected_shape() {
|
||||
initialization_mode: ThreadInitializationMode::New,
|
||||
subagent_source: None,
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
created_at: 1,
|
||||
},
|
||||
});
|
||||
@@ -1349,6 +1350,7 @@ fn thread_initialized_event_serializes_expected_shape() {
|
||||
"initialization_mode": "new",
|
||||
"subagent_source": null,
|
||||
"parent_thread_id": null,
|
||||
"parent_turn_id": null,
|
||||
"created_at": 1
|
||||
}
|
||||
})
|
||||
@@ -1733,6 +1735,7 @@ async fn compaction_event_ingests_custom_fact() {
|
||||
"gpt-5",
|
||||
AppServerSessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: Some("turn-parent-222".to_string()),
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1744,6 +1747,13 @@ async fn compaction_event_ingests_custom_fact() {
|
||||
&mut events,
|
||||
)
|
||||
.await;
|
||||
let payload = serde_json::to_value(&events).expect("serialize events");
|
||||
assert_eq!(payload.as_array().expect("events array").len(), 1);
|
||||
assert_eq!(payload[0]["event_type"], "codex_thread_initialized");
|
||||
assert_eq!(
|
||||
payload[0]["event_params"]["parent_turn_id"],
|
||||
"turn-parent-222"
|
||||
);
|
||||
events.clear();
|
||||
|
||||
reducer
|
||||
@@ -2391,6 +2401,7 @@ fn subagent_thread_started_review_serializes_expected_shape() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-review".to_string(),
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
@@ -2423,6 +2434,7 @@ fn subagent_thread_started_review_serializes_expected_shape() {
|
||||
assert_eq!(payload["event_params"]["initialization_mode"], "new");
|
||||
assert_eq!(payload["event_params"]["subagent_source"], "review");
|
||||
assert_eq!(payload["event_params"]["parent_thread_id"], json!(null));
|
||||
assert_eq!(payload["event_params"]["parent_turn_id"], json!(null));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2434,6 +2446,7 @@ fn subagent_thread_started_thread_spawn_serializes_parent_thread_id() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-spawn".to_string(),
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
@@ -2441,6 +2454,7 @@ fn subagent_thread_started_thread_spawn_serializes_parent_thread_id() {
|
||||
ephemeral: true,
|
||||
subagent_source: SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: Some("turn-parent-123".to_string()),
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2457,6 +2471,7 @@ fn subagent_thread_started_thread_spawn_serializes_parent_thread_id() {
|
||||
payload["event_params"]["parent_thread_id"],
|
||||
"11111111-1111-1111-1111-111111111111"
|
||||
);
|
||||
assert_eq!(payload["event_params"]["parent_turn_id"], "turn-parent-123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2465,6 +2480,7 @@ fn subagent_thread_started_memory_consolidation_serializes_expected_shape() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-memory".to_string(),
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
@@ -2482,6 +2498,7 @@ fn subagent_thread_started_memory_consolidation_serializes_expected_shape() {
|
||||
"memory_consolidation"
|
||||
);
|
||||
assert_eq!(payload["event_params"]["parent_thread_id"], json!(null));
|
||||
assert_eq!(payload["event_params"]["parent_turn_id"], json!(null));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2490,6 +2507,7 @@ fn subagent_thread_started_other_serializes_expected_shape() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-guardian".to_string(),
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
@@ -2503,6 +2521,7 @@ fn subagent_thread_started_other_serializes_expected_shape() {
|
||||
let payload = serde_json::to_value(&event).expect("serialize other subagent event");
|
||||
assert_eq!(payload["event_params"]["subagent_source"], "guardian");
|
||||
assert_eq!(payload["event_params"]["parent_thread_id"], json!(null));
|
||||
assert_eq!(payload["event_params"]["parent_turn_id"], json!(null));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2511,6 +2530,7 @@ fn subagent_thread_started_other_serializes_explicit_parent_thread_id() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-guardian".to_string(),
|
||||
parent_thread_id: Some("parent-thread-guardian".to_string()),
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
@@ -2527,6 +2547,7 @@ fn subagent_thread_started_other_serializes_explicit_parent_thread_id() {
|
||||
payload["event_params"]["parent_thread_id"],
|
||||
"parent-thread-guardian"
|
||||
);
|
||||
assert_eq!(payload["event_params"]["parent_turn_id"], json!(null));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -2540,6 +2561,7 @@ async fn subagent_thread_started_publishes_without_initialize() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-review".to_string(),
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
@@ -2606,6 +2628,7 @@ async fn subagent_thread_started_inherits_parent_connection_for_new_thread() {
|
||||
&mut events,
|
||||
)
|
||||
.await;
|
||||
events.clear();
|
||||
|
||||
reducer
|
||||
.ingest(
|
||||
@@ -2613,6 +2636,7 @@ async fn subagent_thread_started_inherits_parent_connection_for_new_thread() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-review".to_string(),
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
product_client_id: "parent-client".to_string(),
|
||||
client_name: "parent-client".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
@@ -2620,6 +2644,7 @@ async fn subagent_thread_started_inherits_parent_connection_for_new_thread() {
|
||||
ephemeral: false,
|
||||
subagent_source: SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: Some("turn-parent-444".to_string()),
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2632,6 +2657,13 @@ async fn subagent_thread_started_inherits_parent_connection_for_new_thread() {
|
||||
)
|
||||
.await;
|
||||
|
||||
let payload = serde_json::to_value(&events).expect("serialize events");
|
||||
assert_eq!(payload.as_array().expect("events array").len(), 1);
|
||||
assert_eq!(payload[0]["event_type"], "codex_thread_initialized");
|
||||
assert_eq!(
|
||||
payload[0]["event_params"]["parent_turn_id"],
|
||||
"turn-parent-444"
|
||||
);
|
||||
events.clear();
|
||||
reducer
|
||||
.ingest(
|
||||
@@ -2680,6 +2712,7 @@ async fn subagent_tool_items_inherit_parent_connection_metadata() {
|
||||
SubAgentThreadStartedInput {
|
||||
thread_id: "thread-subagent".to_string(),
|
||||
parent_thread_id: Some("thread-1".to_string()),
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::events::SkillInvocationEventRequest;
|
||||
use crate::events::TrackEventRequest;
|
||||
use crate::facts::AnalyticsFact;
|
||||
use crate::facts::InvocationType;
|
||||
use crate::facts::SubAgentThreadStartedInput;
|
||||
use codex_app_server_protocol::ApprovalsReviewer as AppServerApprovalsReviewer;
|
||||
use codex_app_server_protocol::AskForApproval as AppServerAskForApproval;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
@@ -28,13 +29,23 @@ use codex_app_server_protocol::TurnStartResponse;
|
||||
use codex_app_server_protocol::TurnStatus as AppServerTurnStatus;
|
||||
use codex_app_server_protocol::TurnSteerParams;
|
||||
use codex_app_server_protocol::TurnSteerResponse;
|
||||
use codex_login::AuthManager;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use codex_utils_absolute_path::test_support::PathBufExt;
|
||||
use codex_utils_absolute_path::test_support::test_path_buf;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Duration;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::sync::mpsc::error::TryRecvError;
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::time::timeout;
|
||||
|
||||
fn sample_accepted_line_fingerprint_event(thread_id: &str) -> TrackEventRequest {
|
||||
TrackEventRequest::AcceptedLineFingerprints(Box::new(
|
||||
@@ -84,6 +95,53 @@ fn client_with_receiver() -> (AnalyticsEventsClient, mpsc::Receiver<AnalyticsFac
|
||||
(AnalyticsEventsClient { queue: Some(queue) }, receiver)
|
||||
}
|
||||
|
||||
struct CapturedHttpRequest {
|
||||
request_line: String,
|
||||
body: Vec<u8>,
|
||||
}
|
||||
|
||||
fn http_header_end(buffer: &[u8]) -> Option<usize> {
|
||||
buffer.windows(4).position(|window| window == b"\r\n\r\n")
|
||||
}
|
||||
|
||||
fn content_length(headers: &str) -> usize {
|
||||
headers
|
||||
.lines()
|
||||
.find_map(|line| {
|
||||
line.strip_prefix("content-length: ")
|
||||
.or_else(|| line.strip_prefix("Content-Length: "))
|
||||
})
|
||||
.and_then(|value| value.parse().ok())
|
||||
.expect("request should include content-length")
|
||||
}
|
||||
|
||||
async fn capture_one_http_request(listener: TcpListener) -> CapturedHttpRequest {
|
||||
let (mut stream, _) = listener.accept().await.expect("accept request");
|
||||
let mut buffer = Vec::new();
|
||||
let mut chunk = [0; 1024];
|
||||
|
||||
loop {
|
||||
let bytes_read = stream.read(&mut chunk).await.expect("read request");
|
||||
assert!(bytes_read > 0, "connection closed before request completed");
|
||||
buffer.extend_from_slice(&chunk[..bytes_read]);
|
||||
|
||||
if let Some(header_end) = http_header_end(&buffer) {
|
||||
let headers = std::str::from_utf8(&buffer[..header_end]).expect("headers are utf8");
|
||||
let body_len = content_length(headers);
|
||||
let body_start = header_end + 4;
|
||||
if buffer.len() >= body_start + body_len {
|
||||
let request_line = headers.lines().next().expect("request line").to_string();
|
||||
let body = buffer[body_start..body_start + body_len].to_vec();
|
||||
stream
|
||||
.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")
|
||||
.await
|
||||
.expect("write response");
|
||||
return CapturedHttpRequest { request_line, body };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sample_turn_start_request() -> ClientRequest {
|
||||
ClientRequest::TurnStart {
|
||||
request_id: RequestId::Integer(1),
|
||||
@@ -262,6 +320,70 @@ fn track_response_only_enqueues_analytics_relevant_responses() {
|
||||
assert!(matches!(receiver.try_recv(), Err(TryRecvError::Empty)));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn track_subagent_thread_started_sends_parent_turn_id_to_backend() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0")
|
||||
.await
|
||||
.expect("bind capture server");
|
||||
let base_url = format!(
|
||||
"http://{}/backend-api",
|
||||
listener.local_addr().expect("local address")
|
||||
);
|
||||
let (request_tx, request_rx) = oneshot::channel();
|
||||
tokio::spawn(async move {
|
||||
let request = capture_one_http_request(listener).await;
|
||||
let _ = request_tx.send(request);
|
||||
});
|
||||
|
||||
let auth_manager =
|
||||
AuthManager::from_auth_for_testing(CodexAuth::create_dummy_chatgpt_auth_for_testing());
|
||||
let client = AnalyticsEventsClient::new(auth_manager, base_url, Some(true));
|
||||
let parent_thread_id =
|
||||
codex_protocol::ThreadId::from_string("11111111-1111-1111-1111-111111111111")
|
||||
.expect("valid thread id");
|
||||
|
||||
client.track_subagent_thread_started(SubAgentThreadStartedInput {
|
||||
thread_id: "thread-spawn".to_string(),
|
||||
parent_thread_id: None,
|
||||
parent_turn_id: None,
|
||||
product_client_id: "codex-tui".to_string(),
|
||||
client_name: "codex-tui".to_string(),
|
||||
client_version: "1.0.0".to_string(),
|
||||
model: "gpt-5".to_string(),
|
||||
ephemeral: false,
|
||||
subagent_source: SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: Some("turn-parent-123".to_string()),
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
agent_role: None,
|
||||
},
|
||||
created_at: 123,
|
||||
});
|
||||
|
||||
let captured = timeout(Duration::from_secs(5), request_rx)
|
||||
.await
|
||||
.expect("analytics request should be sent")
|
||||
.expect("capture task should return request");
|
||||
assert!(
|
||||
captured
|
||||
.request_line
|
||||
.starts_with("POST /backend-api/codex/analytics-events/events ")
|
||||
);
|
||||
let payload: Value =
|
||||
serde_json::from_slice(&captured.body).expect("analytics request body should be json");
|
||||
let event = &payload["events"][0];
|
||||
|
||||
assert_eq!(event["event_type"], "codex_thread_initialized");
|
||||
assert_eq!(event["event_params"]["subagent_source"], "thread_spawn");
|
||||
assert_eq!(
|
||||
event["event_params"]["parent_thread_id"],
|
||||
"11111111-1111-1111-1111-111111111111"
|
||||
);
|
||||
assert_eq!(event["event_params"]["parent_turn_id"], "turn-parent-123");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn track_event_request_batches_only_isolates_accepted_line_fingerprint_events() {
|
||||
let batches = track_event_request_batches(vec![
|
||||
|
||||
@@ -155,6 +155,7 @@ pub(crate) struct ThreadInitializedEventParams {
|
||||
pub(crate) initialization_mode: ThreadInitializationMode,
|
||||
pub(crate) subagent_source: Option<String>,
|
||||
pub(crate) parent_thread_id: Option<String>,
|
||||
pub(crate) parent_turn_id: Option<String>,
|
||||
pub(crate) created_at: u64,
|
||||
}
|
||||
|
||||
@@ -1040,6 +1041,9 @@ pub(crate) fn subagent_thread_started_event_request(
|
||||
parent_thread_id: input
|
||||
.parent_thread_id
|
||||
.or_else(|| subagent_parent_thread_id(&input.subagent_source)),
|
||||
parent_turn_id: input
|
||||
.parent_turn_id
|
||||
.or_else(|| subagent_parent_turn_id(&input.subagent_source)),
|
||||
created_at: input.created_at,
|
||||
};
|
||||
ThreadInitializedEvent {
|
||||
@@ -1067,6 +1071,13 @@ pub(crate) fn subagent_parent_thread_id(subagent_source: &SubAgentSource) -> Opt
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn subagent_parent_turn_id(subagent_source: &SubAgentSource) -> Option<String> {
|
||||
match subagent_source {
|
||||
SubAgentSource::ThreadSpawn { parent_turn_id, .. } => parent_turn_id.clone(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn analytics_hook_status(status: HookRunStatus) -> HookRunStatus {
|
||||
match status {
|
||||
// Running is unexpected here and normalized defensively.
|
||||
|
||||
@@ -201,6 +201,7 @@ pub struct AppInvocation {
|
||||
pub struct SubAgentThreadStartedInput {
|
||||
pub thread_id: String,
|
||||
pub parent_thread_id: Option<String>,
|
||||
pub parent_turn_id: Option<String>,
|
||||
pub product_client_id: String,
|
||||
pub client_name: String,
|
||||
pub client_version: String,
|
||||
|
||||
@@ -56,6 +56,7 @@ use crate::events::codex_plugin_metadata;
|
||||
use crate::events::codex_plugin_used_metadata;
|
||||
use crate::events::plugin_state_event_type;
|
||||
use crate::events::subagent_parent_thread_id;
|
||||
use crate::events::subagent_parent_turn_id;
|
||||
use crate::events::subagent_source_name;
|
||||
use crate::events::subagent_thread_started_event_request;
|
||||
use crate::facts::AnalyticsFact;
|
||||
@@ -259,6 +260,7 @@ struct ThreadMetadataState {
|
||||
initialization_mode: ThreadInitializationMode,
|
||||
subagent_source: Option<String>,
|
||||
parent_thread_id: Option<String>,
|
||||
parent_turn_id: Option<String>,
|
||||
}
|
||||
|
||||
impl ThreadMetadataState {
|
||||
@@ -267,10 +269,11 @@ impl ThreadMetadataState {
|
||||
thread_source: Option<ThreadSource>,
|
||||
initialization_mode: ThreadInitializationMode,
|
||||
) -> Self {
|
||||
let (subagent_source, parent_thread_id) = match session_source {
|
||||
let (subagent_source, parent_thread_id, parent_turn_id) = match session_source {
|
||||
SessionSource::SubAgent(subagent_source) => (
|
||||
Some(subagent_source_name(subagent_source)),
|
||||
subagent_parent_thread_id(subagent_source),
|
||||
subagent_parent_turn_id(subagent_source),
|
||||
),
|
||||
SessionSource::Cli
|
||||
| SessionSource::VSCode
|
||||
@@ -278,13 +281,14 @@ impl ThreadMetadataState {
|
||||
| SessionSource::Mcp
|
||||
| SessionSource::Custom(_)
|
||||
| SessionSource::Internal(_)
|
||||
| SessionSource::Unknown => (None, None),
|
||||
| SessionSource::Unknown => (None, None, None),
|
||||
};
|
||||
Self {
|
||||
thread_source,
|
||||
initialization_mode,
|
||||
subagent_source,
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -517,6 +521,10 @@ impl AnalyticsReducer {
|
||||
.parent_thread_id
|
||||
.clone()
|
||||
.or_else(|| subagent_parent_thread_id(&input.subagent_source));
|
||||
let parent_turn_id = input
|
||||
.parent_turn_id
|
||||
.clone()
|
||||
.or_else(|| subagent_parent_turn_id(&input.subagent_source));
|
||||
let parent_connection_id = parent_thread_id
|
||||
.as_ref()
|
||||
.and_then(|parent_thread_id| self.threads.get(parent_thread_id))
|
||||
@@ -529,6 +537,7 @@ impl AnalyticsReducer {
|
||||
initialization_mode: ThreadInitializationMode::New,
|
||||
subagent_source: Some(subagent_source_name(&input.subagent_source)),
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
});
|
||||
if thread_state.connection_id.is_none() {
|
||||
thread_state.connection_id = parent_connection_id;
|
||||
@@ -1260,6 +1269,7 @@ impl AnalyticsReducer {
|
||||
initialization_mode,
|
||||
subagent_source: thread_metadata.subagent_source.clone(),
|
||||
parent_thread_id: thread_metadata.parent_thread_id,
|
||||
parent_turn_id: thread_metadata.parent_turn_id,
|
||||
created_at: u64::try_from(thread.created_at).unwrap_or_default(),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2900,6 +2900,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
+7
@@ -15017,6 +15017,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/v2/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
+7
@@ -12841,6 +12841,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -905,6 +905,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -720,6 +720,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
+7
@@ -720,6 +720,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -720,6 +720,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -905,6 +905,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -720,6 +720,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -905,6 +905,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -720,6 +720,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -720,6 +720,13 @@
|
||||
},
|
||||
"parent_thread_id": {
|
||||
"$ref": "#/definitions/ThreadId"
|
||||
},
|
||||
"parent_turn_id": {
|
||||
"default": null,
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
import type { AgentPath } from "./AgentPath";
|
||||
import type { ThreadId } from "./ThreadId";
|
||||
|
||||
export type SubAgentSource = "review" | "compact" | { "thread_spawn": { parent_thread_id: ThreadId, depth: number, agent_path: AgentPath | null, agent_nickname: string | null, agent_role: string | null, } } | "memory_consolidation" | { "other": string };
|
||||
export type SubAgentSource = "review" | "compact" | { "thread_spawn": { parent_thread_id: ThreadId, parent_turn_id: string | null, depth: number, agent_path: AgentPath | null, agent_nickname: string | null, agent_role: string | null, } } | "memory_consolidation" | { "other": string };
|
||||
|
||||
@@ -132,6 +132,7 @@ mod tests {
|
||||
let review = CoreSessionSource::SubAgent(CoreSubAgentSource::Review);
|
||||
let spawn = CoreSessionSource::SubAgent(CoreSubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -947,6 +947,7 @@ mod thread_processor_behavior_tests {
|
||||
timestamp: timestamp.clone(),
|
||||
source: SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1085,6 +1086,7 @@ mod thread_processor_behavior_tests {
|
||||
let source =
|
||||
serde_json::to_string(&SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: ThreadId::from_string("ad7f0408-99b8-4f6e-a46f-bd0eec433370")?,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -151,6 +151,7 @@ pub(super) fn with_thread_spawn_agent_metadata(
|
||||
codex_protocol::protocol::SessionSource::SubAgent(
|
||||
codex_protocol::protocol::SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path,
|
||||
agent_nickname: existing_agent_nickname,
|
||||
@@ -159,6 +160,7 @@ pub(super) fn with_thread_spawn_agent_metadata(
|
||||
) => codex_protocol::protocol::SessionSource::SubAgent(
|
||||
codex_protocol::protocol::SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path,
|
||||
agent_nickname: agent_nickname.or(existing_agent_nickname),
|
||||
|
||||
@@ -853,6 +853,7 @@ async fn thread_list_filters_by_source_kind_subagent_thread_spawn() -> Result<()
|
||||
/*git_info*/ None,
|
||||
CoreSessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -918,6 +919,7 @@ async fn thread_list_filters_by_subagent_variant() -> Result<()> {
|
||||
/*git_info*/ None,
|
||||
CoreSessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -211,6 +211,7 @@ impl AgentControl {
|
||||
let (session_source, mut agent_metadata) = match session_source {
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path,
|
||||
agent_role,
|
||||
@@ -220,6 +221,7 @@ impl AgentControl {
|
||||
&mut reservation,
|
||||
&config,
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path,
|
||||
agent_role,
|
||||
@@ -300,6 +302,7 @@ impl AgentControl {
|
||||
client_metadata,
|
||||
new_thread.thread_id,
|
||||
/*parent_thread_id*/ None,
|
||||
/*parent_turn_id*/ None,
|
||||
thread_config,
|
||||
subagent_source.clone(),
|
||||
);
|
||||
@@ -494,6 +497,7 @@ impl AgentControl {
|
||||
let child_session_source =
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: child_depth,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -542,6 +546,7 @@ impl AgentControl {
|
||||
let (session_source, agent_metadata) = match session_source {
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path,
|
||||
agent_role: _,
|
||||
@@ -560,6 +565,7 @@ impl AgentControl {
|
||||
&mut reservation,
|
||||
&config,
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path,
|
||||
resumed_agent_role,
|
||||
@@ -1021,6 +1027,7 @@ impl AgentControl {
|
||||
reservation: &mut crate::agent::registry::SpawnReservation,
|
||||
config: &crate::config::Config,
|
||||
parent_thread_id: ThreadId,
|
||||
parent_turn_id: Option<String>,
|
||||
depth: i32,
|
||||
agent_path: Option<AgentPath>,
|
||||
agent_role: Option<String>,
|
||||
@@ -1040,6 +1047,7 @@ impl AgentControl {
|
||||
)?);
|
||||
let session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path: agent_path.clone(),
|
||||
agent_nickname: agent_nickname.clone(),
|
||||
|
||||
@@ -688,6 +688,7 @@ async fn spawn_agent_can_fork_parent_thread_history_with_sanitized_items() {
|
||||
text_input("child task"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -782,6 +783,7 @@ async fn spawn_agent_fork_flushes_parent_rollout_before_loading_history() {
|
||||
text_input("child task"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -892,6 +894,7 @@ async fn spawn_agent_fork_last_n_turns_keeps_only_recent_turns() {
|
||||
text_input("child task"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1181,6 +1184,7 @@ async fn spawn_child_completion_notifies_parent_history() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1217,6 +1221,7 @@ async fn multi_agent_v2_completion_ignores_dead_direct_parent() {
|
||||
text_input("hello worker"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(worker_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1233,6 +1238,7 @@ async fn multi_agent_v2_completion_ignores_dead_direct_parent() {
|
||||
text_input("hello tester"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: worker_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: Some(tester_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1331,6 +1337,7 @@ async fn multi_agent_v2_completion_queues_message_for_direct_parent() {
|
||||
tester_thread_id,
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: worker_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: Some(tester_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1417,6 +1424,7 @@ async fn completion_watcher_notifies_parent_when_child_is_missing() {
|
||||
child_thread_id,
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1460,6 +1468,7 @@ async fn spawn_thread_subagent_gets_random_nickname_in_session_source() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1512,6 +1521,7 @@ async fn spawn_thread_subagent_uses_role_specific_nickname_candidates() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1570,6 +1580,7 @@ async fn resume_thread_subagent_restores_stored_nickname_and_role() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(agent_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1639,6 +1650,7 @@ async fn resume_thread_subagent_restores_stored_nickname_and_role() {
|
||||
child_thread_id,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(agent_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1658,6 +1670,7 @@ async fn resume_thread_subagent_restores_stored_nickname_and_role() {
|
||||
.await;
|
||||
let SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: resumed_parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: resumed_depth,
|
||||
agent_path: resumed_agent_path,
|
||||
agent_nickname: resumed_nickname,
|
||||
@@ -1743,6 +1756,7 @@ async fn list_agent_subtree_thread_ids_includes_anonymous_and_closed_descendants
|
||||
text_input("hello worker"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(worker_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1758,6 +1772,7 @@ async fn list_agent_subtree_thread_ids_includes_anonymous_and_closed_descendants
|
||||
text_input("hello worker child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: worker_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: Some(
|
||||
worker_path
|
||||
@@ -1777,6 +1792,7 @@ async fn list_agent_subtree_thread_ids_includes_anonymous_and_closed_descendants
|
||||
text_input("hello anonymous child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: worker_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1792,6 +1808,7 @@ async fn list_agent_subtree_thread_ids_includes_anonymous_and_closed_descendants
|
||||
text_input("hello anonymous grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: no_path_child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 3,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1807,6 +1824,7 @@ async fn list_agent_subtree_thread_ids_includes_anonymous_and_closed_descendants
|
||||
text_input("hello reviewer"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(reviewer_path),
|
||||
agent_nickname: None,
|
||||
@@ -1867,6 +1885,7 @@ async fn shutdown_agent_tree_closes_live_descendants() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1882,6 +1901,7 @@ async fn shutdown_agent_tree_closes_live_descendants() {
|
||||
text_input("hello grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1952,6 +1972,7 @@ async fn shutdown_agent_tree_closes_descendants_when_started_at_child() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -1967,6 +1988,7 @@ async fn shutdown_agent_tree_closes_descendants_when_started_at_child() {
|
||||
text_input("hello grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2043,6 +2065,7 @@ async fn resume_agent_from_rollout_does_not_reopen_closed_descendants() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2058,6 +2081,7 @@ async fn resume_agent_from_rollout_does_not_reopen_closed_descendants() {
|
||||
text_input("hello grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2138,6 +2162,7 @@ async fn resume_closed_child_reopens_open_descendants() {
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2153,6 +2178,7 @@ async fn resume_closed_child_reopens_open_descendants() {
|
||||
text_input("hello grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2193,6 +2219,7 @@ async fn resume_closed_child_reopens_open_descendants() {
|
||||
child_thread_id,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2235,6 +2262,7 @@ async fn resume_agent_from_rollout_reopens_open_descendants_after_manager_shutdo
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2250,6 +2278,7 @@ async fn resume_agent_from_rollout_reopens_open_descendants_after_manager_shutdo
|
||||
text_input("hello grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2326,6 +2355,7 @@ async fn resume_agent_from_rollout_uses_edge_data_when_descendant_metadata_sourc
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2341,6 +2371,7 @@ async fn resume_agent_from_rollout_uses_edge_data_when_descendant_metadata_sourc
|
||||
text_input("hello grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2379,6 +2410,7 @@ async fn resume_agent_from_rollout_uses_edge_data_when_descendant_metadata_sourc
|
||||
stale_metadata.source =
|
||||
serde_json::to_string(&SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: ThreadId::new(),
|
||||
parent_turn_id: None,
|
||||
depth: 99,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2429,6 +2461,7 @@ async fn resume_agent_from_rollout_uses_edge_data_when_descendant_metadata_sourc
|
||||
.await;
|
||||
let SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: resumed_parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: resumed_depth,
|
||||
..
|
||||
}) = resumed_grandchild_snapshot.session_source
|
||||
@@ -2457,6 +2490,7 @@ async fn resume_agent_from_rollout_skips_descendants_when_parent_resume_fails()
|
||||
text_input("hello child"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2472,6 +2506,7 @@ async fn resume_agent_from_rollout_skips_descendants_when_parent_resume_fails()
|
||||
text_input("hello grandchild"),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: child_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -47,6 +47,7 @@ fn session_depth_defaults_to_zero_for_root_sources() {
|
||||
fn thread_spawn_depth_increments_and_enforces_limit() {
|
||||
let session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: ThreadId::new(),
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -274,6 +274,7 @@ fn build_ws_client_metadata_includes_window_lineage_and_turn_metadata() {
|
||||
let parent_thread_id = ThreadId::new();
|
||||
let client = test_model_client(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -110,6 +110,7 @@ pub(crate) async fn run_codex_thread_interactive(
|
||||
client_metadata,
|
||||
codex.session.conversation_id,
|
||||
Some(parent_session.conversation_id),
|
||||
/*parent_turn_id*/ None,
|
||||
thread_config,
|
||||
subagent_source,
|
||||
);
|
||||
|
||||
@@ -3402,6 +3402,7 @@ pub(crate) fn emit_subagent_session_started(
|
||||
client_metadata: AppServerClientMetadata,
|
||||
thread_id: ThreadId,
|
||||
parent_thread_id: Option<ThreadId>,
|
||||
parent_turn_id: Option<String>,
|
||||
thread_config: ThreadConfigSnapshot,
|
||||
subagent_source: SubAgentSource,
|
||||
) {
|
||||
@@ -3420,6 +3421,7 @@ pub(crate) fn emit_subagent_session_started(
|
||||
analytics_events_client.track_subagent_thread_started(SubAgentThreadStartedInput {
|
||||
thread_id: thread_id.to_string(),
|
||||
parent_thread_id: parent_thread_id.map(|thread_id| thread_id.to_string()),
|
||||
parent_turn_id,
|
||||
product_client_id: client_name.clone(),
|
||||
client_name,
|
||||
client_version,
|
||||
|
||||
@@ -4684,6 +4684,7 @@ async fn resumed_subagent_session_keeps_inherited_session_id() {
|
||||
let thread_id = ThreadId::new();
|
||||
let session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -6809,6 +6810,7 @@ async fn build_initial_context_adds_multi_agent_v2_subagent_usage_hint_as_develo
|
||||
make_multi_agent_v2_usage_hint_test_session(/*enable_multi_agent_v2*/ true).await;
|
||||
let session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: ThreadId::new(),
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(AgentPath::try_from("/root/worker").expect("agent path should parse")),
|
||||
agent_nickname: Some("worker".to_string()),
|
||||
|
||||
@@ -22,7 +22,6 @@ use codex_protocol::protocol::SessionSource;
|
||||
use codex_protocol::protocol::ThreadSource;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
use codex_protocol::protocol::UserMessageEvent;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use core_test_support::PathBufExt;
|
||||
use core_test_support::PathExt;
|
||||
use core_test_support::responses::mount_models_once;
|
||||
@@ -346,7 +345,7 @@ async fn start_thread_rejects_explicit_local_environment_when_default_provider_i
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn start_thread_uses_all_default_environments_from_codex_home() {
|
||||
async fn default_environment_selections_include_all_defaults_from_codex_home() {
|
||||
let temp_dir = tempdir().expect("tempdir");
|
||||
let mut config = test_config().await;
|
||||
config.codex_home = temp_dir.path().join("codex-home").abs();
|
||||
@@ -390,52 +389,19 @@ args = ["dev", "cd /tmp && true"]
|
||||
environment_manager,
|
||||
);
|
||||
|
||||
let thread = manager
|
||||
.start_thread(config)
|
||||
.await
|
||||
.expect("thread should start");
|
||||
|
||||
let prompt_items = crate::prompt_debug::build_prompt_input_from_session(
|
||||
thread.thread.codex.session.as_ref(),
|
||||
Vec::<UserInput>::new(),
|
||||
)
|
||||
.await
|
||||
.expect("prompt input");
|
||||
let environment_context = prompt_items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
ResponseItem::Message { content, .. } => Some(content),
|
||||
_ => None,
|
||||
})
|
||||
.flatten()
|
||||
.find_map(|content| match content {
|
||||
ContentItem::InputText { text } if text.contains("<environment_context>") => {
|
||||
Some(text.as_str())
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.expect("environment context prompt item");
|
||||
assert!(environment_context.contains("<environments>"));
|
||||
let cwd = thread.session_configured.cwd.display().to_string();
|
||||
let dev_entry = format!(
|
||||
r#"<environment id="dev">
|
||||
<cwd>{cwd}</cwd>
|
||||
<shell>"#
|
||||
assert_eq!(
|
||||
manager.default_environment_selections(&config.cwd),
|
||||
vec![
|
||||
TurnEnvironmentSelection {
|
||||
environment_id: "dev".to_string(),
|
||||
cwd: config.cwd.clone(),
|
||||
},
|
||||
TurnEnvironmentSelection {
|
||||
environment_id: "local".to_string(),
|
||||
cwd: config.cwd.clone(),
|
||||
},
|
||||
]
|
||||
);
|
||||
let local_entry = format!(
|
||||
r#"<environment id="local">
|
||||
<cwd>{cwd}</cwd>
|
||||
<shell>"#
|
||||
);
|
||||
let dev_position = environment_context
|
||||
.find(&dev_entry)
|
||||
.expect("dev environment entry");
|
||||
let local_position = environment_context
|
||||
.find(&local_entry)
|
||||
.expect("local environment entry");
|
||||
assert!(dev_position < local_position);
|
||||
assert!(!environment_context.contains("\n <cwd>"));
|
||||
assert!(!environment_context.contains("\n <shell>"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -180,6 +180,7 @@ async fn try_resume_closed_agent(
|
||||
receiver_thread_id,
|
||||
thread_spawn_source(
|
||||
session.conversation_id,
|
||||
/*parent_turn_id*/ None,
|
||||
&turn.session_source,
|
||||
child_depth,
|
||||
/*agent_role*/ None,
|
||||
|
||||
@@ -113,6 +113,7 @@ async fn handle_spawn_agent(
|
||||
input_items,
|
||||
Some(thread_spawn_source(
|
||||
session.conversation_id,
|
||||
Some(turn.sub_id.clone()),
|
||||
&turn.session_source,
|
||||
child_depth,
|
||||
role_name,
|
||||
|
||||
@@ -137,6 +137,7 @@ pub(crate) fn collab_agent_error(agent_id: ThreadId, err: CodexErr) -> FunctionC
|
||||
|
||||
pub(crate) fn thread_spawn_source(
|
||||
parent_thread_id: ThreadId,
|
||||
parent_turn_id: Option<String>,
|
||||
parent_session_source: &SessionSource,
|
||||
depth: i32,
|
||||
agent_role: Option<&str>,
|
||||
@@ -154,6 +155,7 @@ pub(crate) fn thread_spawn_source(
|
||||
.transpose()?;
|
||||
Ok(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id,
|
||||
depth,
|
||||
agent_path,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -260,6 +260,7 @@ async fn spawn_agent_uses_explorer_role_and_preserves_approval_policy() {
|
||||
.expect("approval policy should be set");
|
||||
turn.provider = create_model_provider(provider_info, turn.auth_manager.clone());
|
||||
turn.config = Arc::new(config);
|
||||
let parent_turn_id = turn.sub_id.clone();
|
||||
|
||||
let invocation = invocation(
|
||||
Arc::new(session),
|
||||
@@ -292,6 +293,14 @@ async fn spawn_agent_uses_explorer_role_and_preserves_approval_policy() {
|
||||
.await;
|
||||
assert_eq!(snapshot.approval_policy, AskForApproval::OnRequest);
|
||||
assert_eq!(snapshot.model_provider_id, "ollama");
|
||||
let SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_turn_id: actual_parent_turn_id,
|
||||
..
|
||||
}) = snapshot.session_source
|
||||
else {
|
||||
panic!("spawned agent should have a thread-spawn source");
|
||||
};
|
||||
assert_eq!(actual_parent_turn_id, Some(parent_turn_id));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -1012,6 +1021,7 @@ async fn multi_agent_v2_spawn_returns_path_and_send_message_accepts_relative_pat
|
||||
.enable(Feature::MultiAgentV2)
|
||||
.expect("test config should allow feature update");
|
||||
turn.config = Arc::new(config);
|
||||
let parent_turn_id = turn.sub_id.clone();
|
||||
|
||||
let session = Arc::new(session);
|
||||
let turn = Arc::new(turn);
|
||||
@@ -1053,6 +1063,14 @@ async fn multi_agent_v2_spawn_returns_path_and_send_message_accepts_relative_pat
|
||||
child_snapshot.session_source.get_agent_path().as_deref(),
|
||||
Some("/root/test_process")
|
||||
);
|
||||
let SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_turn_id: actual_parent_turn_id,
|
||||
..
|
||||
}) = child_snapshot.session_source
|
||||
else {
|
||||
panic!("spawned agent should have a thread-spawn source");
|
||||
};
|
||||
assert_eq!(actual_parent_turn_id, Some(parent_turn_id));
|
||||
assert!(manager.captured_ops().iter().any(|(id, op)| {
|
||||
*id == child_thread_id
|
||||
&& matches!(
|
||||
@@ -1243,6 +1261,7 @@ async fn multi_agent_v2_send_message_accepts_root_target_from_child() {
|
||||
.into(),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(child_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1256,6 +1275,7 @@ async fn multi_agent_v2_send_message_accepts_root_target_from_child() {
|
||||
session.conversation_id = child_thread_id;
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(child_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1319,6 +1339,7 @@ async fn multi_agent_v2_followup_task_rejects_root_target_from_child() {
|
||||
.into(),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(child_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1332,6 +1353,7 @@ async fn multi_agent_v2_followup_task_rejects_root_target_from_child() {
|
||||
session.conversation_id = child_thread_id;
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(child_path),
|
||||
agent_nickname: None,
|
||||
@@ -1492,6 +1514,7 @@ async fn multi_agent_v2_list_agents_filters_by_relative_path_prefix() {
|
||||
.into(),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(researcher_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1513,6 +1536,7 @@ async fn multi_agent_v2_list_agents_filters_by_relative_path_prefix() {
|
||||
.into(),
|
||||
Some(SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 2,
|
||||
agent_path: Some(worker_path.clone()),
|
||||
agent_nickname: None,
|
||||
@@ -1525,6 +1549,7 @@ async fn multi_agent_v2_list_agents_filters_by_relative_path_prefix() {
|
||||
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(researcher_path),
|
||||
agent_nickname: None,
|
||||
@@ -2182,6 +2207,7 @@ async fn spawn_agent_rejects_when_depth_limit_exceeded() {
|
||||
let max_depth = turn.config.agent_max_depth;
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: session.conversation_id,
|
||||
parent_turn_id: None,
|
||||
depth: max_depth,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2222,6 +2248,7 @@ async fn spawn_agent_allows_depth_up_to_configured_max_depth() {
|
||||
turn.config = Arc::new(config);
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: session.conversation_id,
|
||||
parent_turn_id: None,
|
||||
depth: DEFAULT_AGENT_MAX_DEPTH,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
@@ -2277,6 +2304,7 @@ async fn multi_agent_v2_spawn_agent_ignores_configured_max_depth() {
|
||||
let parent_path = AgentPath::try_from("/root/parent").expect("agent path");
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root.thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(parent_path),
|
||||
agent_nickname: None,
|
||||
@@ -2650,6 +2678,7 @@ async fn resume_agent_rejects_when_depth_limit_exceeded() {
|
||||
let max_depth = turn.config.agent_max_depth;
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: session.conversation_id,
|
||||
parent_turn_id: None,
|
||||
depth: max_depth,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -38,7 +38,9 @@ impl ToolExecutor<ToolInvocation> for Handler {
|
||||
&self,
|
||||
invocation: ToolInvocation,
|
||||
) -> Result<Box<dyn crate::tools::context::ToolOutput>, FunctionCallError> {
|
||||
handle_spawn_agent(invocation).await.map(boxed_tool_output)
|
||||
Box::pin(handle_spawn_agent(invocation))
|
||||
.await
|
||||
.map(boxed_tool_output)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +111,7 @@ async fn handle_spawn_agent(
|
||||
|
||||
let spawn_source = thread_spawn_source(
|
||||
session.conversation_id,
|
||||
Some(turn.sub_id.clone()),
|
||||
&turn.session_source,
|
||||
child_depth,
|
||||
role_name,
|
||||
|
||||
@@ -16,6 +16,7 @@ async fn multi_agent_v2_request_user_input_rejects_subagent_threads() {
|
||||
let (session, mut turn) = make_session_and_context().await;
|
||||
turn.session_source = SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: ThreadId::new(),
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
|
||||
@@ -242,9 +242,22 @@ fn build_code_mode_executors(
|
||||
executor.spec()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let namespace_descriptions = code_mode_namespace_descriptions(&code_mode_nested_tool_specs);
|
||||
let code_mode_prompt_tool_specs = executors
|
||||
.iter()
|
||||
.filter_map(|executor| {
|
||||
if matches!(
|
||||
executor.exposure(),
|
||||
ToolExposure::DirectModelOnly | ToolExposure::Deferred
|
||||
) {
|
||||
return None;
|
||||
}
|
||||
|
||||
executor.spec()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let namespace_descriptions = code_mode_namespace_descriptions(&code_mode_prompt_tool_specs);
|
||||
let mut enabled_tools =
|
||||
collect_code_mode_exec_prompt_tool_definitions(code_mode_nested_tool_specs.iter());
|
||||
collect_code_mode_exec_prompt_tool_definitions(code_mode_prompt_tool_specs.iter());
|
||||
enabled_tools
|
||||
.sort_by(|left, right| compare_code_mode_tools(left, right, &namespace_descriptions));
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ const BACKOFF_FACTOR: f64 = 2.0;
|
||||
///
|
||||
/// ```rust
|
||||
/// codex_core::feedback_tags!(model = "gpt-5", cached = true);
|
||||
/// let provider_id = "openai";
|
||||
/// let request_id = "req_123";
|
||||
/// codex_core::feedback_tags!(provider = provider_id, request_id = request_id);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
|
||||
@@ -476,6 +476,7 @@ async fn thread_lifecycle_params_include_legacy_sandbox_when_no_active_profile()
|
||||
let cwd = tempdir().expect("create temp cwd");
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.path().to_path_buf())
|
||||
.loader_overrides(LoaderOverrides::without_managed_config_for_tests())
|
||||
.harness_overrides(ConfigOverrides {
|
||||
sandbox_mode: Some(SandboxMode::DangerFullAccess),
|
||||
..Default::default()
|
||||
|
||||
@@ -81,7 +81,7 @@ async fn test_apply_patch_tool() -> anyhow::Result<()> {
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-s")
|
||||
.arg("danger-full-access")
|
||||
.arg("workspace-write")
|
||||
.arg("foo")
|
||||
.assert()
|
||||
.success();
|
||||
@@ -132,7 +132,7 @@ async fn test_apply_patch_freeform_tool() -> anyhow::Result<()> {
|
||||
test.cmd_with_server(&server)
|
||||
.arg("--skip-git-repo-check")
|
||||
.arg("-s")
|
||||
.arg("danger-full-access")
|
||||
.arg("workspace-write")
|
||||
.arg("foo")
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
@@ -2573,6 +2573,8 @@ pub enum SubAgentSource {
|
||||
Compact,
|
||||
ThreadSpawn {
|
||||
parent_thread_id: ThreadId,
|
||||
#[serde(default)]
|
||||
parent_turn_id: Option<String>,
|
||||
depth: i32,
|
||||
#[serde(default)]
|
||||
agent_path: Option<AgentPath>,
|
||||
@@ -3980,6 +3982,37 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_spawn_session_source_deserializes_without_parent_turn_id() {
|
||||
let parent_thread_id =
|
||||
ThreadId::from_string("11111111-1111-1111-1111-111111111111").expect("valid thread id");
|
||||
|
||||
let source: SessionSource = serde_json::from_value(serde_json::json!({
|
||||
"subagent": {
|
||||
"thread_spawn": {
|
||||
"parent_thread_id": parent_thread_id.to_string(),
|
||||
"depth": 1,
|
||||
"agent_path": null,
|
||||
"agent_nickname": null,
|
||||
"agent_role": null
|
||||
}
|
||||
}
|
||||
}))
|
||||
.expect("thread spawn source should deserialize without parent_turn_id");
|
||||
|
||||
assert_eq!(
|
||||
source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: None,
|
||||
agent_nickname: None,
|
||||
agent_role: None,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inter_agent_communication_response_input_item_preserves_commentary_phase() {
|
||||
let communication = InterAgentCommunication {
|
||||
|
||||
@@ -73,6 +73,7 @@ fn spawned_thread_start_appends_to_root_bundle() -> anyhow::Result<()> {
|
||||
agent_role: Some("worker".to_string()),
|
||||
session_source: SessionSource::SubAgent(SubAgentSource::ThreadSpawn {
|
||||
parent_thread_id: root_thread_id,
|
||||
parent_turn_id: None,
|
||||
depth: 1,
|
||||
agent_path: Some(
|
||||
AgentPath::try_from("/root/repo_file_counter").map_err(anyhow::Error::msg)?,
|
||||
|
||||
Reference in New Issue
Block a user