Skip to navigation

Receiving External Events

View as MarkdownOpen in Claude

There Is No Webhook Receiver To Build

Remediation Orchestrator has no webhook receiver. The script-launch API is already an authenticated HTTP endpoint that starts a workflow from a JSON body. An external system points at it, and a Starlark script turns the incoming event into a specialized action.

The HTTP API, workflow runtime, argument parsing, idempotency, and circuit breaker stay generic; the script is the only place that knows what the source is, what its payload means, and what to do about it.

A node health monitor is the running example.

The Pattern At A Glance

POST /api/v1/script/{name}/{function} Authenticate, parse args by docstring type Start or reuse workflow by workflow_id 202 Accepted { workflow_id } Validate payload, take specialized action Hand off through an existing workflow path Repair and decide the terminal state Access token + JSON body External system Remediation Orchestrator script API Starlark workflow Downstream handoff

The external system makes one authenticated POST. Remediation Orchestrator starts or reuses a workflow and returns 202 immediately; everything after the response runs asynchronously on Temporal.

The Request Contract

The endpoint is the generic script entrypoint, the same route the Run Workflow dialog uses.

POST /api/v1/script/{script_name}/{function}?tenant={tenant}
Authorization: Bearer <access-token>
Content-Type: application/json
{ "field": "value" }
PartContract
Method and routePOST /api/v1/script/{script_name}/{function}. script_name is the uploaded script (for example monitor.star); function is a registered workflow entrypoint in it. A script in a folder is named by its path from scripts/, so send its slashes as %2F, for example integrations%2Fmonitor.star.
tenant querySelects the tenant whose scripts and modules handle the request.
Auth headerA short-lived access token from the deployment’s identity provider. See Authentication And Provisioning for which header carries it.
BodyA single flat JSON object. Keys map to the entrypoint parameters by name; values are coerced to the types declared in the function docstring. Capped at 1 MB; larger bodies are rejected with 413.
Optional headersX-Maestro-Cluster-ID and X-Maestro-Datacenter-ID set workflow context when a deployment still needs them. Most node-scoped integrations leave them unset.

A success returns 202 Accepted:

{ "workflow_id": "monitor/node-001" }

202 means the workflow started, not that the work finished. Treat the body as a handle for status and correlation, not a result.

Errors worth handling on the caller side:

StatusMeaning
400 Bad RequestThe script name or entrypoint does not exist, or the body is not valid JSON.
413 Request Entity Too LargeThe body is larger than 1 MB.
429 Too Many RequestsMax-concurrency limit hit, or the circuit breaker is open. Back off and retry later.
503 Service UnavailableThe entrypoint is disabled.
500 Internal Server ErrorThe workflow failed to start for another reason.

Write The Receiving Script

A receiving script defines one entrypoint function and registers it. Two rules carry the contract:

  • The docstring declares each argument and type in Google style (name: type, description). Remediation Orchestrator uses it to coerce the JSON body and reject mismatched types.
  • The function returns a dict describing what it did. That dict is recorded with the workflow and shown to operators inspecting the run. Declare the return type in the docstring as dict: description so workflow queries can validate the result.

A minimal receiver:

def handle_event(entity_id, signal_name, event_id):
"""
Args:
entity_id: string, the entity this workflow acts on (node, cluster, job, and so on).
signal_name: string, name of the external signal.
event_id: string, unique occurrence id from the source.
Returns:
dict: what the workflow did.
"""
if entity_id.strip() == "":
fail("entity_id must be set")
# ... take a specialized action here ...
return {"action": "handled", "entity_id": entity_id}
wf = register_workflow(handle_event)

That accepts POST /api/v1/script/<script_name>/handle_event. register_workflow takes optional callbacks the next sections use:

ArgumentPurpose
workflow_functionThe entrypoint. Required.
workflow_idReturns the workflow ID for a given payload. This is the idempotency lever.
on_failureCalled when the workflow fails. Receives the same arguments plus the error history.
on_cancel, queryHooks for cancellation handling and status queries.
max_concurrencyCaps concurrent runs of this workflow.

Worked Example: A Node Health Monitor

The monitor detects node health signals (link-down, NVLink bandwidth loss, symbol errors) and, while a node stays unhealthy, posts a fresh alert every minute. The script drains the node so the existing breakfix flow picks it up.

The monitor calls:

POST /api/v1/script/monitor.star/drain_from_monitor?tenant=default
Authorization: Bearer <access-token>
Content-Type: application/json

with this body:

FieldRequiredMeaning
node_idyesSlurm node hostname the signal is about.
signal_nameyesStable monitor signal or alert name.
event_idyesUnique monitor alert occurrence ID.
severitynoSignal severity.
observed_atnoEvent timestamp, RFC3339.
summarynoShort human-readable summary.
event_urlnoLink back to the monitor event.

The entrypoint validates the required fields, builds a drain reason, looks up the node, and drains it. Only the required fields drive behavior; the rest is metadata for humans.

def drain_from_monitor(node_id, signal_name, event_id, severity = "", observed_at = "", summary = "", event_url = ""):
"""
Args:
node_id: string, Slurm node hostname reported by the monitor.
signal_name: string, Monitor node signal or alert name.
event_id: string, Unique monitor alert occurrence ID recorded in the drain reason.
Kwargs:
severity: string, Monitor signal severity.
observed_at: string, Monitor event timestamp in RFC3339 format.
summary: string, Short human-readable event summary.
event_url: string, Link to the monitor event.
Returns:
dict: drain action and reason details.
"""
_require_non_empty("node_id", node_id)
_require_non_empty("signal_name", signal_name)
_require_non_empty("event_id", event_id)
reason = "[MONITOR] %s; %s%s" % (signal_name, MONITOR_EVENT_MARKER_PREFIX, event_id)
...
slurm.drain_node(node.node_id, reason, wait_for_sync = True)

The drain reason carries the [MONITOR] source tag plus the originating event_id.

State the source plainly in whatever the action leaves behind (a drain reason here, a cordon note or ticket body elsewhere). Name the source it came from; do not borrow another subsystem’s vocabulary, since a health-check-looking reason that never came from a health check would mislead whoever reads it next. Let the downstream flow decide what the tag means.

Idempotency For Real-Time Sources

A real-time source does not retry deliveries; it keeps sending new events while a condition persists. The monitor posts a new event_id every minute for the same node. Without idempotency, each post starts another workflow.

Remediation Orchestrator deduplicates by workflow ID: while a workflow with a given ID is running, a new start for that ID reuses it instead of starting a second, and does not count against the circuit breaker. The workflow_id callback chooses the key. Scope it to the entity being worked on, not the event:

def _monitor_workflow_id(node_id, signal_name, event_id, severity = "", observed_at = "", summary = "", event_url = ""):
return "monitor/%s" % node_id

Two consequences:

  • Repeated posts for the same entity return the same workflow_id and do no extra work while it is handled (the monitor’s minute-by-minute posts for one node collapse onto a single workflow).
  • Once the entity is resolved and the workflow ends, a later post is a genuine new occurrence and starts a fresh workflow (a node that returns to service and later fires again gets a new run).

The event_id stays in the drain reason for traceability, but it is not the key. Putting a per-occurrence identifier (such as the monitor’s per-minute event_id) in the workflow ID defeats dedupe and causes a workflow storm.

A Working POST Is Not Enough

A 202 only means the workflow started. The integration is safe only when the downstream workflow’s terminal behavior is valid for the signal. A 202 says nothing about whether the entity was repaired, quarantined, or sent back to service unchanged.

The Boomerang

A transient signal often will not reproduce when the downstream flow re-checks the entity at pickup, because that check only sees the entity’s state at validation time, not the state when the signal fired. The drain is real and the flow picks up the entity, but the check finds nothing wrong, so the entity passes, returns to service unfixed, and the source fires again.

Node health monitors show this directly. Most of their signals are transient (a port flaps, bandwidth drops for a window), and breakfix validates with point-in-time health checks, so the condition is usually gone by the time the node is re-checked.

The plumbing works; the outcome is wrong. A signal the downstream flow does not handle specially gets default treatment, which can run standard validation and return the entity to service.

What To Decide Before Enabling

Decide the terminal state for the source’s signals before enabling in production:

  • Auto-repair, but only for signals backed by a reproducing check or a concrete remediation action?
  • Hold or quarantine the entity for a human owner instead of letting standard validation pass it?
  • Teach the downstream flow the source tag so it applies a signal-specific policy instead of the default path?

Decide the terminal behavior before you enable. The receiving script’s job is only to deliver a truthful event. Until the terminal behavior is settled, keep the integration disabled, and do not call it automatic repair.

Surface Asynchronous Failures

Because the response returns at 202 and the workflow runs afterward, a post-start failure is invisible to the caller. Without a hook, the only trace is in Temporal history, which no external operator watches.

Register an on_failure handler that notifies wherever the integration’s owners actually watch (Slack here, a pager or ticket queue elsewhere). It receives the original arguments plus the error history, so it can report which event failed and why:

def failure_handler(node_id, signal_name, event_id, error = None, errors = None, severity = "", observed_at = "", summary = "", event_url = ""):
"""Report a failed monitor drain workflow to the integration's owners.
Args:
node_id: string, Slurm node hostname reported by the monitor.
signal_name: string, Monitor node signal or alert name.
event_id: string, Unique monitor alert occurrence ID.
Kwargs:
error: string, The most recent error from the failed workflow.
errors: list[string], Every error recorded for the failed workflow.
severity: string, Monitor signal severity.
observed_at: string, Monitor event timestamp in RFC3339 format.
summary: string, Short human-readable event summary.
event_url: string, Link to the monitor event.
"""
message = "Monitor drain workflow failed for node %s: %s. signal_name=%s event_id=%s" % (
node_id,
error or "unknown error",
signal_name,
event_id,
)
if errors:
message = "%s errors=%s" % (message, " | ".join(errors))
slack.send_message(message, channel = MONITOR_FAILURE_SLACK_CHANNEL, use_thread_for_workflow = True)
wf = register_workflow(
drain_from_monitor,
workflow_id = _monitor_workflow_id,
on_failure = failure_handler,
)

The handler needs its own docstring. Remediation Orchestrator drops positional arguments the docstring does not declare. Every keyword argument the original workflow receives must also be declared in the handler’s docstring and signature; an undeclared keyword argument makes the handler fail before it runs, so no failure alert is sent. error and errors are passed only when declared as string and list[string].

The handler succeeds even though the workflow failed: that is what converts a silent Temporal failure into a message the right people see.

Authentication And Provisioning

The caller sends an access token from the deployment’s identity provider on every request. The header depends on the deployment’s authentication setup, described in Appendix B of the deployment checklist:

DeploymentHeader
Built-in Dex profile or OIDC bearer ingressAuthorization: Bearer <access-token>

The deployment owner tells the caller which identity provider issues its tokens and authorizes the caller to access the Remediation Orchestrator API for the target environment. This is a deployment configuration change, separate from the script. Tokens are short-lived, so mint a fresh one and cache it until it expires rather than requesting one per event.

For quick manual testing, you can also copy a ready-to-use token from the Profile page in the Remediation Orchestrator UI (user menu, then Profile), if a token is shown, instead of minting one. The page also shows when the token expires and a sample curl command. The token is tied to your own session, so use it for one-off curl checks, not for a standing integration.

Where To Go Next