Skip to content

feat(messages): track and surface send failures across channels - #946

Merged
sung17 merged 1 commit into
mainfrom
feat/message-send-error-status
Aug 13, 2026
Merged

sung17 merged 1 commit into
mainfrom
feat/message-send-error-status

Conversation

@sung17

@sung17 sung17 commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • When the channel API (Messenger/WhatsApp/Zalo/TikTok/Instagram/Telegram) fails to deliver an outgoing message, the message previously stayed persisted and looked "sent" with no failure indication anywhere.
  • Adds a nullable Message.sendError column, persists/clears it around the shared sendMessageToChannel send path (agent-composed and bot/flow-composed messages alike), and surfaces it in the inbox UI.
  • Fixes several follow-up gaps found in code review: stale error after a successful retry, a race between the messageFailed and messageCreated realtime events, and bot-originated sends not being tracked at all.

Changes

  • packages/database/src/schema/message.ts + sharded mirror/migrations — new nullable sendError column (migration generated, not yet applied — needs explicit approval per repo convention).
  • packages/database/src/repositories/message/message-repository.ts + sharded repository — updateSendError method.
  • apps/worker/src/chat/handlers/send-message.ts — persists/clears sendError on send failure/retry-success, broadcasts a new messageFailed realtime event, shared broadcastChatEvent helper, caps error length at 500 chars.
  • apps/worker/src/chat/handlers/send-flow-step.ts — bot/flow-originated sends now record sendError the same way as inbox-composed messages.
  • apps/worker/src/chat/worker.ts — passes job.attemptsMade through so a successful retry can clear a prior error.
  • packages/partysocket-config/src/schemas.ts — new RealtimeEventMessageFailed event type (clientId + nullable error).
  • apps/builder/src/features/chat/store/chat-store.ts + chat-realtime.tsx — markMessageFailed matches by clientId first (falls back to id) to avoid losing the error to a race with messageCreated; preserves sendError across the optimistic-message swap.
  • apps/builder/src/features/messages/components/message-item.tsx — small icon next to outgoing failed messages; error text only shown in a hover tooltip. New sendFailed i18n key added to all 19 language files.
  • apps/worker/__tests__/send-message-handler.test.ts — new tests for the failure/clear-on-retry paths.

Test plan

  • pnpm --filter @chatbotx.io/database check-types
  • pnpm --filter worker check-types
  • pnpm --filter builder check-types
  • pnpm lint
  • pnpm --filter worker exec vitest run __tests__/send-message-handler.test.ts (15/15 passing)
  • Manual: send a message on a channel with a broken/expired token, confirm the icon + tooltip appear and a later successful retry clears it
  • DB migration review + explicit approval before running db:migrate / db:migrate-shards

Previously an outgoing message stayed looking "sent" even when the
channel API (Messenger/WhatsApp/Zalo/TikTok/Instagram/Telegram) failed
to deliver it — no status was persisted and the UI showed nothing.

- add nullable Message.sendError column (+ sharded schema mirror and
  migrations, not yet applied)
- sendMessageToChannel persists the error and broadcasts a new
  messageFailed realtime event; clears it if a BullMQ retry later
  succeeds
- sendFlowStepToChannel (bot/flow-originated sends) now records
  failures the same way as inbox-composed messages
- chat-store matches messageFailed by clientId first (falls back to
  id) to avoid losing the error to a race with the messageCreated
  broadcast, and preserves it across the optimistic-message swap
- message bubble shows a small icon next to outgoing failed messages;
  the error text only appears in a hover tooltip
@github-actions github-actions Bot added the feature New feature or request label Aug 13, 2026
@sung17
sung17 merged commit 7cb00ce into main Aug 13, 2026
8 checks passed
viethung0o0 pushed a commit that referenced this pull request Sep 7, 2026
Previously an outgoing message stayed looking "sent" even when the
channel API (Messenger/WhatsApp/Zalo/TikTok/Instagram/Telegram) failed
to deliver it — no status was persisted and the UI showed nothing.

- add nullable Message.sendError column (+ sharded schema mirror and
  migrations, not yet applied)
- sendMessageToChannel persists the error and broadcasts a new
  messageFailed realtime event; clears it if a BullMQ retry later
  succeeds
- sendFlowStepToChannel (bot/flow-originated sends) now records
  failures the same way as inbox-composed messages
- chat-store matches messageFailed by clientId first (falls back to
  id) to avoid losing the error to a race with the messageCreated
  broadcast, and preserves it across the optimistic-message swap
- message bubble shows a small icon next to outgoing failed messages;
  the error text only appears in a hover tooltip

Co-authored-by: Deathgiver <[email protected]>

This branch was previously deployed

1 inactive deployment
dev — 57ba58d8 Deployed Aug 13, 2026 by sung17 via Build builder #2360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant