Skip to content

fix(web): a pending send stays shown after leaving and returning to its thread - #38948

Open
juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-38903-a1795062471
Open

juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-38903-a1795062471

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

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

  • A pending message for a left thread whose ack arrives while the view is away stays in pendingByThread until the view returns to that thread or unmounts (bounded and small; not cleaned up proactively).
  • Image thumbnails of a pending message are not kept across a thread switch; keeping them would mean changing blob-preview ownership so leaving a thread does not revoke them.
  • Not reproduced in the running app; the repro step's browser reproduction and its unit test were relied on, plus the unit tests here.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 2 commits November 19, 2026 04:52
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>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Optimistic user messages now remain associated with their thread while it is inactive. Reconciliation restores pending messages when a thread becomes active, and updates for inactive threads modify that thread’s pending messages.

Changes: Thread-scoped optimistic messages

Layer / File(s) Summary
Store and restore pending messages
apps/web/src/components/chat/optimisticUserMessages.ts, apps/web/src/components/chat/optimisticUserMessages.test.ts
The state now stores pending messages by thread. Reconciliation restores a thread’s pending messages and stores messages from the previous thread without blob preview URLs. The test checks that an unacknowledged message remains visible after returning to its thread.
Apply updates to inactive threads
apps/web/src/components/chat/optimisticUserMessages.ts, apps/web/src/components/chat/optimisticUserMessages.test.ts
Updates for inactive threads now apply to their pending messages. Tests check that a failed send is removed and that another send remains visible after reconciliation without its blob preview.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • pingdotgg/t3code#25710: Changes the same optimistic-message state to key messages and blob previews by thread.

Suggested labels: bugfix

Suggested reviewers: maria-rcks, yash-singh1

Merge Risk: Minimal · up to 5cd2e

Pending messages now stay visible when switching away from a thread and back, and failures are applied to the thread's pending list. No actionable merge-blocking issues were found. Thumbnails are intentionally not preserved across switches.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #38903 requires that a send still in flight stays visible in its thread after switching threads and back, and that a failed send shows as failed with a way to resend. At the reviewed head, optim… Confirm, from ChatView rendering and chatViewSend.ts at head, whether (a) pending optimistic rows render with a sending state, and (b) a failed send for a thread the view has left is shown as failed or otherwise gives a resend path, as #389…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title states the main change: a pending send now stays visible after leaving and returning to its thread. It matches the raw summary, the PR objectives, and the linked issue #38903. It uses a conv…
Description check Passed The description covers the required template sections. Problem is given as the cause and symptom, with reproduction steps on main. Change explains the pendingByThread fix and why blob previews are rem…
Out of Scope Changes check Passed All changed code is in apps/web/src/components/chat/optimisticUserMessages.ts and its test file. The source changes add pendingByThread, the thread-switch handoff of pending messages, send-path routin…
Full details: Title check

Explanation

The title states the main change: a pending send now stays visible after leaving and returning to its thread. It matches the raw summary, the PR objectives, and the linked issue #38903. It uses a conventional commit prefix and plain language. At 78 characters it is slightly long but still readable.

Full details: Description check

Explanation

The description covers the required template sections. Problem is given as the cause and symptom, with reproduction steps on main. Change explains the pendingByThread fix and why blob previews are removed. Scope links issue #38903 and describes it as a bug fix. Verification lists the unit test results and the commands run, and states what was not checked in the running app. The Evidence section is empty and marked as being captured, so the before/after screenshots that the template requires for UI changes are still missing. This is one gap, but the description is otherwise mostly complete.

Full details: Out of Scope Changes check

Explanation

All changed code is in apps/web/src/components/chat/optimisticUserMessages.ts and its test file. The source changes add pendingByThread, the thread-switch handoff of pending messages, send-path routing for left threads, and withoutBlobPreviews. Each change supports retaining unacknowledged sends across thread switches, which #38903 requires. withoutBlobPreviews is needed because leaving a thread revokes its blob previews. The test rewrite replaces the assertion that encoded the buggy behaviour. The 'Not in this change' section excludes slow dispatch, which #38903 names as a separate problem. No unrelated change was identified.

Full details: Linked Issues check

Explanation

Issue #38903 requires that a send still in flight stays visible in its thread after switching threads and back, and that a failed send shows as failed with a way to resend. At the reviewed head, optimisticUserMessages.ts meets the first part. reconcileOptimisticUserMessages stores the previous thread's unacknowledged messages in pendingByThread and restores them when the view returns. The unit test 'a send the server has not acknowledged is still shown after leaving and returning to its thread' covers this. Applying send-path updates to pendingByThread for a left thread covers the late add and failure removal. The second part is not established. The failure path removes the message from the pending list. The change does not add a failed state or a sending indicator in the code reviewed. The issue states that a failed send restores its text to the composer draft (chatViewSend.ts). I did not inspect ChatView rendering or chatViewSend.ts, so I cannot confirm whether a sending marker or a failed row exists or whether the draft restore gives a resend path for a left thread.

Resolution

Confirm, from ChatView rendering and chatViewSend.ts at head, whether (a) pending optimistic rows render with a sending state, and (b) a failed send for a thread the view has left is shown as failed or otherwise gives a resend path, as #38903 expects. If neither is present, the failed-state requirement of #38903 is unmet and the PR needs to add it, or the scope must be narrowed by the maintainers.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 082bc2c and 5cd2e62.

Files selected for processing: 2

  • apps/web/src/components/chat/optimisticUserMessages.test.ts
  • apps/web/src/components/chat/optimisticUserMessages.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Desktop: a message still being sent disappears if you switch threads before the server accepts it

1 participant