Open MercatoDocsSearch docsAPI reference

User guide

Signals

Use a signal when a run must wait for information coming from outside its current step. Match the signal to the waiting instance so the right case resumes.

Typical sources include webhooks, payment notifications and an approval from another application.

What Are Signals?

A signal is a named event sent from outside the workflow engine to resume execution. Workflows can wait for signals at WAIT_FOR_SIGNAL steps, allowing them to pause until an external system confirms an action.

Key Concepts:

Use Cases

Common Scenarios:

WAIT_FOR_SIGNAL Step

Configure a step to wait for a specific signal:

{
  "stepId": "wait-for-payment",
  "stepName": "Wait for Payment Confirmation",
  "stepType": "WAIT_FOR_SIGNAL",
  "signalConfig": {
    "signalName": "payment-confirmed",
    "timeout": "7 days"
  }
}

Configuration:

When the workflow reaches this step:

  1. Workflow status becomes "WAITING_FOR_SIGNAL"
  2. Execution pauses until signal is received or timeout expires
  3. Signal payload is merged into workflow context
  4. Workflow resumes and advances to the next step

Sending Signals

External systems send signals via the REST API:

API Endpoint

POST /api/workflows/instances/{instanceId}/signal

Request Body

{
  "signalName": "payment-confirmed",
  "payload": {
    "transactionId": "txn_abc123",
    "amount": 150.00,
    "paidAt": "2024-01-15T10:30:00Z",
    "paymentMethod": "credit_card"
  }
}

Example: cURL

curl -X POST https://your-domain.com/api/workflows/instances/wf-inst-123/signal \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access-token>" \
  -d '{
    "signalName": "payment-confirmed",
    "payload": {
      "transactionId": "txn_abc123",
      "amount": 150.00
    }
  }'

Example: TypeScript/JavaScript

import { apiFetch } from '@open-mercato/ui/backend/utils/api'

async function sendPaymentSignal(instanceId: string, transactionId: string) {
  const response = await apiFetch(`/api/workflows/instances/${instanceId}/signal`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      signalName: 'payment-confirmed',
      payload: {
        transactionId,
        amount: 150.00,
        paidAt: new Date().toISOString()
      }
    })
  })

  if (!response.ok) {
    throw new Error('Failed to send signal')
  }

  return await response.json()
}

Signal Payload

Signal payloads are merged into the workflow context, making the data available to subsequent steps.

Before Signal:

{
  "orderId": "order-123",
  "customerId": "cust-456",
  "amount": 150.00
}

Signal Sent:

{
  "signalName": "payment-confirmed",
  "payload": {
    "transactionId": "txn_abc123",
    "paidAt": "2024-01-15T10:30:00Z"
  }
}

After Signal (Merged Context):

{
  "orderId": "order-123",
  "customerId": "cust-456",
  "amount": 150.00,
  "transactionId": "txn_abc123",
  "paidAt": "2024-01-15T10:30:00Z"
}

Access signal data in subsequent steps: {{context.transactionId}}

Correlation Keys

Correlation keys help external systems identify which workflow instance to signal.

Setting Correlation Key:

When starting a workflow, provide a correlation key:

POST /api/workflows/instances
{
  "workflowId": "order-fulfillment-v1",
  "initialContext": {
    "orderId": "order-123",
    "customerId": "cust-456"
  },
  "correlationKey": "order-123"
}

Finding Instance by Correlation Key:

External systems can query workflows by correlation key:

GET /api/workflows/instances?correlationKey=order-123

This returns the instance ID, which is used to send signals:

POST /api/workflows/instances/{instanceId}/signal
{
  "signalName": "payment-confirmed",
  "payload": { ... }
}

Use Cases:

Signalling every instance with a key:

POST /api/workflows/signals sends the signal to every paused instance that shares the correlation key. The response reports how many instances advanced and, per instance, every delivery that failed:

{
  "success": true,
  "message": "Signal sent to 2 workflow(s)",
  "count": 2,
  "failures": [
    { "instanceId": "…", "code": "WORKFLOW_NOT_PAUSED", "message": "Workflow is not paused" }
  ]
}

Duplicate and Concurrent Delivery

A paused instance is advanced by exactly one delivery of a signal. When the same signal arrives more than once at the same time – a webhook retried by its sender, at-least-once event delivery, a double-clicked action – the first delivery claims the instance and the others are refused:

A correlation-key delivery is addressed to the wait each instance was parked on when it was listed. If a concurrent delivery has already moved the instance on to a later wait – even one waiting for the same signal name – the late delivery is refused the same way instead of consuming that later wait.

The same holds when a workflow loops back to the wait it was parked on. Each time an instance parks, that occurrence of the wait is distinct from the previous one: a delivery that found the instance parked on the earlier occurrence is refused even if it only gets to claim it after the loop has parked the instance on the same step again. A signal sent once the instance is parked on the new occurrence is a new delivery and advances it.

An occurrence only ends when the instance leaves its wait. Edits that keep the instance parked on the same step – an SLA attention marker, a context or metadata update – do not start a new occurrence, so a delivery that found the instance parked still advances it.

A refused delivery changes nothing. A 409 means the instance is no longer parked on the wait the delivery found – another delivery advanced it, or the run moved on (for example it was cancelled) – so a sender retrying a signal it already sent can treat it as "this wait no longer needs the signal". A delivery that fails before anything of it is recorded hands the wait back, so retrying it delivers the signal rather than being refused.

Example: Order Fulfillment with Payment Webhook

Here's a complete workflow that waits for payment confirmation:

Workflow Steps:

  1. START → Create order
  2. Send Payment Link (AUTOMATED) → Email payment link to customer
  3. Wait for Payment (WAIT_FOR_SIGNAL) → Wait for "payment-confirmed" signal
  4. Fulfill Order (AUTOMATED) → Ship items, send confirmation email
  5. END → Workflow complete

Step Configuration:

{
  "stepId": "wait-for-payment",
  "stepName": "Wait for Payment Confirmation",
  "stepType": "WAIT_FOR_SIGNAL",
  "signalConfig": {
    "signalName": "payment-confirmed",
    "timeout": "7 days"
  }
}

Payment Gateway Webhook:

When payment is confirmed, the payment gateway calls your webhook endpoint:

// Your webhook handler
app.post('/webhooks/payment', async (req, res) => {
  const { orderId, transactionId, amount } = req.body

  // Find workflow instance by correlation key (orderId)
  const instances = await fetch(
    `/api/workflows/instances?correlationKey=${orderId}`
  ).then(r => r.json())

  if (instances.length === 0) {
    return res.status(404).json({ error: 'Workflow not found' })
  }

  const instance = instances[0]

  // Send signal to resume workflow
  await fetch(`/api/workflows/instances/${instance.id}/signal`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      signalName: 'payment-confirmed',
      payload: {
        transactionId,
        amount,
        paidAt: new Date().toISOString()
      }
    })
  })

  res.status(200).json({ success: true })
})

Workflow Execution:

  1. Customer places order → Workflow starts with correlationKey: "order-123"
  2. Workflow sends payment link → Customer receives email
  3. Workflow waits at WAIT_FOR_SIGNAL step
  4. Customer pays → Payment gateway calls webhook → Webhook sends signal
  5. Signal resumes workflow → Order is fulfilled

Timeout Handling

If a signal is not received within the timeout period, the workflow can be configured to:

Configure timeout behavior with transitions:

{
  "transitionId": "timeout-to-cancelled",
  "fromStepId": "wait-for-payment",
  "toStepId": "end-cancelled",
  "trigger": "timer",
  "timerConfig": {
    "duration": "7 days"
  }
}

Best Practices

For Workflow Designers

For External Systems

For Administrators

Next Steps

See Also:

Previous: Monitoring Workflows · Next: Step Types