Repository navigation
fix(comment-automation): stop silent failures in FB comment auto-reply - #706
Merged
Merged
Conversation
Facebook comment automations could stop replying permanently on production despite correct config, with no error trace: - processCommentAutomation was keyed by a fixed jobId per comment; once it failed twice it sat in BullMQ's failed set, so a Facebook webhook redelivery for that comment became a permanent no-op. Now checks for and removes a failed job with the same id before re-enqueuing. - The "reply once per user per post" dedup row was written before the reply was actually dispatched. A transient send failure (network, rate limit) permanently blocked that contact/post from ever getting an automated reply. Dedup insertion now happens only after a configured reply channel dispatches without throwing. - sendMessageToChannel overwrote an already-correct contentAttributes.replyToCommentId with null when the parent-comment lookup missed, causing a silently swallowed PAYLOAD_INVALID error. Now falls back to the existing value instead of nulling it. - The webhook handler only processed the first "feed" change per entry, dropping every other comment when Facebook batched multiple changes into one delivery. Now iterates all feed changes. - Feed payloads that fail schema validation, and comment automations skipped because their contactInbox lookup missed, are now logged instead of failing silently.
5 tasks
viethung0o0
pushed a commit
that referenced
this pull request
Sep 7, 2026
#706) Facebook comment automations could stop replying permanently on production despite correct config, with no error trace: - processCommentAutomation was keyed by a fixed jobId per comment; once it failed twice it sat in BullMQ's failed set, so a Facebook webhook redelivery for that comment became a permanent no-op. Now checks for and removes a failed job with the same id before re-enqueuing. - The "reply once per user per post" dedup row was written before the reply was actually dispatched. A transient send failure (network, rate limit) permanently blocked that contact/post from ever getting an automated reply. Dedup insertion now happens only after a configured reply channel dispatches without throwing. - sendMessageToChannel overwrote an already-correct contentAttributes.replyToCommentId with null when the parent-comment lookup missed, causing a silently swallowed PAYLOAD_INVALID error. Now falls back to the existing value instead of nulling it. - The webhook handler only processed the first "feed" change per entry, dropping every other comment when Facebook batched multiple changes into one delivery. Now iterates all feed changes. - Feed payloads that fail schema validation, and comment automations skipped because their contactInbox lookup missed, are now logged instead of failing silently. Co-authored-by: Deathgiver <[email protected]>
This branch was previously deployed
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
origin/main.jobIdper comment that permanently blackholes retries after 2 failures, a "reply once per user/post" dedup row written before the send was attempted (permanently locking out a contact after any transient failure), and areplyToCommentIdthat got silently overwritten tonullon a DB lookup miss.feedchange per webhook entry was processed (dropping batched comments), and unrecognized feed payloads / missingcontactInboxlookups failed with no log line.Changes
apps/worker/src/integration/handlers/received-message.ts— remove a stale failedprocessCommentAutomationjob (samejobId) before re-enqueuing, so a Facebook webhook redelivery can actually retry.apps/worker/src/integration/handlers/comment-automation/index.ts— move dedup insertion to after a configured reply channel dispatches without throwing; log a warning whencontactInboxlookup misses instead of returning silently.apps/worker/src/chat/handlers/send-message.ts— fall back to the existingreplyToCommentIdinstead of forcingnullwhen the parent-comment lookup misses.integrations/messenger/src/handlers/webhook.ts— iterate allfeedchanges in a webhook entry (not just the first); log unrecognized feed payloads instead of dropping them silently.packages/worker-config/src/lib/connection.ts— addgetJobto the build-timefakeQueuestub so the new job-cleanup check type-checks.Test plan
npx biome checkon all 5 changed filespnpm --filter worker check-typespnpm --filter @chatbotx.io/integration-messenger check-typespnpm typecheckvia pre-commit hook (all 49 packages pass)feedchanges, confirm both comments land in the inbox