From fe1cbd0f388bd2c15b8087913921be839ca5f381 Mon Sep 17 00:00:00 2001 From: jif-oai Date: Thu, 5 Feb 2026 16:07:50 +0000 Subject: [PATCH] chore: handle shutdown correctly in tui (#10756) --- codex-rs/tui/src/chatwidget/agent.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/codex-rs/tui/src/chatwidget/agent.rs b/codex-rs/tui/src/chatwidget/agent.rs index c902e5c63..d905f884f 100644 --- a/codex-rs/tui/src/chatwidget/agent.rs +++ b/codex-rs/tui/src/chatwidget/agent.rs @@ -62,7 +62,13 @@ pub(crate) fn spawn_agent( }); while let Ok(event) = thread.next_event().await { + let is_shutdown_complete = matches!(event.msg, EventMsg::ShutdownComplete); app_event_tx_clone.send(AppEvent::CodexEvent(event)); + if is_shutdown_complete { + // ShutdownComplete is terminal for a thread; drop this receiver task so + // the Arc can be released and thread resources can clean up. + break; + } } }); @@ -99,7 +105,13 @@ pub(crate) fn spawn_agent_from_existing( }); while let Ok(event) = thread.next_event().await { + let is_shutdown_complete = matches!(event.msg, EventMsg::ShutdownComplete); app_event_tx_clone.send(AppEvent::CodexEvent(event)); + if is_shutdown_complete { + // ShutdownComplete is terminal for a thread; drop this receiver task so + // the Arc can be released and thread resources can clean up. + break; + } } });