Repository navigation
fix(web): a pending send stays shown after leaving and returning to its thread - #38948
juliusmarminge wants to merge 2 commits into
Conversation
Fails on main: reconcileOptimisticUserMessages drops an unacknowledged optimistic message when the view switches threads, so returning to the thread shows nothing until the server accepts the send (#38903). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts thread The chat view's optimistic messages were dropped when it switched threads, and later send-path updates for the left thread were ignored, so a send the server had not accepted yet vanished until the server echoed it (#38903). Unacknowledged messages of a left thread now wait per thread and come back when the view returns; a late add or failure for that thread applies to them. Their blob previews are dropped, since leaving the thread revokes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Cause: in apps/web/src/components/chat/optimisticUserMessages.ts, reconcileOptimisticUserMessages emptied the chat view's optimistic messages when the thread changed, and applyOptimisticUserMessagesAction ignored later updates for a thread the view had left. A send the server had not accepted yet therefore disappeared until the server echoed it. Fix: OptimisticUserMessages gains
pendingByThread. On a thread switch, the previous thread's unacknowledged messages move there, and the new thread's messages come back out (then reconcile drops any the server accepted in the meantime). The previous thread's handoff is still released. Send-path updates for a left thread (an add that lands after leaving during an upload, or the failure path's removal) now apply to that thread's pending list, so a failed send never gets stuck as sending. Leaving a thread already revokes its blob previews (useAttachmentPreviewHandoff's revokeThread), so pending messages have their blob previewUrl removed and render as image attachments without a preview, the same as server rows whose URLs are not minted yet, never as broken images. The existing test 'drops a late update for a thread the view has left' asserted the buggy behaviour, so it is rewritten to check that a late add and a failure for a left thread apply to its pending list, and that blob previews are removed. The repro test from factory/repro-38903 is kept unchanged. No new regex or parser. Verified with unit tests only, not in the running app.Fixes #38903
Reproduction on main
Commit a941ab5 (origin/main). Ran the web dev server with T3CODE_DEV_SEED=0 on a fresh database; the desktop app renders the same ChatView. Created threads A and B with window.t3dev.replay("multi-turn") (Replay dev provider). To simulate a slow server, patched WebSocket.prototype.send in the page to hold every orchestration.dispatchCommand frame for 30 s. On thread A, typed "REPRO-38903 slow send" and pressed Enter: the message.dispatch command was held, the optimistic message showed in A, and the composer cleared. Clicked thread B in the sidebar, then clicked thread A again, with the send still held: A showed only its earlier turn, the message was gone, the composer was empty, and nothing indicated a send in progress. The only sign was the 'Some requests are slow - 1 request waiting longer than 15s' toast, matching the report. When the held frame was released after 30 s, the server accepted the message and it appeared in A. Unit test on branch factory/repro-38903 (08ce654): leaving thread A and returning drops the unacknowledged optimistic message (expected ["a1"], got []).
Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/components/chat/optimisticUserMessages.test.ts (apps/web): 7/7 pass with the fix; with only the source file reverted, the repro test and the rewritten late-update test fail (2 failed, 5 passed). vp run check:changed: format, lint, knip, typecheck (2 packages), tests, react compiler all pass.
Not in this change
Who did the work
Run by the t3code factory in T3 Code.