fix: root as std agent (#15881)

This commit is contained in:
jif-oai
2026-03-26 17:57:34 +00:00
committed by GitHub
parent 0bd34c28c7
commit 970386e8b2
3 changed files with 173 additions and 12 deletions

View File

@@ -44,6 +44,7 @@ use tracing::warn;
const AGENT_NAMES: &str = include_str!("agent_names.txt");
const FORKED_SPAWN_AGENT_OUTPUT_MESSAGE: &str = "You are the newly spawned agent. The prior conversation history was forked from your parent agent. Treat the next user message as your new task, and use the forked history only as background context.";
const ROOT_LAST_TASK_MESSAGE: &str = "Main thread";
#[derive(Clone, Debug, Default)]
pub(crate) struct SpawnAgentOptions {
@@ -650,12 +651,6 @@ impl AgentControl {
let agent_path = current_agent_path
.resolve(agent_reference)
.map_err(CodexErr::UnsupportedOperation)?;
if agent_path.is_root() {
return Err(CodexErr::UnsupportedOperation(
"root is not a spawned agent".to_string(),
));
}
if let Some(thread_id) = self.state.agent_id_for_path(&agent_path) {
return Ok(thread_id);
}
@@ -737,7 +732,21 @@ impl AgentControl {
})
});
let mut agents = Vec::with_capacity(live_agents.len());
let root_path = AgentPath::root();
let mut agents = Vec::with_capacity(live_agents.len().saturating_add(1));
if resolved_prefix
.as_ref()
.is_none_or(|prefix| agent_matches_prefix(Some(&root_path), prefix))
&& let Some(root_thread_id) = self.state.agent_id_for_path(&root_path)
&& let Ok(root_thread) = state.get_thread(root_thread_id).await
{
agents.push(ListedAgent {
agent_name: root_path.to_string(),
agent_status: root_thread.agent_status().await,
last_task_message: Some(ROOT_LAST_TASK_MESSAGE.to_string()),
});
}
for metadata in live_agents {
let Some(thread_id) = metadata.agent_id else {
continue;