From 469b7cf8c6c50aceda58d625701aba217c6e2a2c Mon Sep 17 00:00:00 2001 From: Austin Schaefer Date: Mon, 17 Aug 2026 12:19:08 +0200 Subject: [PATCH] simplify: use print! + flush for streamed chunks, not an explicit stdout lock print! already locks stdout per call, so the manual lock()/write!() was extra ceremony over what the flush actually needed. Matches rig's own cli_chatbot streaming example more closely. Co-Authored-By: Claude Sonnet 5 --- deep_research/src/core.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/deep_research/src/core.rs b/deep_research/src/core.rs index ad8ed03..fcfbc9d 100644 --- a/deep_research/src/core.rs +++ b/deep_research/src/core.rs @@ -178,7 +178,6 @@ async fn write_report( drop(spinner); let mut report = String::new(); - let stdout = std::io::stdout(); while let Some(chunk) = response_stream.next().await { match chunk? { @@ -187,9 +186,11 @@ async fn write_report( .. })) => { report.push_str(&text); - let mut handle = stdout.lock(); - write!(handle, "{text}")?; - handle.flush()?; + // Terminal stdout is line-buffered, so a flush is needed here — + // otherwise a chunk without a trailing newline sits in the + // buffer instead of appearing as it streams in. + print!("{text}"); + std::io::stdout().flush()?; } _ => continue, }