fix(tui): coalesce part stream deltas per frame to prevent stalls - #41472
Draft
warrenbhw wants to merge 1 commit into
Draft
fix(tui): coalesce part stream deltas per frame to prevent stalls#41472warrenbhw wants to merge 1 commit into
warrenbhw wants to merge 1 commit into
Conversation
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
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. |
Author
|
This is obviously not ready for review, just had an agent do a first slop pass trying to fix a bug I hit in opencode2. I'll figure out a repro case, validate the fix, and clean up the code sometime in the next couple of days. |
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.
Problem
Clicking to expand a streaming
<thinking>block in the TUI can stall the UI until reasoning finishes.Root cause chain:
session.next.reasoning.delta(andtext.delta/tool.input.delta) events per chunk, unbuffered (packages/core/src/session/runner/publish-llm-event.ts:278).match.text += event.data.deltaon each event (packages/tui/src/context/data.tsx).Note the web app already avoids this exact problem with per-part delta accumulation (
part_text_accum_delta, #26822); the TUI had no equivalent.Change
Adds a per-frame delta coalescer (
packages/tui/src/context/delta-buffer.ts):(kind, sessionID, messageID, partID); the store is rewritten at most once per animation frame instead of once per event.drain()runs before any non-delta event (e.g.*.ended) so terminating events that replace the full part text still observe the final accumulated deltas; also drains on provider unmount.text.delta,reasoning.delta, andtool.input.delta(identical pattern, same fix).Testing
createDeltaBuffer(coalescing, per-part isolation, drain semantics, stale flush no-op, single-schedule).bun testpasses 5/5.tsgo --noEmitin this environment (tool not installed); changes are type-annotated to match the module's existing usage.Follow-up (not included)
packages/core/src/session/message-updater.ts:358) performs the same per-delta full-text rewrite; worth batching there separately.