fix: case where agent is already closed (#15163)

This commit is contained in:
jif-oai 2026-03-19 12:12:50 +00:00 committed by GitHub
parent 70cdb17703
commit 32d2df5c1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 14 deletions

View file

@ -444,11 +444,17 @@ impl AgentControl {
/// persisted spawn-edge state.
pub(crate) async fn shutdown_live_agent(&self, agent_id: ThreadId) -> CodexResult<String> {
let state = self.upgrade()?;
if let Ok(thread) = state.get_thread(agent_id).await {
let result = if let Ok(thread) = state.get_thread(agent_id).await {
thread.codex.session.ensure_rollout_materialized().await;
thread.codex.session.flush_rollout().await;
}
let result = state.send_op(agent_id, Op::Shutdown {}).await;
if matches!(thread.agent_status().await, AgentStatus::Shutdown) {
Ok(String::new())
} else {
state.send_op(agent_id, Op::Shutdown {}).await
}
} else {
state.send_op(agent_id, Op::Shutdown {}).await
};
let _ = state.remove_thread(&agent_id).await;
self.state.release_spawned_thread(agent_id);
result

View file

@ -68,17 +68,13 @@ impl ToolHandler for Handler {
return Err(collab_agent_error(agent_id, err));
}
};
let result = if !matches!(status, AgentStatus::Shutdown) {
session
.services
.agent_control
.close_agent(agent_id)
.await
.map_err(|err| collab_agent_error(agent_id, err))
.map(|_| ())
} else {
Ok(())
};
let result = session
.services
.agent_control
.close_agent(agent_id)
.await
.map_err(|err| collab_agent_error(agent_id, err))
.map(|_| ());
session
.send_event(
&turn,