Repository navigation
fix(messages): keep failed sends only for inbox messages, log the rest - #1749
Merged
Merged
Conversation
A failed outgoing message stayed in the conversation with "Failed to send" whatever sent it, so automated sends (flows, triggers, AI, keyword replies, comment automation, broadcasts) cluttered the inbox with bot errors. Now only a message a member sends from the builder Inbox (composer, flow, template, booking link, call-permission request, Resend) is kept with its error. Every other send is hard-deleted on its final failure and a new `messageRemoved` realtime event drops it from the open timeline; the error reaches the Error Log through the existing `message:failed` listener (broadcast and sequence sends stay out of it, as before). - `sendFrom` is now "inbox" | "api": builder actions pass "inbox", the public API and order notifications pass "api"; the six existing comparisons treat both alike (`isManualSend`), so send behaviour is unchanged. Rows sent from the Inbox carry `sentFromInbox` so retries and late delivery-status failures apply the same rule. - One settle function for sendMessageToChannel, flow steps, both template senders, delivery-status failures, quota skips and queueing failures. - Template retries no longer leave a duplicate row per attempt, and a failed template is no longer left looking delivered. - AI comment private replies and the SMTP email step now write Error Log rows. - `hardDeleteById` removes the message and its attachments (the existing delete is soft and renders as "The message has been deleted"). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…essages hardDeleteById swallowed every shard error and returned [], so callers published messageRemoved for a delete that never happened and the row reappeared after a reload. It now deletes the attachments and the message in one transaction per shard, tries every shard, and throws if any failed; the worker and createOutgoing already log that and skip the realtime event. A late "failed" delivery status carries no sendFrom, so an Inbox message sent before the sentFromInbox marker existed was removed as if automated. createOutgoing and the template senders now stamp sentFromInbox true/false, and a member's message with no stamp at all is kept (isLegacyMemberMessage). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
…t (#1749) * fix(messages): keep failed sends only for inbox messages, log the rest A failed outgoing message stayed in the conversation with "Failed to send" whatever sent it, so automated sends (flows, triggers, AI, keyword replies, comment automation, broadcasts) cluttered the inbox with bot errors. Now only a message a member sends from the builder Inbox (composer, flow, template, booking link, call-permission request, Resend) is kept with its error. Every other send is hard-deleted on its final failure and a new `messageRemoved` realtime event drops it from the open timeline; the error reaches the Error Log through the existing `message:failed` listener (broadcast and sequence sends stay out of it, as before). - `sendFrom` is now "inbox" | "api": builder actions pass "inbox", the public API and order notifications pass "api"; the six existing comparisons treat both alike (`isManualSend`), so send behaviour is unchanged. Rows sent from the Inbox carry `sentFromInbox` so retries and late delivery-status failures apply the same rule. - One settle function for sendMessageToChannel, flow steps, both template senders, delivery-status failures, quota skips and queueing failures. - Template retries no longer leave a duplicate row per attempt, and a failed template is no longer left looking delivered. - AI comment private replies and the SMTP email step now write Error Log rows. - `hardDeleteById` removes the message and its attachments (the existing delete is soft and renders as "The message has been deleted"). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(messages): fail a hard delete loudly and keep pre-marker member messages hardDeleteById swallowed every shard error and returned [], so callers published messageRemoved for a delete that never happened and the row reappeared after a reload. It now deletes the attachments and the message in one transaction per shard, tries every shard, and throws if any failed; the worker and createOutgoing already log that and skip the realtime event. A late "failed" delivery status carries no sendFrom, so an Inbox message sent before the sentFromInbox marker existed was removed as if automated. createOutgoing and the template senders now stamp sentFromInbox true/false, and a member's message with no stamp at all is kept (isLegacyMemberMessage). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Deathgiver <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Behaviour by send source
sendError+messageFailed(unchanged)Only the final failure settles a row. Non-Inbox sends no longer write
sendErroron every retry attempt.How
sendFromis now"inbox" | "api"(packages/utils/src/send-from.ts). Builder actions and the session-onlymessages/api/private.tsroute pass"inbox"; the public APIs andorder/service.tspass"api".createOutgoing,resendOutgoing,sendInboxBookingLink,requestWhatsappCallPermissionand the inbox template sender require it. The six existingsendFromcomparisons (messaging policy, inbox send confirmation, quick replies) useisManualSend(), which treats both values alike, so how messages are sent does not change.sendFrom: "inbox"getcontentAttributes.sentFromInbox(isSentFromInboxinpartials/message.ts), so retries and late delivery-status failures apply the same rule.settleFailedOutgoingMessageinsend-message.ts, used bysendMessageToChannel, flow steps, both template senders,message-status.ts,record-quota-skipped-send.tsand createOutgoing's queueing failure.hardDeleteByIdin the sharded repository andmessageService.hardDeleteremove the message and its attachment rows. The existing delete is soft and renders as "The message has been deleted".messageRemovedevent. The chat store'sremoveMessagesdrops the rows and repoints the open conversation's preview.docs/failed-outgoing-messages.md(linked from AGENTS.md),docs/comment-automation.md, and the public API descriptions formessages.create,sendWhatsappTemplate,resendandcontacts.sendMessage.Known limits
messageRemoved.Test plan
pnpm lintpnpm check-types(67/67)pnpm --filter worker test: 393 files, 5283 tests🤖 Generated with Claude Code