User guide
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.
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:
Common Scenarios:
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:
signalName: The signal to wait for (must match exactly)timeout: Maximum wait time (e.g., "7 days", "2 hours")When the workflow reaches this step:
External systems send signals via the REST API:
POST /api/workflows/instances/{instanceId}/signal
{
"signalName": "payment-confirmed",
"payload": {
"transactionId": "txn_abc123",
"amount": 150.00,
"paidAt": "2024-01-15T10:30:00Z",
"paymentMethod": "credit_card"
}
}
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
}
}'
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 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 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" }
]
}
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:
POST /api/workflows/instances/{instanceId}/signal answers 409 (WORKFLOW_NOT_PAUSED) for the refused deliveries.POST /api/workflows/signals lists them under failures with the code WORKFLOW_NOT_PAUSED.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.
Here's a complete workflow that waits for payment confirmation:
Workflow Steps:
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:
correlationKey: "order-123"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"
}
}
See Also: