Skip to content

Registration transition can duplicate messages sent by single submission #11212

Description

@dianabarsan

Describe the bug
There was an intermittently failing e2e test that revealed this: #10874

Recently I added some debug logging to show which messages were failing the assertions, to assess whether the failures were valid or not. Turn out they were.

This is a document that has two messages that have been sent, even though it should have only one:

{
  "_id": "019ef473-67f7-788a-a9c9-8418ed375bce",
  "_rev": "3-782006900c440c850ae937ca7e24f698",
  "type": "data_record",
  "from": "duplicate-phone",
  "form": "SICK",
  "errors": [],
  "tasks": [
    {
      "messages": [
        {
          "uuid": "019ef473-6827-788a-a9c9-a2262033916b",
          "to": "duplicate-phone",
          "message": "Await further instructions"
        }
      ],
      "state_history": [
        {
          "state": "pending",
          "timestamp": "2026-06-23T12:27:44.555Z"
        },
        {
          "state": "forwarded-to-gateway",
          "timestamp": "2026-06-23T12:27:45.060Z"
        }
      ],
      "state": "forwarded-to-gateway"
    },
    {
      "messages": [
        {
          "uuid": "019ef473-68d9-7ee7-9e4a-8c0f65f1e345",
          "to": "duplicate-phone",
          "message": "Await further instructions"
        }
      ],
      "state_history": [
        {
          "state": "pending",
          "timestamp": "2026-06-23T12:27:44.744Z"
        },
        {
          "state": "forwarded-to-gateway",
          "timestamp": "2026-06-23T12:27:45.060Z"
        }
      ],
      "state": "forwarded-to-gateway"
    }
  ],
  "fields": {},
  "reported_date": 1782217664503,
  "sms_message": {
    "type": "sms_message",
    "message": "SICK",
    "form": "SICK",
    "from": "duplicate-phone",
    "gateway_ref": "019ef473-6668-7000-8677-3ea41fde2fe0"
  }
}

So something is processing these messages twice. This could be a race condition between api and sentinel running the same transition twice over the same doc, but that needs to be confirmed.

Run where this failure happened: https://github.com/medic/cht-core/actions/runs/28024101918/job/82950853099#step:18:3058

Expected behavior
Registration transition should not add messages twice.

Environment

  • Instance: CI
  • App: api/sentinel

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugFix something that isn't working as intended

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions