From 7dec04ae4fd3a26a8ee2a14188f1b28b36c75c7e Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Mon, 4 Aug 2025 15:12:53 -0700 Subject: [PATCH] deadlock --- .../src/tool_handlers/stream_conversation.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/codex-rs/mcp-server/src/tool_handlers/stream_conversation.rs b/codex-rs/mcp-server/src/tool_handlers/stream_conversation.rs index 860a90ddd7..3841007259 100644 --- a/codex-rs/mcp-server/src/tool_handlers/stream_conversation.rs +++ b/codex-rs/mcp-server/src/tool_handlers/stream_conversation.rs @@ -17,7 +17,7 @@ pub(crate) async fn handle_stream_conversation( let session_id = conversation_id.0; - // Ensure the session exists and enable streaming + // Ensure the session exists let conv = get_session(session_id, message_processor.conversation_map()).await; if conv.is_none() { @@ -28,11 +28,7 @@ pub(crate) async fn handle_stream_conversation( return; } - if let Some(conv) = conv { - conv.lock().await.set_streaming(true).await; - } - - // Acknowledge the stream request + // Acknowledge the stream request first so the client can start listening message_processor .send_response_with_optional_error( id, @@ -42,6 +38,13 @@ pub(crate) async fn handle_stream_conversation( Some(false), ) .await; + + // Now enable streaming and send initial state + if let Some(conv) = conv { + tokio::spawn(async move { + conv.lock().await.set_streaming(true).await; + }); + } } /// Handles cancellation for ConversationStream by disabling streaming for the session.