fix(chat): keep pending user message visible until its echo arrives#863
fix(chat): keep pending user message visible until its echo arrives#863bourgois wants to merge 1 commit into
Conversation
The pending (optimistic) user message was only shown while the store was empty (all.length === 0). On an existing session, the first realtime event after sending can be a stream_delta (assistant content) that arrives before the echoed user message is committed to the store. As soon as that delta lands, all.length > 0, the pending message is dropped, and the assistant response briefly renders as the first visible message with the user's prompt missing. Gate on the absence of an actual user message instead of an empty store, and append the pending message after existing content so it stays put until its own echo appears.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesChat Pending Message Race Condition Fix
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hey @bourgois, tried replicating this on main but couldn't get the issue described here. I used claude and codex for testing purposes. Can you check if the issue still exists? |
|
Thanks for checking @blackmammoth — you're right, and the fault is in my repro. I traced it: The only real window is a sub-frame timing race in the new-session path (between the backend assigning a session id and the pending message being flushed to the store), which isn't reliably reproducible by hand and isn't worth your review time. Closing this. Sorry for the noise. #854, #855, and #862 stand on their own. |
Small, self-contained fix extracted from #855 at the maintainer's request.
Issue
The optimistic "pending" user message (shown immediately after you hit send, before the backend echoes it) is only rendered while the message store is empty:
On an existing session, the first realtime event after sending can be a
stream_delta(assistant content) that arrives before the echoed user message is committed to the store. The moment that delta lands,all.length > 0, so the pending message is dropped — and the assistant's reply briefly renders as the first visible message with the user's prompt missing, until the echo catches up.Reproduction
Fix
Gate on the absence of an actual user message (
all.some(m => m.type === 'user')) rather than an empty store, and append the pending message after existing content so it remains visible until its echo is committed.npm run typecheckandeslintpass. Small change inuseChatSessionState.ts.Summary by CodeRabbit