Dev - #27
Merged
Merged
Conversation
Thinking events were streaming at the same 45ms per word as assistant updates, making long reasoning sequences painfully slow. Use 10ms per word for assistant.thinking events while keeping 45ms for assistant.update.
When the user cancelled mid-stream, the backend continued sleeping 2 seconds per event and streaming words the client would never see. With 10+ events queued, the AI message wasn't saved to the DB for 20+ seconds — if the user reopened the chat during that window, all assistant content was missing. Check res.destroyed at the start of handleEvent. If the client is gone, skip all writes and sleeps — just push the event to the events array and return immediately. The AI message is saved right after readAgentStream completes.
events.push was called before writing to the client, so events that were never delivered (due to client disconnect or mid-word-loop cancel) were saved to the DB. On reopen, the user saw events they never received during the live stream. Move events.push to after the write completes. For streaming events (assistant.update/thinking), push only after all words are sent. Check res.destroyed inside the word loop so a mid-stream disconnect skips the push. The title.generated session update still runs before the res.destroyed check so the title is saved regardless.
The run.completed summary was sent as a single NDJSON line, appearing instantly instead of streaming like other assistant messages. When run.completed has a summary, stream it as assistant.update word chunks (45ms each) to the client, then send the run.completed event without the summary. Push only the original run.completed (with summary) to the events array for DB saving — no synthetic assistant.update event is saved, so there is no duplication on reopen.
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.
No description provided.