From 068ad2d4b7ff64564c71a88a2f12ffdcac16f863 Mon Sep 17 00:00:00 2001 From: Reid <61492567+reidliu41@users.noreply.github.com> Date: Mon, 9 Mar 2026 03:54:18 +0800 Subject: [PATCH] Fix single-message mode to exit after one turn when background channels are enabled (#719) --- src/channels/repl.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/channels/repl.rs b/src/channels/repl.rs index 9031aa4e..f49cb7ee 100644 --- a/src/channels/repl.rs +++ b/src/channels/repl.rs @@ -303,6 +303,9 @@ impl Channel for ReplChannel { if let Some(msg) = single_message { let incoming = IncomingMessage::new("repl", "default", &msg).with_timezone(&sys_tz); let _ = tx.blocking_send(incoming); + // Ensure the agent exits after handling exactly one turn in -m mode, + // even when other channels (gateway/http) are enabled. + let _ = tx.blocking_send(IncomingMessage::new("repl", "default", "/quit")); return; } @@ -621,3 +624,29 @@ impl Channel for ReplChannel { Ok(()) } } + +#[cfg(test)] +mod tests { + use futures::StreamExt; + + use super::*; + + #[tokio::test] + async fn single_message_mode_sends_message_then_quit() { + let repl = ReplChannel::with_message("hi".to_string()); + let mut stream = repl.start().await.expect("repl start should succeed"); + + let first = stream.next().await.expect("first message missing"); + assert_eq!(first.channel, "repl"); + assert_eq!(first.content, "hi"); + + let second = stream.next().await.expect("quit message missing"); + assert_eq!(second.channel, "repl"); + assert_eq!(second.content, "/quit"); + + assert!( + stream.next().await.is_none(), + "stream should end after /quit" + ); + } +}