Skip to content

fix(agentic): flush persisted tool result before returning#881

Merged
GCWing merged 1 commit into
GCWing:mainfrom
harryfan1985:hotfix/tool-result-storage-flush
May 28, 2026
Merged

fix(agentic): flush persisted tool result before returning#881
GCWing merged 1 commit into
GCWing:mainfrom
harryfan1985:hotfix/tool-result-storage-flush

Conversation

@harryfan1985
Copy link
Copy Markdown
Contributor

@harryfan1985 harryfan1985 commented May 26, 2026

Summary

  • tool_result_storage::write_once 在 tokio write_all 之后未 flush()tokio::fs::File 缓冲写入且 drop 时不保证刷盘,导致后续同步 std::fs::read_to_string 可能读到空/不完整文件。
  • 添加显式 file.flush().await,保证缓冲数据落到底层 std File(OS 页缓存)。

影响

  • 在 macOS CI 上观察到的间歇性失败:agentic::tools::tool_result_storage::tests::bash_full_output_persists_even_when_assistant_text_is_already_truncated(left: "" vs right: "xxxx...")。
  • 生产路径同样可能受影响——任何在 write_once 返回后立即读取持久化文件的代码都可能拿到空内容。这里只是 macOS 时序更容易触发。

Test plan

  • cargo test -p bitfun-core bash_full_output_persists_even_when_assistant_text_is_already_truncated 通过
  • cargo test -p bitfun-core tool_result_storage(模块全量,6 passed)通过
  • CI(ubuntu/windows/macos) 通过

Notes

发现自 PR #846 的 macOS CI,根因与该 PR 无关,故拆出来单独提交。

🤖 Generated with Claude Code

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 <noreply@anthropic.com>
@GCWing GCWing merged commit 7cc8336 into GCWing:main May 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants