Skip to content

fix(mobile): restore the composer message when a send fails (port #3785) - #3787

Merged
trunk-io[bot] merged 1 commit into
mainfrom
posthog-code/mobile-restore-composer-on-send-failure
Jul 27, 2026
Merged

fix(mobile): restore the composer message when a send fails (port #3785)#3787
trunk-io[bot] merged 1 commit into
mainfrom
posthog-code/mobile-restore-composer-on-send-failure

Conversation

@Gilbert09

Copy link
Copy Markdown
Member

Problem

On the mobile task composer, a failed send silently lost the user's work. handleSend cleared the typed text and attachments and fire-and-forgot the send; when handleSendPrompt rejected (network/API error) it only logged and showed a "Failed to send" alert — the message and any picked attachments were already gone.

Changes

Ports the desktop behaviour from #3766 and #3785 (fix(agent): preserve messages until send succeeds and its follow-up fix: clear sent messages without blocking the composer) to the mobile app.

  • The send path now reports success/failure back to the composer: onSend / handleSendPrompt return Promise<boolean> across every branch — queued-message edit, terminal-session resend, queue mode, steer/interrupt, and the normal send.
  • The composer still clears optimistically on submit and stays responsive — sending is not blocked and typing is not disabled while a send is in flight.
  • On failure the submitted text and attachments are restored into the composer, but only when the composer is still empty (the user hasn't started a new draft) and only when the failed submission is still the latest one (guarded by a monotonically increasing submission id, so a stale failure can't clobber a newer draft).
  • The clear/restore decision logic is factored into a small pure helper module (submitComposerMessage.ts) so it is unit-testable without rendering React Native components.
  • Existing behaviour is preserved: queued-message in-place editing, the pendingPromptRecoveryStore new-task recovery flow, haptics, keyboard dismissal, and trackPromptSent analytics.

How did you test this?

  • Added Vitest coverage for the new pure helpers (submitComposerMessage.test.ts): successful send clears and stays cleared; failed send restores text + attachments; failed send does not restore when a new draft has been typed; a stale failure does not clobber a newer submission; isComposerEmpty cases.
  • pnpm --filter @posthog/mobile test — full mobile suite, 494 tests passing.
  • Typechecked the changed files and confirmed zero new type errors vs. the base tree.
  • biome check clean on the changed files.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

Previously the mobile task composer cleared the typed text and attachments on
submit and fire-and-forgot the send. A failed send (network/API error) only
logged and showed an alert — the user's message and any picked attachments were
lost.

The send path now reports success/failure back to the composer across every
branch of handleSendPrompt (queued-message edit, terminal-session resend, queue
mode, steer/interrupt, and normal send). The composer still clears immediately
and stays responsive; on failure it restores the submitted text and attachments,
but only when the composer is still empty (the user hasn't started a new draft)
and the failed submission is still the latest one (guarded by a monotonic
submission id). The decision logic lives in a small pure helper module with
Vitest coverage.

Ports desktop PRs #3766 and #3785 to the mobile app.

Generated-By: PostHog Code
Task-Id: d27aba44-dcf9-4ed7-b588-128490732718
@Gilbert09
Gilbert09 requested a review from a team July 24, 2026 10:52
@trunk-io

trunk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 028ca90.

@trunk-io
trunk-io Bot merged commit f632bfb into main Jul 27, 2026
28 checks passed
@trunk-io
trunk-io Bot deleted the posthog-code/mobile-restore-composer-on-send-failure branch July 27, 2026 14:07
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.

2 participants