From cb9c5437f44266596aa0e0b5622b3dc823061a4c Mon Sep 17 00:00:00 2001 From: harryfan1985 Date: Tue, 26 May 2026 09:48:28 +0800 Subject: [PATCH] fix(agentic): flush persisted tool result before returning tokio::fs::File buffers writes and does not guarantee a flush on drop, so a subsequent synchronous read could observe an empty/partial file. This caused an intermittent macOS CI failure in bash_full_output_persists_even_when_assistant_text_is_already_truncated. Add an explicit flush() after write_all so persisted output is visible to later readers. Co-Authored-By: Claude Opus 4.7 --- .../core/src/agentic/tools/tool_result_storage.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/crates/core/src/agentic/tools/tool_result_storage.rs b/src/crates/core/src/agentic/tools/tool_result_storage.rs index b3f414880..f4bdcc96c 100644 --- a/src/crates/core/src/agentic/tools/tool_result_storage.rs +++ b/src/crates/core/src/agentic/tools/tool_result_storage.rs @@ -221,6 +221,18 @@ async fn write_once(path: &Path, content: &str) -> BitFunResult<()> { path.display(), error )) + })?; + // tokio::fs::File buffers writes and does NOT guarantee a flush on + // drop, so without an explicit flush a subsequent (possibly + // synchronous) read can observe an empty or partial file. This was + // an intermittent failure on macOS CI. flush() drains the buffer to + // the OS so the persisted output is visible to later readers. + file.flush().await.map_err(|error| { + BitFunError::io(format!( + "Failed to flush tool result file {}: {}", + path.display(), + error + )) }) } Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => Ok(()),