Skip to content

Fix streaming hang when passing string to stream() method#296

Open
delay wants to merge 2 commits intohexgrad:mainfrom
delay:fix/text-splitter-stream-close
Open

Fix streaming hang when passing string to stream() method#296
delay wants to merge 2 commits intohexgrad:mainfrom
delay:fix/text-splitter-stream-close

Conversation

@delay
Copy link

@delay delay commented Jan 26, 2026

Summary

When passing a string directly to the stream() method in kokoro.js, the TextSplitterStream was not being closed after pushing the text chunks. This caused the async iterator to hang indefinitely waiting for more input that would never come.

The Bug

In kokoro.js/src/kokoro.js, when the stream() method receives a string input, it:

  1. Creates a new TextSplitterStream
  2. Splits the text into chunks
  3. Pushes the chunks to the splitter

However, it never called splitter.close() to signal that no more input would be coming. This caused any code iterating over the stream to hang forever after processing all chunks.

The Fix

Added a call to splitter.close() after pushing the chunks to properly signal end-of-input:

splitter.push(...chunks);
// Close the stream to signal no more input is coming
// This fixes a bug where the async iterator would hang waiting for more input
splitter.close();

Testing

Tested by using the stream() method with string input in a Node.js application. Before the fix, the async iteration would hang indefinitely. After the fix, it completes normally when all chunks have been processed.


🤖 Generated with Claude Code

delay and others added 2 commits January 25, 2026 22:55
When passing a string directly to the stream() method, the TextSplitterStream
was not being closed after pushing the text chunks. This caused the async
iterator to hang indefinitely waiting for more input that would never come.

The fix adds a call to splitter.close() after pushing the chunks to properly
signal that no more input is coming, allowing the async iteration to complete.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant