fix: reduce streaming stutter in the web chat - #1085
Conversation
🦋 Changeset detectedLatest commit: 35726c7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 17e8f1b654
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Coalesce high-frequency render events onto the next animation frame; | ||
| // everything else is applied immediately. See createEventBatcher / | ||
| // processEvent above. | ||
| enqueueEvent({ appEvent, meta }); |
There was a problem hiding this comment.
Flush queued stream events before session teardown
When a user archives a streaming session and the archive response returns before the next animation frame, this newly queued assistantDelta/toolOutput can survive archiveSession -> forgetSession, which unsubscribes and deletes the per-session maps. The later rAF drain still calls reduceAppEvent for that session, recreating entries such as messagesBySession[sessionId]/lastSeqBySession after teardown; if that id is fetched again, hasLoadedMessages() can then treat the stale/empty cache as authoritative and skip the snapshot. Please flush or discard pending events for the session before clearing it.
Useful? React with 👍 / 👎.
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Related Issue
No linked issue — investigated from a user report of stuttery streaming in LAN mode. Supersedes #1083 (renamed branch).
Problem
When using the server-hosted web UI (especially over LAN), the assistant stream looks stuttery: tokens appear word-by-word, and it gets worse as a session grows longer. Two independent causes were identified:
messagesToTurnsrebuild + full Markdown re-parse + scroll reflow). When the model streams fast, hundreds of redundant renders per second saturate the main thread, so the stream looks slow.What changed
apps/kimi-web): coalesce high-frequency streaming events (assistantDelta,agentDelta,toolOutput,taskProgress) onto the next animation frame so Vue commits at most one render per frame. Lifecycle / control-flow events still apply immediately (so turn-end cleanup is never delayed, even in a background tab). AddedeventBatcher.ts(pure, tested) and wired it into the WS event pipeline.packages/server): callsocket.setNoDelay(true)on the upgraded WebSocket socket so small delta frames are sent immediately instead of being held by Nagle's algorithm.The logging needed to confirm the arrival cadence already exists: enabling the opt-in debug trace (
?debug=1orlocalStorage["kimi-web.debug"]="1") records every inbound frame's arrival timestamp into a bounded ring buffer, so no new logging was added.Checklist
apps/kimi-web/test/event-batcher.test.ts)gen-changesetsskill, or this PR needs no changeset. (added two changesets)gen-docsskill, or this PR needs no doc update. (no user-facing doc change)