Skip to content

Never lose a message when a send fails - #7784

Merged
ymichael merged 2 commits into
mainfrom
bb/never-lose-a-message-when-a-send-fails-thr_enbyak9n2z
Nov 18, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/never-lose-a-message-when-a-send-fails-thr_enbyak9n2z

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Every composer send path cleared the draft before awaiting the request. On failure it called restoreIfEmpty, which writes the submitted draft back only if the composer is still empty. If the user had started typing while the request was pending (common on flaky Connect or mobile links), the failed message's text and attachments were dropped and the only trace was a generic "Failed to send message" toast. The same clear → await → restore-if-empty sequence was copied into the thread follow-up send, the modifier/shortcut send, the handoff send (ThreadDetailPromptArea) and the new-thread send (NewThreadComposer). A related gap: an inline queued-message edit was dropped silently when its message left the queue (deleted, sent elsewhere, edit hold rejected, or a 404 on save). A sent-message edit was also dropped when its message left the timeline; that case showed a warning toast, but the edited text was still lost.

Credit: found through T3 Code's fixes for the same bug, pingdotgg/t3code#35102 and #32732.

What changed

  • @bb/client-core: mergeUnsentPromptDraft(unsent, current) puts the unsent draft first, then a blank line, then whatever is in the composer now. It shifts the newer mentions by the new offset, dedupes attachments by path, and does nothing if the composer already holds the same draft.
  • usePromptDraftStorage: a new controller method restoreUnsent and one shared sendPromptDraft(controller, submittedDraft, send) helper: clear if current matches, run the send, and on failure merge the draft back (only if this call cleared it). All four send paths now go through it, so none of them restores the draft on its own anymore. restoreIfEmpty is renamed seedIfEmpty because initial-prompt seeding is now its only use, so it can't be mistaken for failure recovery.
  • Queued-message edits: the edit session remembers its starting draft. If the message leaves the queue, the edit hold is rejected, or saving finds it gone, a changed edit is merged into the thread composer and a warning toast says so ("Your queued message edit is in the composer"). Unchanged edits still close quietly.
  • Sent-message edits (ThreadScreen): if the edited message leaves the timeline, a changed edit is merged into the thread composer the same way, guarded against running twice.

The failure toast text is unchanged. The message now reappears in the composer, so I didn't add more wording to the toast. There are no wire, CLI or settings changes.

How you verified

Live repro on origin/main (02264cf) with pnpm dev and a fresh data dir, a fixture thread, and headless Chrome via dev-browser. Puppeteer request interception held POST /api/v1/threads/:id/send:

  1. Typed FIRST message that the user sent, pressed Enter (the request was held and the composer cleared), typed SECOND draft typed while sending, then aborted the request (net::ERR_FAILED).
    • main: composer = SECOND draft typed while sending; the first message was gone from the composer and from localStorage; toast "Failed to send message".
    • this branch: composer = FIRST message that the user sent\n\nSECOND draft typed while sending (also persisted).
  2. Opened the inline editor on a scheduled queued message, changed it to fixture plus my EDITED words, then deleted the message from another client (bb thread queue delete).
    • main: the editor vanished, the edit was lost, and no toast appeared.
    • this branch: composer = fixture plus my EDITED words\n\nnewer composer text, with a warning toast.

Tests (each new or updated case fails against main's composer sources and passes here; 15 failures in ThreadDetailPromptArea.test.tsx on main):

  • ThreadDetailPromptArea.test.tsx: the existing "serializes … without losing edits" matrix (ordinary/modifier × same callback/remount/sibling) used to assert the lossy result (draft = only the newer edit). It now asserts the merge. Added a test for a failed handoff merged back with real storage, and queued-edit tests for leaving the queue, no changes, and a 404 on save.
  • ThreadScreen.test.tsx: a changed sent-message edit moves into the composer when its message leaves the timeline.
  • usePromptDraftStorage.test.tsx: sendPromptDraft success, failure-with-newer-text, and never-cleared cases.
  • client-core/test/prompt-draft.test.ts: merge order, mention offsets, attachment dedupe, idempotence.

Commands: pnpm exec turbo run lint typecheck --filter=@bb/app --filter=@bb/client-core, pnpm exec turbo run test --filter=@bb/client-core, and the targeted @bb/app test files above.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 18, 2026 12:44
Every composer send path cleared the draft before awaiting the request and,
on failure, restored it only into an empty composer. Text typed while the
request was pending silently replaced the failed message. Queued-message and
sent-message edits were likewise dropped when their message disappeared.

Route the thread follow-up, shortcut, handoff and new-thread sends through
one sendPromptDraft helper that merges the unsent draft ahead of anything
typed since. Edits whose queued or sent message disappears now move into
the composer with a warning instead of vanishing. restoreIfEmpty is renamed
seedIfEmpty because only initial-prompt seeding still uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ymichael
ymichael merged commit c9e3e88 into main Nov 18, 2026
37 checks passed
@ymichael
ymichael deleted the bb/never-lose-a-message-when-a-send-fails-thr_enbyak9n2z branch November 18, 2026 21:56
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