fix(tui): resolve streaming freeze from unhandled finish event, missing timeouts, and unguarded effects#15308
Open
coleleavitt wants to merge 1 commit intoanomalyco:devfrom
Open
Conversation
…ng timeouts, and unguarded effects - Fix stream termination in processor.ts: for-await loop now breaks on finish event - Increase SDK event batch window from 16ms to 50ms to reduce render churn - Add withTimeout to MCP client.listTools() to prevent indefinite hangs - Handle fire-and-forget effect Promise rejections in db.ts
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #15310
Related upstream issues
Type of change
What does this PR do?
Fixes four independent bugs that cause TUI freezes/hangs during and after LLM streaming:
processor.ts— Thefor await (stream.fullStream)loop never broke on thefinishevent, only onneedsCompaction. After the LLM finishes, the loop hung at 0% CPU waiting for more events that would never come. Fix: addedfinishedflag that breaks the loop on thefinishcase.sdk.tsx— The 16ms event batch window caused excessive render churn at high token rates (10+ tokens/sec). Each render re-parses accumulated markdown, generating O(n) garbage that pressures the GC. Fix: increased to 50ms, which still feels instant but cuts renders by ~3x during bursts.mcp/index.ts—client.listTools()had no timeout. If an MCP server stalls, this blocks indefinitely. Fix: wrapped inwithTimeout()using the configured or default timeout.db.ts— Fire-and-forget effects could reject silently.Promise.resolve(effect())was called without.catch(), causing unhandled rejections. Fix: added.catch()with error logging.The stream termination bug (#1) is the most impactful — it's the direct cause of the "TUI hangs after response completes" behavior. The underlying GC contention that amplifies these bugs is tracked in the Bun/WebKit issues above.
How did you verify your code works?
turbo typecheckpasses across all 18 packagesturbo buildsucceedsScreenshots / recordings
N/A — not a UI change.
Checklist