fix: messages disappearing when sending during active response#25
Merged
Conversation
The boolean pendingLocalSendRef gets clobbered when a user sends a message while a previous run is still active. The error/final handler from run A clears the flag, so run B final thinks it was external and triggers a full history reload that wipes the UI. Replace with: - localRunIdsRef (Set) to track run IDs from chat.send acks - pendingSendCountRef (counter) for the window before ack arrives This ensures one run completing never affects another run tracking.
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
Messages disappear when you type and send a message while the assistant is still responding. Your sent message and the assistant response both vanish.
Root Cause
pendingLocalSendRefis a single boolean. When you send message B while run A is active:send()setspendingLocalSendRef = truefinalorerror→ clearspendingLocalSendRef = falsewasLocalRun = false(flag was already cleared)loadHistory()which replaces all messages with server historyFix
Replace the boolean with per-run tracking:
localRunIdsRef(Set) — tracks run IDs fromchat.sendackspendingSendCountRef(counter) — covers the window betweensend()and ackOne run completing never affects another run's tracking. The
finalhandler checks if the specific run was local before deciding whether to reload history.Testing