Skip to content

resend-sync marks a user synced before adding them, so an interrupted run loses that user permanently #553

Open

Description

@aivong-openhands

Summary

resend-sync marks a user as synced before adding them to Resend. If the process dies between those two steps, that user is never added to the audience and never gets a welcome email, because every later run skips them as already synced.

Details

In sync_users_to_resend:

  1. L442 skips any email already in synced_emails, which is loaded from resend_synced_users.
  2. L455 mark_user_synced(...) commits the claim row (ON CONFLICT DO NOTHING on uq_resend_synced_email_audience).
  3. L468 add_contact_to_resend(...). If it raises, L476 removes the claim, so the user is retried next run.
  4. L486 send_welcome_email(...). Failures are logged and ignored.

The rollback in step 3 only covers an exception. If the process is killed after step 2 and before step 3 finishes (OOM, eviction, deploy, node loss, or SIGKILL after the termination grace period), the claim row stays, and the user is skipped in step 1 on every future run. A kill between steps 3 and 4 leaves the user in the audience with no welcome email, and nothing retries it.

The job sleeps for rate limiting between users (L483, L495), so a run can take a long time, which makes a kill mid-run more likely.

Impact

  • One user per interrupted run. That user never joins the audience, or never gets the welcome email, and nothing surfaces it.
  • Off by default. The job is disabled in the chart by default, so this affects only deployments that enable it.

Proposed fix

Record progress per user rather than claiming up front:

  • Add a status to resend_synced_users: pending, then added, then welcomed.
  • Skip only users that reached added, or welcomed for the email step.
  • Treat pending rows older than a threshold as retryable.

add_contact_to_resend should be safe to repeat for an email already in the audience; confirm that against the Resend API. A simpler alternative is to write the claim only after add_contact_to_resend succeeds, accepting a possible duplicate add if a concurrent run races, since the unique constraint still limits the claim to one row.

Activity

  1. added
    bug
    on Sep 28, 2026
  2. all-hands-bot commented on Nov 10, 2026

    @all-hands-bot
    Contributor

    [Automatic Post]: This issue has had no activity for 42 days (labels: bug). Could someone take a look when they have a chance and help figure out next steps?

    Generated by OpenHands automation on behalf of the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions