Skip to content

fix(comment-automation): stop silent failures in FB comment auto-reply - #706

Merged
sung17 merged 1 commit into
mainfrom
fix/comment-automation-silent-failures
Jul 8, 2026
Merged

sung17 merged 1 commit into
mainfrom
fix/comment-automation-silent-failures

Conversation

@sung17

@sung17 sung17 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Facebook comment automations could silently stop replying on production despite correct config, with zero error trace — this fixes 4 concrete bugs found while auditing the full webhook → automation → send pipeline against origin/main.
  • Fixes 3 permanent-failure bugs: a fixed BullMQ jobId per 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 a replyToCommentId that got silently overwritten to null on a DB lookup miss.
  • Fixes 2 silent-drop bugs: only the first feed change per webhook entry was processed (dropping batched comments), and unrecognized feed payloads / missing contactInbox lookups failed with no log line.

Changes

  • apps/worker/src/integration/handlers/received-message.ts — remove a stale failed processCommentAutomation job (same jobId) 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 when contactInbox lookup misses instead of returning silently.
  • apps/worker/src/chat/handlers/send-message.ts — fall back to the existing replyToCommentId instead of forcing null when the parent-comment lookup misses.
  • integrations/messenger/src/handlers/webhook.ts — iterate all feed changes in a webhook entry (not just the first); log unrecognized feed payloads instead of dropping them silently.
  • packages/worker-config/src/lib/connection.ts — add getJob to the build-time fakeQueue stub so the new job-cleanup check type-checks.

Test plan

  • npx biome check on all 5 changed files
  • pnpm --filter worker check-types
  • pnpm --filter @chatbotx.io/integration-messenger check-types
  • full pnpm typecheck via pre-commit hook (all 49 packages pass)
  • manual verification on a comment automation with "reply once per user/post" enabled: force a transient send failure, confirm retry still delivers the reply
  • manual verification: send a webhook batch with 2+ feed changes, confirm both comments land in the inbox

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.
@github-actions github-actions Bot added the bug Something isn't working as expected label Jul 8, 2026
@sung17
sung17 merged commit 5be73aa into main Jul 8, 2026
8 checks passed
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

1 inactive deployment
dev — fa7b4d75 Deployed Jul 8, 2026 by sung17 via Build builder #1795
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant