Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Route V2 child loading through `AgentControl` (#47629)

jife1f3fafad8cc
diff --git a/codex-rs/core/src/agent/api.rs b/codex-rs/core/src/agent/api.rs
index 25115088b2..e2ef8de4b5 100644
--- a/codex-rs/core/src/agent/api.rs
+++ b/codex-rs/core/src/agent/api.rs
@@ -62,6 +62,11 @@ pub trait AgentControl: Send + Sync {
/// the root. Legacy user input can address loaded threads outside the agent registry.
fn send(&self, request: SendRequest) -> BoxFuture<'_, Result<DeliveryReceipt>>;
+ /// Load a recorded V2 child through its live immediate parent, without sending input.
+ /// Implementations validate ownership and restore the child under the parent's current
+ /// authority. Success makes the child available for attachment through its thread manager.
+ fn ensure_child_loaded(&self, parent: ThreadId, child: ThreadId) -> BoxFuture<'_, Result<()>>;
+
/// Stop current work and return the pre-interrupt snapshot. V2 rejects root/self
/// targets and tolerates known unloaded agents; other modes retain direct-ID interruption.
fn interrupt(
diff --git a/codex-rs/core/src/agent/control/api.rs b/codex-rs/core/src/agent/control/api.rs
index 9bac5f779e..9ee1d50c57 100644
--- a/codex-rs/core/src/agent/control/api.rs
+++ b/codex-rs/core/src/agent/control/api.rs
@@ -165,6 +165,15 @@ impl AgentControl for LocalAgentControl {
})
}
+ fn ensure_child_loaded(&self, parent: ThreadId, child: ThreadId) -> BoxFuture<'_, Result<()>> {
+ Box::pin(async move {
+ let parent = self.runtime.upgrade()?.get_thread(parent).await?;
+ let config = parent.session.get_config().await.as_ref().clone();
+ self.ensure_v2_agent_loaded(config, child, Some(parent))
+ .await
+ })
+ }
+
fn interrupt(
&self,
caller: ThreadId,
diff --git a/codex-rs/core/src/thread_manager.rs b/codex-rs/core/src/thread_manager.rs
index 239b87e83e..09ad357867 100644
--- a/codex-rs/core/src/thread_manager.rs
+++ b/codex-rs/core/src/thread_manager.rs
@@ -1205,14 +1205,11 @@ impl ThreadManager {
"cannot resume multi-agent v2 child {child_thread_id}: parent {parent_thread_id} is not loaded; resume the parent first"
))
})?;
- let config = parent.session.get_config().await.as_ref().clone();
- let agent_control = parent
+ parent
.session
.services
- .local_agent_runtime
- .control(parent.session.session_id());
- agent_control
- .ensure_v2_agent_loaded(config, child_thread_id, Some(parent))
+ .agent_control
+ .ensure_child_loaded(parent_thread_id, child_thread_id)
.await
}