Wait for agent shutdown before releasing thread

This commit is contained in:
Dylan Hurd
2026-05-06 07:57:04 -04:00
parent f9a907aebe
commit 0d3dd22129

View File

@@ -693,9 +693,14 @@ impl AgentControl {
thread.codex.session.ensure_rollout_materialized().await;
thread.codex.session.flush_rollout().await?;
if matches!(thread.agent_status().await, AgentStatus::Shutdown) {
thread.wait_until_terminated().await;
Ok(String::new())
} else {
state.send_op(agent_id, Op::Shutdown {}).await
let result = state.send_op(agent_id, Op::Shutdown {}).await;
if result.is_ok() {
thread.wait_until_terminated().await;
}
result
}
} else {
state.send_op(agent_id, Op::Shutdown {}).await