From d9f72b6af2a429d15f327bc8477f427c2aa5db06 Mon Sep 17 00:00:00 2001 From: Rasmus Rygaard Date: Tue, 23 Jun 2026 23:48:37 +0000 Subject: [PATCH] [core] stabilize subagent resume mode test --- codex-rs/core/src/agent/control_tests.rs | 61 ++++++++++++++++-------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/codex-rs/core/src/agent/control_tests.rs b/codex-rs/core/src/agent/control_tests.rs index e37e9b04db..6d71fe81d2 100644 --- a/codex-rs/core/src/agent/control_tests.rs +++ b/codex-rs/core/src/agent/control_tests.rs @@ -2291,6 +2291,47 @@ async fn resume_thread_subagent_restores_stored_metadata_and_effective_multi_age .get_thread(child_thread_id) .await .expect("child thread should exist"); + let mut status_rx = harness + .control + .subscribe_status(child_thread_id) + .await + .expect("status subscription should succeed"); + timeout(Duration::from_secs(5), async { + while matches!(status_rx.borrow().clone(), AgentStatus::PendingInit) { + status_rx + .changed() + .await + .expect("child status should advance past pending init"); + } + if matches!(status_rx.borrow().clone(), AgentStatus::Running) { + harness + .control + .interrupt_agent(child_thread_id) + .await + .expect("child turn should accept interruption"); + } + while matches!( + status_rx.borrow().clone(), + AgentStatus::PendingInit | AgentStatus::Running + ) { + status_rx + .changed() + .await + .expect("child status should reach a terminal state"); + } + while child_thread + .codex + .session + .active_turn + .lock() + .await + .is_some() + { + sleep(Duration::from_millis(10)).await; + } + }) + .await + .expect("child turn should settle before writing resume history"); let mut child_turn_context = child_thread .codex .session @@ -2323,26 +2364,6 @@ async fn resume_thread_subagent_restores_stored_metadata_and_effective_multi_age }) .await .expect("change parent multi-agent mode before child resume"); - let mut status_rx = harness - .control - .subscribe_status(child_thread_id) - .await - .expect("status subscription should succeed"); - if matches!(status_rx.borrow().clone(), AgentStatus::PendingInit) { - timeout(Duration::from_secs(5), async { - loop { - status_rx - .changed() - .await - .expect("child status should advance past pending init"); - if !matches!(status_rx.borrow().clone(), AgentStatus::PendingInit) { - break; - } - } - }) - .await - .expect("child should initialize before shutdown"); - } let original_snapshot = child_thread.config_snapshot().await; let original_nickname = original_snapshot .session_source