Get alerted when one of your automations fails

Notify the owner and email the team when another automation fails for good. A validated automation.run_failed@1 definition.

When one of your automations breaks, hear about it the same hour instead of finding it a month later in the history. Trigger: automation.run_failed@1. Actions: notify_me@1 and send_internal_email@1.

Model background: Automations.

The definition

{
  "schemaVersion": 1,
  "trigger": {
    "type": "automation.run_failed@1",
    "origins": [
      "USER",
      "API",
      "MCP",
      "ASSISTANT",
      "BULK",
      "IMPORT",
      "DUPLICATE",
      "SYSTEM",
      "AUTOMATION"
    ],
    "filter": {
      "op": "all",
      "rules": [
        {
          "path": "event.facts.run.status",
          "op": "eq",
          "value": "FAILED"
        },
        {
          "path": "event.facts.run.retriesExhausted",
          "op": "eq",
          "value": true
        }
      ]
    }
  },
  "steps": [
    {
      "id": "tell",
      "type": "action",
      "contract": "notify_me@1",
      "input": {
        "title": "An automation failed: {{automation.name}}",
        "message": "A run of {{automation.name}} ended {{run.status}} with the code {{run.errorCode}}. Open Settings, Automations, then History, to see which step failed."
      }
    },
    {
      "id": "mail",
      "type": "action",
      "contract": "send_internal_email@1",
      "input": {
        "recipientUserIds": ["user_REPLACE_WITH_TEAM_MEMBER_ID"],
        "subject": "Automation failed: {{automation.name}}",
        "body": "A run of {{automation.name}} ended {{run.status}}. Error code: {{run.errorCode}}. Check its history in Settings, Automations.",
        "includeEntityLink": false
      }
    }
  ]
}

Replace user_REPLACE_WITH_TEAM_MEMBER_ID with the id of a team member who may manage automations. The notice goes to the people who manage automations in the dashboard; the email goes only to the people you name.

How it works

  • automation.run_failed@1 fires once per run of one of the store's automations that ends FAILED (a permanent error, or the retries ran out: run.retriesExhausted is true) or NEEDS_REVIEW (the engine cannot tell whether the action happened, or the run stalled).
  • Its facts: event.facts.automation.id, event.facts.automation.name (the name you gave the automation), event.facts.run.status (FAILED or NEEDS_REVIEW), event.facts.run.errorCode (a closed engine code such as RETRIES_EXHAUSTED), event.facts.run.retriesExhausted, event.facts.run.triggerType (what started the failed run, for example order.paid@1) and event.facts.run.failedContract (the action that failed, for example send_http_request@1).
  • No value is ever a fact. Not the order, not the step's input or output, not the error message. The alert tells you which automation and how it ended; the details are in that automation's history.
  • A text may use {{automation.name}}, {{run.status}} and {{run.errorCode}}.
  • The entity is the store, like the clock, but the trigger is not a schedule and takes no schedule block. There is no order, customer or product to act on, so only three actions run under it: notify_me@1, send_internal_email@1 and send_http_request@1. A wait, a fetch step and a for_each loop are refused, and so is every order, customer or product action.
  • The filter above keeps only runs that failed for good: FAILED with the retries used up. Remove the second rule to also hear about a permanent error, and drop the first to also hear about NEEDS_REVIEW. To watch one automation only, add a rule on event.facts.automation.id.

What it does not do

  • It does not fire for a run that is SKIPPED. A condition that was not met, a configuration problem and a plan quota are not failures, and a configuration problem already raises its own notice in the dashboard.
  • It does not fire when a store HTTP connection is switched off by the circuit breaker. That is a connection, not a run.
  • A run that was itself started by this trigger never fires it again, so an alert that fails cannot start another alert. The failure of any other automation of the store fires it, including a run deep in a chain.
  • It does not tell you what was in the failed order or step. Those values are never in the facts.
  • It needs a plan that includes automations, like every automation.

One failure, many alerts

A store whose automation fails on every order raises one event per failed run, so it can raise many alerts in an hour. The usual hourly action limits apply to the alert automation itself. To keep it quiet, filter on run.status or on automation.id, and send one email to a shared inbox rather than one per person.

Create it

With the Admin MCP:

  1. get_automation_guide with topic: "triggers", then "messages".
  2. validate_automation_definition. Fix every finding.
  3. test_automation with entity: { "type": "Store", "id": "<the store id>" }. The test runs a sample failure: the automation name and the error are examples, and nothing is saved or sent.
  4. create_automation_draft with name: "Automation failure alert".
  5. Tell the merchant to approve it in the dashboard.

With the SDK:

const check = await admin.validateAutomationDefinition(storeId, { definition });
if (!check.ok) throw new Error(JSON.stringify(check.errors));

const draft = await admin.createAutomation(storeId, {
  name: 'Automation failure alert',
  definition,
});

What the merchant sees

A draft in Settings, then Automations. Once on, each run that fails for good starts a run of this automation: the notice arrives in the dashboard and the email goes to the people you chose. The history of this automation shows one row per alert, about the store rather than about an order.