Skip to content

fix: messages disappearing when sending during active response#25

Merged
ngmaloney merged 2 commits into
mainfrom
fix/message-disappearing-concurrent-send
Apr 2, 2026
Merged

fix: messages disappearing when sending during active response#25
ngmaloney merged 2 commits into
mainfrom
fix/message-disappearing-concurrent-send

Conversation

@ngmaloney
Copy link
Copy Markdown
Owner

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

pendingLocalSendRef is a single boolean. When you send message B while run A is active:

  1. send() sets pendingLocalSendRef = true
  2. Run A completes with final or error → clears pendingLocalSendRef = false
  3. Run B completes → wasLocalRun = false (flag was already cleared)
  4. Non-local run triggers loadHistory() which replaces all messages with server history
  5. UI state (your message + streaming response) gets wiped

Fix

Replace the boolean with per-run tracking:

  • localRunIdsRef (Set) — tracks run IDs from chat.send acks
  • pendingSendCountRef (counter) — covers the window between send() and ack

One run completing never affects another run's tracking. The final handler checks if the specific run was local before deciding whether to reload history.

Testing

  1. Connect to gateway, start chatting
  2. While assistant is responding, type and send another message
  3. Both messages should remain visible
  4. Assistant responses should not disappear

ngmaloney and others added 2 commits April 1, 2026 13:25
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.
@ngmaloney ngmaloney merged commit 8849c10 into main Apr 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant