Skip to content

fix: stop repeated DMs after ambiguous Meta delivery errors - #68

Open
dada878 wants to merge 1 commit into
diwenne:mainfrom
dada878:fix/stop-ambiguous-dm-resends
Open

dada878 wants to merge 1 commit into
diwenne:mainfrom
dada878:fix/stop-ambiguous-dm-resends

Conversation

@dada878

@dada878 dada878 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Meta can return error code 1 after a comment reply has reached the recipient. The worker currently treats that unknown result as a button-template rejection, sends a text fallback, and logs the comment as retryable. The polling reconciler then creates fresh jobs every five minutes; each job resets DmLog.attempts from its own BullMQ counter. A single comment can therefore produce repeated messages indefinitely.

This change claims the DM and public-reply legs atomically in DmLog before contacting Instagram. Unknown/network outcomes and failed result writes retain the claim, while explicit rejections release it. DM attempts are counted durably across jobs and capped at three; polling also skips uncertain and exhausted deliveries, including historical Meta code 1/2/5xx failures. New comments continue normally, without pausing campaigns.

Plain-text fallback now requires a specific Meta code 100 template/button rejection and preserves the fallback's own error if that second send is uncertain. Meta postbacks also use the existing durable per-tap claim, as Zernio postbacks already do.

This deliberately favors avoiding duplicates after an uncertain outcome or a process crash between claiming and sending. Inspect the inbox before manually retrying those deliveries. No schema migration is required. The change is based on current main (5760181) and contains no saved-template feature changes.

Validation:

  • Four focused regression cases fail on unmodified main: ambiguous Meta response, reset attempt budget, missing pre-send claim, and redelivered Meta postback.
  • npm run typecheck, npm run lint, and npm run build pass.
  • TEST_DATABASE_URL=... npm test: 312 tests pass in 28 files, including real PostgreSQL tests in disposable schemas for simultaneous claims, persistent attempt limits, and independent public/DM claims.
  • Worker/poller tests cover successful delivery followed by failed database writes, ambiguous fallback outcomes, historical failures, and continued processing of new comments.

@vercel

vercel Bot commented Sep 22, 2026

Copy link
Copy Markdown

@dada878 is attempting to deploy a commit to the diwenne's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant