Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Keep agent registry identities consistent (#35744)

Tamir Dubersteine597169e9a78
diff --git a/codex-rs/core/src/agent/control_tests.rs b/codex-rs/core/src/agent/control_tests.rs
index 1e5cf0a87f..ab732ec3c2 100644
--- a/codex-rs/core/src/agent/control_tests.rs
+++ b/codex-rs/core/src/agent/control_tests.rs
@@ -783,6 +783,9 @@ async fn resume_agent_from_rollout_does_not_reopen_v2_descendants() {
)
.await
.expect("reviewer spawn should succeed");
+ let sibling_thread_id = harness
+ .spawn_anonymous_child(parent_thread_id, SpawnAgentOptions::default())
+ .await;
let worker_thread = harness
.manager
@@ -794,11 +797,21 @@ async fn resume_agent_from_rollout_does_not_reopen_v2_descendants() {
.get_thread(reviewer_thread_id)
.await
.expect("reviewer thread should exist");
+ let sibling_thread = harness
+ .manager
+ .get_thread(sibling_thread_id)
+ .await
+ .expect("sibling thread should exist");
persist_thread_for_tree_resume(&parent_thread, "parent persisted").await;
persist_thread_for_tree_resume(&worker_thread, "worker persisted").await;
persist_thread_for_tree_resume(&reviewer_thread, "reviewer persisted").await;
- wait_for_live_thread_spawn_children(&harness.control, parent_thread_id, &[worker_thread_id])
- .await;
+ persist_thread_for_tree_resume(&sibling_thread, "sibling persisted").await;
+ wait_for_live_thread_spawn_children(
+ &harness.control,
+ parent_thread_id,
+ &[worker_thread_id, sibling_thread_id],
+ )
+ .await;
wait_for_live_thread_spawn_children(&harness.control, worker_thread_id, &[reviewer_thread_id])
.await;
@@ -832,6 +845,24 @@ async fn resume_agent_from_rollout_does_not_reopen_v2_descendants() {
);
assert_thread_not_loaded(&resumed_manager, worker_thread_id).await;
assert_thread_not_loaded(&resumed_manager, reviewer_thread_id).await;
+ assert_thread_not_loaded(&resumed_manager, sibling_thread_id).await;
+ resumed_control
+ .restore_v2_agent_metadata(&harness.config, parent_thread_id)
+ .await;
+ for thread_id in [worker_thread_id, sibling_thread_id] {
+ assert!(resumed_control.ensure_agent_known(thread_id).is_ok());
+ }
+
+ resumed_control
+ .close_agent(worker_thread_id)
+ .await
+ .expect("closing a restored sibling should succeed");
+
+ let closed_worker = resumed_control.ensure_agent_known(worker_thread_id);
+ let surviving_sibling = resumed_control.ensure_agent_known(sibling_thread_id);
+ assert!(closed_worker.is_err());
+ assert!(surviving_sibling.is_ok());
+ assert_thread_not_loaded(&resumed_manager, sibling_thread_id).await;
}
#[tokio::test]
diff --git a/codex-rs/core/src/agent/registry.rs b/codex-rs/core/src/agent/registry.rs
index 36b8cdf862..e1ceccae1f 100644
--- a/codex-rs/core/src/agent/registry.rs
+++ b/codex-rs/core/src/agent/registry.rs
@@ -29,6 +29,7 @@ pub(crate) struct AgentRegistry {
#[derive(Default)]
struct ActiveAgents {
agent_tree: HashMap<String, AgentMetadata>,
+ thread_paths: HashMap<ThreadId, String>,
used_agent_nicknames: HashSet<String>,
nickname_reset_count: usize,
}
@@ -104,12 +105,9 @@ impl AgentRegistry {
.active_agents
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
- let removed_key = active_agents
- .agent_tree
- .iter()
- .find_map(|(key, metadata)| (metadata.agent_id == Some(thread_id)).then_some(key))
- .cloned();
- removed_key
+ active_agents
+ .thread_paths
+ .remove(&thread_id)
.and_then(|key| active_agents.agent_tree.remove(key.as_str()))
.is_some_and(|metadata| {
!metadata.agent_path.as_ref().is_some_and(AgentPath::is_root)
@@ -125,14 +123,19 @@ impl AgentRegistry {
.active_agents
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
- active_agents
+ let root_path = AgentPath::ROOT.to_string();
+ let root_thread_id = active_agents
.agent_tree
- .entry(AgentPath::ROOT.to_string())
+ .entry(root_path.clone())
.or_insert_with(|| AgentMetadata {
agent_id: Some(thread_id),
agent_path: Some(AgentPath::root()),
..Default::default()
- });
+ })
+ .agent_id;
+ if let Some(root_thread_id) = root_thread_id {
+ active_agents.thread_paths.insert(root_thread_id, root_path);
+ }
}
pub(crate) fn agent_id_for_path(&self, agent_path: &AgentPath) -> Option<ThreadId> {
@@ -145,12 +148,14 @@ impl AgentRegistry {
}
pub(crate) fn agent_metadata_for_thread(&self, thread_id: ThreadId) -> Option<AgentMetadata> {
- self.active_agents
+ let active_agents = self
+ .active_agents
.lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .agent_tree
- .values()
- .find(|metadata| metadata.agent_id == Some(thread_id))
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ active_agents
+ .thread_paths
+ .get(&thread_id)
+ .and_then(|path| active_agents.agent_tree.get(path))
.cloned()
}
@@ -184,7 +189,17 @@ impl AgentRegistry {
if let Some(agent_nickname) = agent_metadata.agent_nickname.clone() {
active_agents.used_agent_nicknames.insert(agent_nickname);
}
- active_agents.agent_tree.insert(key, agent_metadata);
+ if let Some(previous_key) = active_agents.thread_paths.insert(thread_id, key.clone())
+ && previous_key != key
+ {
+ active_agents.agent_tree.remove(previous_key.as_str());
+ }
+ if let Some(previous_metadata) = active_agents.agent_tree.insert(key, agent_metadata)
+ && let Some(previous_thread_id) = previous_metadata.agent_id
+ && previous_thread_id != thread_id
+ {
+ active_agents.thread_paths.remove(&previous_thread_id);
+ }
}
fn reserve_agent_nickname(&self, names: &[&str], preferred: Option<&str>) -> Option<String> {
diff --git a/codex-rs/core/src/agent/registry_tests.rs b/codex-rs/core/src/agent/registry_tests.rs
index 160489d2d1..24d204ee56 100644
--- a/codex-rs/core/src/agent/registry_tests.rs
+++ b/codex-rs/core/src/agent/registry_tests.rs
@@ -88,6 +88,13 @@ fn commit_holds_slot_until_release() {
let thread_id = ThreadId::new();
reservation.commit(agent_metadata(thread_id));
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(thread_id)
+ .and_then(|metadata| metadata.agent_id),
+ Some(thread_id)
+ );
+
let err = match registry.reserve_spawn_slot(Some(1)) {
Ok(_) => panic!("limit should be enforced"),
Err(err) => err,
@@ -98,12 +105,37 @@ fn commit_holds_slot_until_release() {
assert_eq!(*max_threads, 1);
registry.release_spawned_thread(thread_id);
+ assert!(registry.agent_metadata_for_thread(thread_id).is_none());
let reservation = registry
.reserve_spawn_slot(Some(1))
.expect("slot released after thread removal");
drop(reservation);
}
+#[test]
+fn releasing_one_spawned_thread_preserves_sibling_identity() {
+ let registry = Arc::new(AgentRegistry::default());
+ let first_id = ThreadId::new();
+ let second_id = ThreadId::new();
+
+ for thread_id in [first_id, second_id] {
+ registry
+ .reserve_spawn_slot(/*max_threads*/ None)
+ .expect("reserve sibling slot")
+ .commit(agent_metadata(thread_id));
+ }
+
+ registry.release_spawned_thread(first_id);
+
+ assert!(registry.agent_metadata_for_thread(first_id).is_none());
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(second_id)
+ .and_then(|metadata| metadata.agent_id),
+ Some(second_id)
+ );
+}
+
#[test]
fn release_ignores_unknown_thread_id() {
let registry = Arc::new(AgentRegistry::default());
@@ -301,6 +333,40 @@ fn register_root_thread_indexes_root_path() {
registry.agent_id_for_path(&AgentPath::root()),
Some(root_thread_id)
);
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(root_thread_id)
+ .and_then(|metadata| metadata.agent_path),
+ Some(AgentPath::root())
+ );
+
+ let other_thread_id = ThreadId::new();
+ registry.register_root_thread(other_thread_id);
+
+ assert_eq!(
+ registry.agent_id_for_path(&AgentPath::root()),
+ Some(root_thread_id)
+ );
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(root_thread_id)
+ .and_then(|metadata| metadata.agent_path),
+ Some(AgentPath::root())
+ );
+ assert!(
+ registry
+ .agent_metadata_for_thread(other_thread_id)
+ .is_none()
+ );
+
+ registry.release_spawned_thread(root_thread_id);
+ assert_eq!(registry.agent_id_for_path(&AgentPath::root()), None);
+ assert!(registry.agent_metadata_for_thread(root_thread_id).is_none());
+
+ let reservation = registry
+ .reserve_spawn_slot(Some(1))
+ .expect("releasing the uncounted root should not consume a spawn slot");
+ drop(reservation);
}
#[test]
@@ -342,10 +408,166 @@ fn committed_agent_path_is_indexed_until_release() {
registry.agent_id_for_path(&agent_path("/root/researcher")),
Some(thread_id)
);
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(thread_id)
+ .and_then(|metadata| metadata.agent_path),
+ Some(agent_path("/root/researcher"))
+ );
registry.release_spawned_thread(thread_id);
assert_eq!(
registry.agent_id_for_path(&agent_path("/root/researcher")),
None
);
+ assert!(registry.agent_metadata_for_thread(thread_id).is_none());
+}
+
+#[test]
+fn replacing_agent_metadata_updates_thread_identity_index() {
+ let registry = AgentRegistry::default();
+ let previous_thread_id = ThreadId::new();
+ let current_thread_id = ThreadId::new();
+ let path = agent_path("/root/researcher");
+
+ registry.register_spawned_thread(AgentMetadata {
+ agent_id: Some(previous_thread_id),
+ agent_path: Some(path.clone()),
+ ..Default::default()
+ });
+ registry.register_spawned_thread(AgentMetadata {
+ agent_id: Some(current_thread_id),
+ agent_path: Some(path.clone()),
+ ..Default::default()
+ });
+ registry.register_spawned_thread(AgentMetadata {
+ agent_id: Some(current_thread_id),
+ agent_path: Some(path.clone()),
+ agent_role: Some("researcher".to_string()),
+ ..Default::default()
+ });
+
+ assert!(
+ registry
+ .agent_metadata_for_thread(previous_thread_id)
+ .is_none()
+ );
+ assert_eq!(registry.agent_id_for_path(&path), Some(current_thread_id));
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(current_thread_id)
+ .map(|metadata| (metadata.agent_path, metadata.agent_role)),
+ Some((Some(path), Some("researcher".to_string())))
+ );
+
+ registry.release_spawned_thread(previous_thread_id);
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(current_thread_id)
+ .and_then(|metadata| metadata.agent_id),
+ Some(current_thread_id)
+ );
+}
+
+#[test]
+fn thread_identity_can_move_between_pathless_and_path_backed_metadata() {
+ let registry = Arc::new(AgentRegistry::default());
+ let thread_id = ThreadId::new();
+ let path = agent_path("/root/researcher");
+ let reservation = registry.reserve_spawn_slot(Some(1)).expect("reserve slot");
+ reservation.commit(agent_metadata(thread_id));
+
+ registry.register_spawned_thread(AgentMetadata {
+ agent_id: Some(thread_id),
+ agent_path: Some(path.clone()),
+ ..Default::default()
+ });
+
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(thread_id)
+ .map(|metadata| (metadata.agent_id, metadata.agent_path)),
+ Some((Some(thread_id), Some(path.clone())))
+ );
+ assert_eq!(registry.agent_id_for_path(&path), Some(thread_id));
+
+ registry.register_spawned_thread(agent_metadata(thread_id));
+
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(thread_id)
+ .map(|metadata| (metadata.agent_id, metadata.agent_path)),
+ Some((Some(thread_id), None))
+ );
+ assert_eq!(registry.agent_id_for_path(&path), None);
+
+ let mut path_reservation = registry
+ .reserve_spawn_slot(/*max_threads*/ None)
+ .expect("reserve path reuse slot");
+ path_reservation
+ .reserve_agent_path(&path)
+ .expect("moving back to pathless metadata should release the old path");
+ drop(path_reservation);
+
+ registry.release_spawned_thread(thread_id);
+ assert!(registry.agent_metadata_for_thread(thread_id).is_none());
+
+ let reservation = registry
+ .reserve_spawn_slot(Some(1))
+ .expect("releasing the migrated agent should free its spawn slot");
+ drop(reservation);
+}
+
+#[test]
+fn thread_identity_can_move_between_agent_paths() {
+ let registry = Arc::new(AgentRegistry::default());
+ let thread_id = ThreadId::new();
+ let previous_path = agent_path("/root/researcher");
+ let current_path = agent_path("/root/reviewer");
+ let mut reservation = registry.reserve_spawn_slot(Some(1)).expect("reserve slot");
+ reservation
+ .reserve_agent_path(&previous_path)
+ .expect("reserve original path");
+ reservation.commit(AgentMetadata {
+ agent_id: Some(thread_id),
+ agent_path: Some(previous_path.clone()),
+ ..Default::default()
+ });
+
+ registry.register_spawned_thread(AgentMetadata {
+ agent_id: Some(thread_id),
+ agent_path: Some(current_path.clone()),
+ agent_role: Some("reviewer".to_string()),
+ ..Default::default()
+ });
+
+ assert_eq!(
+ registry
+ .agent_metadata_for_thread(thread_id)
+ .map(|metadata| (metadata.agent_id, metadata.agent_path, metadata.agent_role)),
+ Some((
+ Some(thread_id),
+ Some(current_path.clone()),
+ Some("reviewer".to_string())
+ ))
+ );
+ assert_eq!(registry.agent_id_for_path(&previous_path), None);
+ assert_eq!(registry.agent_id_for_path(&current_path), Some(thread_id));
+
+ let mut path_reservation = registry
+ .reserve_spawn_slot(/*max_threads*/ None)
+ .expect("reserve path reuse slot");
+ path_reservation
+ .reserve_agent_path(&previous_path)
+ .expect("moving to a different path should release the old path");
+ drop(path_reservation);
+
+ registry.release_spawned_thread(thread_id);
+ assert_eq!(registry.agent_id_for_path(&current_path), None);
+ assert!(registry.agent_metadata_for_thread(thread_id).is_none());
+
+ let reservation = registry
+ .reserve_spawn_slot(Some(1))
+ .expect("releasing the migrated agent should free its spawn slot");
+ drop(reservation);
}
diff --git a/codex-rs/core/tests/suite/multi_agent_resume.rs b/codex-rs/core/tests/suite/multi_agent_resume.rs
index c2bd591a18..703c1bddd3 100644
--- a/codex-rs/core/tests/suite/multi_agent_resume.rs
+++ b/codex-rs/core/tests/suite/multi_agent_resume.rs
@@ -4,6 +4,7 @@ use codex_features::Feature;
use codex_protocol::models::PermissionProfile;
use codex_protocol::openai_models::ReasoningEffort;
use codex_protocol::protocol::AgentStatus;
+use codex_protocol::protocol::EventMsg;
use core_test_support::responses::ev_assistant_message;
use core_test_support::responses::ev_completed;
use core_test_support::responses::ev_function_call_with_namespace;
@@ -12,6 +13,7 @@ use core_test_support::responses::mount_sse_once_match;
use core_test_support::responses::sse;
use core_test_support::responses::start_mock_server;
use core_test_support::test_codex::test_codex;
+use core_test_support::wait_for_event;
use pretty_assertions::assert_eq;
use serde_json::Value;
use serde_json::json;
@@ -22,10 +24,19 @@ use tokio::time::sleep;
const COLLABORATION_NAMESPACE: &str = "collaboration";
const SPAWN_CALL_ID: &str = "spawn-worker";
const FOLLOWUP_CALL_ID: &str = "followup-worker";
+const SIBLING_SPAWN_CALL_ID: &str = "spawn-survivor";
+const SIBLING_FOLLOWUP_CALL_ID: &str = "followup-survivor";
+const INTERRUPT_CALL_ID: &str = "interrupt-worker";
const INITIAL_PROMPT: &str = "spawn a durable worker";
const INITIAL_TASK: &str = "inspect the repository";
const FOLLOWUP_PROMPT: &str = "continue the durable worker";
const FOLLOWUP_TASK: &str = "inspect the tests too";
+const SIBLING_PROMPT: &str = "spawn a second durable worker";
+const SIBLING_TASK: &str = "inspect the release lifecycle";
+const SIBLING_FOLLOWUP_PROMPT: &str = "continue the surviving worker";
+const SIBLING_FOLLOWUP_TASK: &str = "verify the surviving worker";
+const INTERRUPT_PROMPT: &str = "release the interrupted worker";
+const SIBLING_NAME: &str = "survivor";
const ROLE_NAME: &str = "durable_worker";
const ROLE_MODEL: &str = "gpt-5.4";
const ROLE_MODEL_PROVIDER_ID: &str = "mock";
@@ -55,6 +66,12 @@ fn body_contains(request: &wiremock::Request, text: &str) -> bool {
.is_some_and(|body| body.contains(text))
}
+fn request_has_model(request: &wiremock::Request, model: &str) -> bool {
+ decoded_body(request)
+ .and_then(|body| serde_json::from_slice::<Value>(&body).ok())
+ .is_some_and(|body| body.get("model").and_then(Value::as_str) == Some(model))
+}
+
fn request_has_input_type(request: &wiremock::Request, input_type: &str) -> bool {
decoded_body(request)
.and_then(|body| serde_json::from_slice::<Value>(&body).ok())
@@ -66,6 +83,43 @@ fn request_has_input_type(request: &wiremock::Request, input_type: &str) -> bool
})
}
+async fn mount_root_collaboration_call(
+ server: &wiremock::MockServer,
+ prompt: &'static str,
+ call_id: &'static str,
+ tool_name: &'static str,
+ arguments: &str,
+) {
+ let first_response_id = format!("resp-{call_id}-1");
+ mount_sse_once_match(
+ server,
+ move |request: &wiremock::Request| {
+ body_contains(request, prompt) && !request_has_model(request, ROLE_MODEL)
+ },
+ sse(vec![
+ ev_response_created(&first_response_id),
+ ev_function_call_with_namespace(call_id, COLLABORATION_NAMESPACE, tool_name, arguments),
+ ev_completed(&first_response_id),
+ ]),
+ )
+ .await;
+
+ let second_response_id = format!("resp-{call_id}-2");
+ let message_id = format!("msg-{call_id}-2");
+ mount_sse_once_match(
+ server,
+ move |request: &wiremock::Request| {
+ body_contains(request, call_id) && !request_has_model(request, ROLE_MODEL)
+ },
+ sse(vec![
+ ev_response_created(&second_response_id),
+ ev_assistant_message(&message_id, "collaboration completed"),
+ ev_completed(&second_response_id),
+ ]),
+ )
+ .await;
+}
+
fn configure_multi_agent_v2_with_role(
config: &mut codex_core::config::Config,
model_provider_base_url: &str,
@@ -125,7 +179,9 @@ async fn cold_root_resume_restores_agent_identity_and_role_on_followup() -> Resu
let initial_child_request = mount_sse_once_match(
&server,
|request: &wiremock::Request| {
- request_has_input_type(request, "agent_message") && body_contains(request, INITIAL_TASK)
+ request_has_model(request, ROLE_MODEL)
+ && request_has_input_type(request, "agent_message")
+ && body_contains(request, INITIAL_TASK)
},
sse(vec![
ev_response_created("resp-worker-1"),
@@ -137,8 +193,7 @@ async fn cold_root_resume_restores_agent_identity_and_role_on_followup() -> Resu
mount_sse_once_match(
&server,
|request: &wiremock::Request| {
- body_contains(request, SPAWN_CALL_ID)
- && !request_has_input_type(request, "agent_message")
+ body_contains(request, SPAWN_CALL_ID) && !request_has_model(request, ROLE_MODEL)
},
sse(vec![
ev_response_created("resp-spawn-2"),
@@ -213,8 +268,53 @@ async fn cold_root_resume_restores_agent_identity_and_role_on_followup() -> Resu
PermissionProfile::Disabled,
)
);
+
+ let sibling_spawn_args = serde_json::to_string(&json!({
+ "message": SIBLING_TASK,
+ "task_name": SIBLING_NAME,
+ "agent_type": ROLE_NAME,
+ "fork_turns": "none",
+ }))?;
+ mount_root_collaboration_call(
+ &server,
+ SIBLING_PROMPT,
+ SIBLING_SPAWN_CALL_ID,
+ "spawn_agent",
+ &sibling_spawn_args,
+ )
+ .await;
+ mount_sse_once_match(
+ &server,
+ |request: &wiremock::Request| {
+ request_has_model(request, ROLE_MODEL)
+ && request_has_input_type(request, "agent_message")
+ && body_contains(request, SIBLING_TASK)
+ },
+ sse(vec![
+ ev_response_created("resp-survivor-1"),
+ ev_assistant_message("msg-survivor-1", "initial survivor task complete"),
+ ev_completed("resp-survivor-1"),
+ ]),
+ )
+ .await;
+ initial.submit_turn(SIBLING_PROMPT).await?;
+
+ let sibling_thread_id = initial
+ .thread_manager
+ .list_thread_ids()
+ .await
+ .into_iter()
+ .find(|thread_id| *thread_id != root_thread_id && *thread_id != worker_thread_id)
+ .ok_or_else(|| anyhow::anyhow!("spawned sibling should be registered"))?;
+ let sibling_thread = initial.thread_manager.get_thread(sibling_thread_id).await?;
+ wait_for_event(sibling_thread.as_ref(), |event| {
+ matches!(event, EventMsg::TurnComplete(_))
+ })
+ .await;
+ sibling_thread.flush_rollout().await?;
worker_thread.flush_rollout().await?;
initial.codex.flush_rollout().await?;
+ drop(sibling_thread);
drop(worker_thread);
drop(initial);
@@ -240,7 +340,8 @@ async fn cold_root_resume_restores_agent_identity_and_role_on_followup() -> Resu
let followup_child_request = mount_sse_once_match(
&server,
|request: &wiremock::Request| {
- request_has_input_type(request, "agent_message")
+ request_has_model(request, ROLE_MODEL)
+ && request_has_input_type(request, "agent_message")
&& body_contains(request, FOLLOWUP_TASK)
},
sse(vec![
@@ -253,8 +354,7 @@ async fn cold_root_resume_restores_agent_identity_and_role_on_followup() -> Resu
mount_sse_once_match(
&server,
|request: &wiremock::Request| {
- body_contains(request, FOLLOWUP_CALL_ID)
- && !request_has_input_type(request, "agent_message")
+ body_contains(request, FOLLOWUP_CALL_ID) && !request_has_model(request, ROLE_MODEL)
},
sse(vec![
ev_response_created("resp-followup-2"),
@@ -280,6 +380,13 @@ async fn cold_root_resume_restores_agent_identity_and_role_on_followup() -> Resu
.await
.is_err()
);
+ assert!(
+ resumed
+ .thread_manager
+ .get_thread(sibling_thread_id)
+ .await
+ .is_err()
+ );
resumed.submit_turn(FOLLOWUP_PROMPT).await?;
@@ -315,5 +422,76 @@ async fn cold_root_resume_restores_agent_identity_and_role_on_followup() -> Resu
);
assert_eq!(reloaded_worker_role_config, initial_worker_role_config);
+ reloaded_worker.shutdown_and_wait().await?;
+ assert!(
+ resumed
+ .thread_manager
+ .get_thread(worker_thread_id)
+ .await
+ .is_ok()
+ );
+
+ let interrupt_args = serde_json::to_string(&json!({
+ "target": "worker",
+ }))?;
+ mount_root_collaboration_call(
+ &server,
+ INTERRUPT_PROMPT,
+ INTERRUPT_CALL_ID,
+ "interrupt_agent",
+ &interrupt_args,
+ )
+ .await;
+ resumed.submit_turn(INTERRUPT_PROMPT).await?;
+ assert!(
+ resumed
+ .thread_manager
+ .get_thread(worker_thread_id)
+ .await
+ .is_err()
+ );
+
+ let sibling_followup_args = serde_json::to_string(&json!({
+ "target": SIBLING_NAME,
+ "message": SIBLING_FOLLOWUP_TASK,
+ }))?;
+ mount_root_collaboration_call(
+ &server,
+ SIBLING_FOLLOWUP_PROMPT,
+ SIBLING_FOLLOWUP_CALL_ID,
+ "followup_task",
+ &sibling_followup_args,
+ )
+ .await;
+ let sibling_followup_request = mount_sse_once_match(
+ &server,
+ |request: &wiremock::Request| {
+ request_has_model(request, ROLE_MODEL)
+ && request_has_input_type(request, "agent_message")
+ && body_contains(request, SIBLING_FOLLOWUP_TASK)
+ },
+ sse(vec![
+ ev_response_created("resp-survivor-2"),
+ ev_assistant_message("msg-survivor-2", "survivor follow-up complete"),
+ ev_completed("resp-survivor-2"),
+ ]),
+ )
+ .await;
+ resumed.submit_turn(SIBLING_FOLLOWUP_PROMPT).await?;
+
+ let surviving_sibling = resumed
+ .thread_manager
+ .get_thread(sibling_thread_id)
+ .await
+ .expect("follow-up should reload the surviving sibling");
+ wait_for_event(surviving_sibling.as_ref(), |event| {
+ matches!(event, EventMsg::TurnComplete(_))
+ })
+ .await;
+ assert!(sibling_followup_request.requests().iter().any(|request| {
+ request.body_contains_text(SIBLING_FOLLOWUP_TASK)
+ && request.body_contains_text(ROLE_DEVELOPER_INSTRUCTIONS)
+ }));
+
Ok(())
}