Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@TianYi0217
Copy link
Contributor

The streaming output seems correct but only appears together at the very last moment. I tried to use AI tools to find and modify this problem.

Since I'm not familiar with go, I followed the ai's advice and used a streaming package size of 512b instead of the 100-200b officially used by Anthropic. You can modify it to a more suitable size.

流式输出看起来正确但是只有在最后的时刻才一起出现. 我试着用AI工具找到并修改了这个问题.

因为我对go并不了解, 所以遵循ai的建议使用了并非Anthropic官方使用的100-200b而是512b的流式包大小. 你们可以修改成更合适的大小.


This project is extremely helpful. I have been facing this problem for a long time but don't have the appropriate ability to complete similar projects. Thank you all.

这个项目非常的有帮助, 我长期面临这个问题但是没有合适的能力来完成类似的项目, 感谢你们.

@TianYi0217
Copy link
Contributor Author

(base) PS C:\Users\Administrator\Documents\GitHub\autocache> go test ./...
?       autocache/cmd/autocache [no test files]
ok      autocache/internal/cache        0.068s
?       autocache/internal/client       [no test files]
ok      autocache/internal/config       0.072s
ok      autocache/internal/pricing      0.061s
ok      autocache/internal/server       0.083s
ok      autocache/internal/tokenizer    2.706s
ok      autocache/internal/types        0.049s

It seems that all the tests have passed. No new tests were created because no new features were added.

This is the first time I have submitted to an open-source project using the Pull Request function, so I'm not very familiar with it. If there are any mistakes in the process, you can leave a message for discussion.

测试看起来都通过了. 没有创建新的测试, 因为并没有新的功能添加.

这是我第一次使用Pull Request功能提交到开源项目, 因此我并不是很熟悉它. 如果流程有误可以留言讨论.

@jmrobles
Copy link
Contributor

Thanks @TianYi0217 for this excellent contribution!

Review Summary

I've reviewed the changes and they correctly address the streaming buffering issue. The implementation is sound:

✅ What works well:

  1. Root Cause Fix: Correctly identified that io.Copy() was buffering (32KB internal buffer) and replaced it with manual read/write loop with immediate flushing
  2. Smart Buffer Size: 512 bytes is a good choice for Anthropic's SSE events (typically 100-200 bytes each)
  3. Proper Error Handling: Clean separation of write errors vs read errors, with EOF handled correctly
  4. Interface Implementation: responseWrapper now properly implements http.Flusher with safe delegation

📝 Test Coverage

I've added comprehensive unit tests to validate the Flush functionality:

  • TestResponseWrapperFlush - Validates interface implementation
  • TestResponseWrapperFlushWithNonFlusher - Tests graceful degradation

All tests pass ✅

🎯 Recommendation

APPROVE - Ready to merge

This PR delivers real-time streaming as expected, with proper HTTP flushing for server-sent events. The changes are backward compatible and include graceful degradation when flushing isn't available.

Great work! 🎉

jmrobles pushed a commit that referenced this pull request Oct 23, 2025
Add comprehensive unit tests for the http.Flusher interface implementation
in responseWrapper, which is required for real-time streaming support.

Tests added:
- TestResponseWrapperFlush: Validates that responseWrapper implements
  http.Flusher and properly delegates Flush() calls to the underlying
  ResponseWriter
- TestResponseWrapperFlushWithNonFlusher: Ensures graceful handling
  when the underlying ResponseWriter doesn't support flushing

These tests validate the PR #8 changes that fix real-time streaming
by implementing proper HTTP flushing for server-sent events.
@jmrobles jmrobles merged commit 56de42c into montevive:main Oct 26, 2025
5 checks passed
jmrobles pushed a commit that referenced this pull request Oct 26, 2025
Add changelog entry for v1.0.4 release documenting the real-time
streaming improvements from PR #8.

Changes:
- Document fix for real-time streaming with proper HTTP flushing
- Detail technical implementation (manual read/write loop, Flush interface)
- Note 512-byte buffer optimization for SSE events
- Credit @TianYi0217 for the contribution
- Add unit test additions to changelog
jmrobles pushed a commit that referenced this pull request Oct 26, 2025
Add changelog entry for v1.0.4 release documenting the real-time
streaming improvements from PR #8.

Changes:
- Document fix for real-time streaming with proper HTTP flushing
- Detail technical implementation (manual read/write loop, Flush interface)
- Note 512-byte buffer optimization for SSE events
- Credit @TianYi0217 for the contribution
- Add unit test additions to changelog
jmrobles added a commit that referenced this pull request Oct 27, 2025
Add changelog entry for v1.0.4 release documenting the real-time
streaming improvements from PR #8.

Changes:
- Document fix for real-time streaming with proper HTTP flushing
- Detail technical implementation (manual read/write loop, Flush interface)
- Note 512-byte buffer optimization for SSE events
- Credit @TianYi0217 for the contribution
- Add unit test additions to changelog

Co-authored-by: chema <[email protected]>
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