Skip to main content

Workflow runner

The workflow runner executes a workflow for you. You send a plan of steps, each one a message to an agent registered on the gateway, and the gateway runs the steps in order or as a dependency graph, passes each step's answer to the steps after it and records everything as a workflow run. Steps can target A2A agents and custom agents.

The runner is part of the gateway and needs a database. Run state lives in the database and every replica takes part, so the steps of a run keep going when one replica restarts.

The workflow runner needs a Spanway enterprise license that includes the workflow_runner feature. Without it every /v1/workflows/runner and /v1/workflows/runs route answers 403 and the gateway does not run steps. The plain workflow runs storage API needs the same feature.

Scenario​

Every Monday an on-call lead collects last week's incidents for the checkout service and writes a summary for the leadership meeting. With the workflow runner, a two step run does it. The first step asks a research agent for the incidents, the second asks a writer agent for the summary, each with its own budget and timeout. If the research agent is rate limited the step retries on its own, and if the writer fails the lead sees exactly which step stopped and resumes it instead of starting over.

Steps​

  1. Register the agents the steps call, an A2A agent on the Agents page and a custom agent on its Custom agents tab.

  2. In the Admin UI open Workflow Runs under Agentic and click Start run. Pick Run as key, give a Workflow type of incident-summary, set Run budget (USD, optional) to 2, add two steps with Add step, pick A2A agent or Custom agent as the Step type, fill Agent id, Message, Budget (USD) and Timeout (s) for each, and click Start run. The same run from the API looks like this.

    curl -X POST http://localhost:4000/v1/workflows/runner/start \
    -H "Authorization: Bearer sk-my-key" -H "Content-Type: application/json" \
    -d '{
    "workflow_type": "incident-summary",
    "input": {"service": "checkout"},
    "mode": "sequential",
    "run_budget_usd": 2.0,
    "steps": [
    {"key": "research", "target": {"kind": "a2a_agent", "agent_id": "research-agent"},
    "message": "List the incidents for {{input.service}} in the last week", "budget_usd": 1.0},
    {"key": "write", "target": {"kind": "custom_agent", "custom_agent_id": "writer-agent"},
    "message": "Write a short summary of: {{steps.research.output}}", "budget_usd": 0.5}
    ]
    }'
  3. Follow the run. Click its row on the Runs tab to open the run drawer with each step's status, or poll GET /v1/workflows/runner/runs/{run_id}/steps.

  4. If a step fails for good, open the Dead letters tab, read the error and click Requeue after fixing the cause, or call POST /v1/workflows/runner/runs/{run_id}/resume.

  5. Open the run in the run ledger from the drawer's link to see every model request, tool call and the spend per step.

Expected result​

The start call answers 200 with the run and its steps.

{
"run": {"run_id": "run_01J...", "session_id": "ses_01J...", "workflow_type": "incident-summary", "status": "running", "mode": "sequential", "run_budget_usd": 2.0},
"steps": [
{"step_key": "research", "position": 0, "target_kind": "a2a_agent", "target_id": "research-agent", "status": "running", "attempt": 1, "budget_usd": 1.0, "spend_usd": 0.0},
{"step_key": "write", "position": 1, "target_kind": "custom_agent", "target_id": "writer-agent", "status": "pending", "attempt": 0, "budget_usd": 0.5, "spend_usd": 0.0}
]
}

Each step turns succeeded with its output, the run ends completed with the outputs of the last steps, and the run drawer shows the same steps with their spend. A failed step leaves the run failed with the step's error code, and a resume runs only the unfinished steps.

Start a run​

curl -X POST http://localhost:4000/v1/workflows/runner/start \
-H "Authorization: Bearer sk-my-key" -H "Content-Type: application/json" \
-d '{
"workflow_type": "incident-summary",
"input": {"service": "checkout"},
"mode": "sequential",
"run_budget_usd": 2.0,
"steps": [
{"key": "research", "target": {"kind": "a2a_agent", "agent_id": "research-agent"},
"message": "List the incidents for {{input.service}} in the last week", "budget_usd": 1.0},
{"key": "write", "target": {"kind": "custom_agent", "custom_agent_id": "writer-agent"},
"message": "Write a short summary of: {{steps.research.output}}", "budget_usd": 0.5}
]
}'

The response is the run with its steps, all pending. The runner picks the steps up within a couple of seconds. Follow them with GET /v1/workflows/runner/runs/{run_id}/steps.

FieldMeaning
steps[].keyLowercase name of the step, unique in the run
steps[].target{"kind": "a2a_agent", "agent_id": ...} or {"kind": "custom_agent", "custom_agent_id": ...}. Use the agent's id, not its name
steps[].messageThe text sent to the agent, up to 32,000 characters
steps[].depends_onSteps that must succeed first, only in dag mode
steps[].budget_usdSpend limit of the step
steps[].timeout_secondsHow long one attempt may take, 1 to 3,600, default 300
steps[].total_timeout_secondsOptional limit for every attempt of the step together, backoff included, up to 86,400 and at least timeout_seconds. See retries
steps[].retryThe step's retry policy. Without one a step runs once
steps[].tool_identityshared (the default) or triggering_user, only on a custom_agent step. See per-user credentials
modesequential (each step waits for the one before it) or dag
run_budget_usdOptional limit for the whole run. The step budgets must fit inside it
max_parallelSteps of this run that may run at the same time, 1 to 16, default 4
deadline_secondsNo attempt starts after the deadline, 60 to 86,400, default 3,600
run_as_keyOnly for dashboard sessions, see below
on_failureWhat happens when the run fails, see on failure. Its budget comes out of run_budget_usd

Metadata keys that start with trigger_ or workflow_definition_ are reserved for the gateway, which sets them on runs started by its own triggers and by workflow definitions. A request that sets one is refused with a 422.

A plan is checked before anything is stored. Duplicate keys, unknown dependencies, cycles and a message that uses the output of a step that does not run before it are refused with a 422 that names the step.

Retrying a start safely​

Send an Idempotency-Key header (1 to 255 printable ASCII characters) to make a start safe to retry. A second start from the same virtual key with the same key and the same body returns the first run instead of starting another, with the response header Idempotent-Replayed: true. The same key with a different body is refused with a 422. Keys are scoped to the virtual key that runs, so two keys never see each other's runs. A retry returns the first run even when the agent was halted or disabled after it started, because the gateway looks for the earlier run before checking the agents again. Dashboard sessions are the exception, and their ownership of run_as_key is checked first.

Messages and step outputs​

A message can use two kinds of placeholders. {{input.<path>}} reads the run input, and {{steps.<key>.output}} is the answer of an earlier step. Nothing else is evaluated. A placeholder without a value fails the step instead of sending a message with a gap in it.

Treat step outputs as untrusted input. One agent's answer becomes part of the next agent's prompt, so an agent that can be talked into writing instructions can pass them on. Only chain agents you would let read each other's output, and keep write tools on the steps that need them. Outputs are stored and passed on up to 32,000 characters, and longer answers are cut with a marker.

Which key a run uses​

Every step runs as one virtual key, so the key's model and agent permissions, guardrails, rate limits, budgets and spend attribution apply to every call a step makes. A key that starts a run is that key. A dashboard session expires long before a run may finish, so a session names one of its user's own keys in run_as_key. The master key cannot start runs.

The runner reloads the key from the database before every attempt and runs the same checks the gateway applies to a request. A key that was deleted, blocked or expired, an owner deactivated through SCIM, a blocked team or organization, a route the key may not call or an exhausted key, user, team or organization budget stops the step with actor_revoked or actor_over_budget, and the run fails. The key's IP allow list is checked when the run is started. Later attempts come from the gateway itself, so there is no client address to check.

Per-user credentials​

By default a custom agent step calls its MCP tools with whatever credential each MCP server is set up with, which may be one shared API key or service account. Set "tool_identity": "triggering_user" on a custom_agent step to make every MCP tool call of that step use the stored credential of the user who started the run instead, either their own BYOK key or their own OAuth sign-in for the server. The user connects those first, the same way they would to call the tool themselves.

The step fails closed. Before each attempt the runner checks that the run's key still belongs to the user recorded when the run started, and fails the step with user_credential_missing when the key has no user or now belongs to someone else. Each tool call then checks that it runs as that user. A server that only has a shared credential, such as a static API key, static headers or an OAuth client credentials grant, refuses the call with shared_credential_refused, and a server the user never connected refuses it with user_credential_missing. The agent sees the refusal as a failed tool call. Servers without any credential and token exchange servers, which always act for the calling user, work as usual. One user's credential is never looked up for another user's run, and a replay of the step keeps the setting, so it cannot fall back to a shared credential. Sub-workflows run as the parent's key, so they keep the same user.

Only custom agent steps take the setting, because an A2A agent is called over the network and uses its own credentials. It needs the workflow_runner and custom_agents license features, like every custom agent step.

What is checked before each attempt​

On whichever replica picks the step up, the runner checks, in this order:

  • the run was not cancelled and its deadline has not passed,
  • the run's key can still run (above),
  • the agent exists, is the kind the step names, has no kill switch halt and is enabled,
  • the run's key may call the agent,
  • the step and the run are under budget.

Only then is the message sent. A step that fails one of these checks is never sent.

Budgets​

A step's spend is the larger of two numbers. One is the sum of the cost every attempt of the step reported, failed and timed out attempts included. The other is what the gateway logged with the run's own key under the step's trace id and under the run ids of the custom agent runs the step started. The Steps view, the dead letter view and the budget check all read this same number. Spend is checked before every attempt, so a step or run at its budget starts no further attempt. A call already in flight is not stopped, so a run can go over by the attempts that were running when the limit was reached (at most max_parallel of them) plus spend not yet written to the spend logs. The key's own budgets are enforced on every call as usual.

Every attempt is told what it may still spend, the smaller of what is left of the step's budget and of the run's. A custom agent step runs the custom agent in the gateway and caps the custom agent's own run budget at that amount, so the custom agent stops itself before it can spend more than the step has left (it can go over by the one model call in flight, as its limits describe). An A2A agent receives the amount as spanway_budget_remaining_usd in the call metadata, as advice only. Spend a remote agent makes without going through the gateway, or through the gateway under its own key, is not counted against the step, because the gateway cannot see it. Agents that send their own model calls through the gateway with the run's key and the x-spanway-trace-id header they receive have those calls counted toward the step.

Retries and timeouts​

Retries need the workflow_retries license feature on top of workflow_runner. A start that sets a retry policy other than the default, a total_timeout_seconds or an on_failure without it is refused with a 403. Without a policy a step runs once, because agents can have side effects.

{"key": "write", "target": {"kind": "custom_agent", "custom_agent_id": "writer-agent"},
"message": "Write a short summary of: {{steps.research.output}}", "budget_usd": 0.5,
"timeout_seconds": 120, "total_timeout_seconds": 600,
"retry": {"max_attempts": 3, "initial_backoff_seconds": 2, "max_backoff_seconds": 60,
"retry_on": ["transport_error", "rate_limited"]}}
FieldMeaning
max_attempts1 to 5, default 1
initial_backoff_secondsWait before the first retry, 0.5 to 300, default 2
max_backoff_secondsLongest wait, 1 to 3,600, default 60, at least initial_backoff_seconds
retry_onWhich failures are retried, default transport_error and rate_limited

retry_on can list transport_error (the agent could not be reached or answered with a 5xx), rate_limited (a 429), timeout (no answer within timeout_seconds), agent_error (the agent answered with an error or a failed task, which usually means the request itself is wrong) and lease_lost (the replica running the attempt stopped responding). timeout and lease_lost are not retried by default, because the agent may already have done its work. Every other failure, such as a budget refusal, a revoked key or the kill switch, is never retried and cannot be listed.

The wait before attempt n+1 uses equal jitter. The runner takes min(max_backoff_seconds, initial_backoff_seconds × 2^(n-1)), waits half of it, and adds a random share of the other half, so a retry never fires at once while retries of many runs still spread out. When the agent sends a Retry-After header in seconds that is longer, the runner waits that long instead, up to max_backoff_seconds. A retry of an A2A agent always waits at least PROXY_BATCH_WRITE_AT plus 5 seconds, so the spend of the failed attempt is in the spend logs before the next budget check.

A retry is refused, and the step fails, when:

  • the failure is not in retry_on, with the failure's own code,
  • the step used max_attempts, with the failure's own code,
  • the step or run budget is spent, or the failed attempt cost more than what is left, with budget_exhausted,
  • the retry would start after the step's total_timeout_seconds ran out, with timeout, or after the run's deadline, with run_deadline.

An attempt never runs past the step's total timeout or the run's deadline. Its timeout is the shortest of timeout_seconds, what is left of the step's total timeout and what is left before the run's deadline, and an attempt cut short by either deadline fails with timeout or run_deadline instead of being retried. The total timeout counts from the step's first attempt, and a resume starts it again.

The runner does not wait for a replica to pick up an expired run. Each replica sweeps runs whose deadline passed every few seconds, skips the steps that have not started, fails a step that was waiting for its retry with run_deadline, stops running steps and fails the run.

Every attempt of an A2A agent step sends an idempotency_key in the message metadata. Retries of a step share it and a resume or requeue changes it, so an agent can recognize an operation it already performed. Custom agent steps do not get one yet, because their tool calls have no field to carry it, so keep max_attempts at 1 for a custom agent with write tools unless those tools are safe to repeat.

An A2A agent can answer with a task that is not finished yet. The runner then polls tasks/get every two seconds until the task ends, within the step's timeout. A task that asks the caller for input fails the step, since there is nobody to answer, and a task that ends failed or canceled fails it too. A custom agent run that stops at its step limit, its budget or a model error answers with a failed task, so the step fails instead of passing the stop message on as an answer.

A step that ends for good while polling sends tasks/cancel to the agent. That is a cancel, a kill switch, another step failing or the step's own timeout. A step whose replica lost its lease or is shutting down does not cancel the remote task, because another replica may take the step over.

Each step sends a stable messageId. It changes only when the step is retried after a known failure, so an agent that remembers message ids can recognize a resend after a replica crash.

When a step fails​

The runner fails fast. When a step fails, the steps that have not started are skipped, steps still running are stopped, and the run ends failed. The step shows an error code and lands in the dead letters.

CodeMeaning
agent_not_foundNo agent with that id that the run's key can see, or not the kind the step names
agent_disabledThe agent is disabled
kill_switchThe agent's kill switch fired. The step shows as blocked
not_allowedThe run's key may not call the agent
actor_revoked / actor_over_budgetThe run's key can no longer run. A budget refusal from the gateway during a call is actor_over_budget and is never retried
budget_exhaustedThe step or run reached its budget
timeoutNo answer within timeout_seconds
rate_limited / transport_error / agent_errorThe agent call failed
run_deadlineThe run passed its deadline
lease_lostThe replica running the last attempt stopped responding and the policy does not retry lost leases
cancelled / dependency_failedThe run was cancelled, or another step failed

Dead letters​

A step that fails for good, as failed or blocked, gets one dead letter per generation of the step. Cancelled steps and the steps a failure skipped do not. A dead letter points at the run, the step and its attempts instead of copying them, so it holds no content of its own. It is deleted with its run, so maximum_workflow_run_retention_period and data subject erasure cover it. Dead letter routes need the workflow_retries feature.

curl "http://localhost:4000/v1/workflows/runner/dead_letters?state=open" -H "Authorization: Bearer $SPANWAY_KEY"
curl "http://localhost:4000/v1/workflows/runner/dead_letters/$DEAD_LETTER_ID" -H "Authorization: Bearer $SPANWAY_KEY"

The list returns ids, the step key, the error code, the attempt count and the state (open, requeued or discarded), newest first, 50 at a time with a next_cursor. It takes state (default open, or all for every state) and workflow_type. The detail adds the step's attempts without their content, the last error text (the fixed description of the code for a metadata_only run), the step's spend and a run_ledger_url.

POST /v1/workflows/runner/dead_letters/{dead_letter_id}/requeue resumes the run exactly as resume does, with the same checks and the same body, and marks the run's open dead letters requeued. The failed step, the steps it held back and any cancelled siblings run again in a new generation. Spend already made still counts against the step and run budgets, so a step that failed with budget_exhausted fails again until it is started as a new run with a larger budget. POST /v1/workflows/runner/dead_letters/{dead_letter_id}/discard marks one as handled and runs nothing, with an optional reason of up to 500 characters that is kept in the audit row. Both answer 409 for a dead letter that is no longer open, and both write an audit row against the dead letter.

On failure​

on_failure says what happens once when a run ends failed, whatever the cause, including a deadline, a budget, the kill switch or a revoked key. It does not fire for a cancelled run, because a person chose to stop it.

"on_failure": {"kind": "alert", "level": "High"}
"on_failure": {
"kind": "workflow",
"run_budget_usd": 0.5,
"alert": true,
"steps": [
{"key": "refund", "target": {"kind": "a2a_agent", "agent_id": "billing-agent"},
"message": "Refund task {{input.failure.succeeded_steps.charge.a2a_task_id}} because {{input.failure.step_key}} failed with {{input.failure.error_code}}",
"budget_usd": 0.5}
]
}

alert sends a workflow_run_failed alert. workflow starts a compensating run of up to 10 steps as the same virtual key, with its own mode, deadline_seconds (default 3,600) and run_budget_usd. Its steps are checked like the run's own, and their agents pass the same checks when the run starts. When the run has a run_budget_usd, the step budgets plus the on_failure budget must fit inside it, and the run's own steps may only spend what is left after that reserve, so the compensation always has money set aside. With alert: true (the default) the run also sends an alert, and a compensating run that fails sends one alert of its own and starts nothing further.

The compensating run is started in the same transaction that marks the run failed, so it starts exactly once per failure even when several replicas see the failure. Its input is {"failure": {...}} with the run id, the workflow type, the first failed step's key, error code and attempt count, and the A2A task id of every step that succeeded. It carries no step outputs and not the run's input, so pass on only what the compensation needs through those references. Its workflow type is the run's with :on_failure added, and it carries the run's capture mode and data subject. The compensating steps are kept on the run only until its content is purged or its data subject is erased, and a data subject export includes them.

Resuming or requeueing a run after its compensating run started answers 409, because the compensation may already have undone work the retry would redo. Send "acknowledge_compensation": true to run the failed steps again anyway. The acknowledgement is written to the audit row, and if the run fails again it starts a new compensating run.

Failure alerts​

workflow_run_failed alerts go through the gateway's alerting integrations. They are not in the default alert types, so add workflow_run_failed to general_settings.alert_types to receive them. An alert carries the run id, the failed step key, its error code and attempt count and the compensating run id, never error text, inputs or outputs. On Spanway Cloud these integrations belong to the operator, so a run that asks for an alert, through kind: alert or a workflow with alert left true, is refused with 422. Use a workflow with "alert": false there. One replica claims each alert before sending it, so it is sent at most once. A virtual key's runs send at most WORKFLOW_RUNNER_FAILURE_ALERTS_PER_ACTOR_HOUR (default 10) alerts an hour, and the rest are recorded as a run.failure_alert_suppressed event on the run.

Cancel, kill switch and resume​

POST /v1/workflows/runner/runs/{run_id}/cancel cancels the pending steps at once. Running steps are stopped by the replica running them at its next poll, a few seconds later, and the run ends cancelled when the last one stops. A step that finishes on its own after the cancel still counts, and a step that would have been retried is cancelled instead. If the replica running a stopped step dies, another replica marks the step stopped once its lease runs out.

Firing an agent's kill switch also halts the runner for that agent. The halt is stored, so every replica refuses the agent's next step, running steps on the agent stop, and their runs fail with kill_switch. The agent stays halted for the runner until a proxy admin calls POST /v1/workflows/runner/agents/{agent_id}/release. The kill switch also disables the agent and blocks its keys, but the runner halt is kept apart from that, so re-enabling the agent does not release it. If the runner tables cannot be written, the rest of the kill switch still runs, the response reports halted_workflow_runs: null and the error is logged.

POST /v1/workflows/runner/runs/{run_id}/resume runs a failed or cancelled run again. Steps that succeeded keep their output, and every other step starts again from attempt one in a new generation, still as the run's original key. The person resuming must be allowed to call every agent that will run again, the run's key must still be able to run, and no step may target a halted agent. deadline_seconds in the body sets a new deadline, and acknowledge_compensation is needed when the run's on failure workflow already started.

Sub-workflows​

A step with "target": {"kind": "workflow", ...} runs a saved workflow definition version as a child run instead of calling an agent. While the child runs the step is waiting. The step fails with workflow_not_found, workflow_halted, depth_exceeded, input_invalid, output_invalid, child_failed or child_cancelled when the child cannot start or does not complete. Cancel, resume and re-run apply to the root run only. On a sub-workflow run they answer 409.

Resuming a root run checks the person resuming against every agent left to run in the whole tree, including the agents of sub-workflow steps that have not started their child yet, and needs the workflow_subworkflows licence feature. A sub-workflow step whose replica stops while it starts the child is started again, up to the same small number of attempts as any other transient error while starting it. Purging a run's inputs and outputs, and erasing a data subject, also clear the inputs of its sub-workflow steps.

Several replicas​

Each replica polls for ready steps and claims one with a conditional update, so a step runs on one replica at a time. Claims for one run are serialized, so max_parallel holds across replicas. A replica keeps a lease on the steps it runs and renews it on its own heartbeat, three times per lease, separate from polling. A replica that has not renewed a step's lease for four fifths of lease_seconds, for example because the database is unreachable, stops that step itself and writes nothing, so it never races the replica that takes the step over. If a replica stops, the lease runs out after 30 seconds and another replica picks the step up. The new attempt runs only when the step's retry policy lists lease_lost, attempts are left and the budgets and deadlines allow it, and otherwise the step fails with lease_lost.

When the gateway shuts down it stops claiming new steps, and the graceful shutdown drain (GRACEFUL_SHUTDOWN_TIMEOUT) waits for the steps it is running as well as for in-flight requests. Steps still running when the drain times out are handed back to the queue before the process exits, without cancelling the agent's task, so another replica can take them over at once. A step handed back before its message reached the agent keeps its attempt.

An A2A step whose agent answers with a task that is still working records that task as soon as it sees it. When the replica running the step dies or hands it back at shutdown, the next replica polls the same task with tasks/get instead of sending the message again, and the attempt does not count toward max_attempts. That happens at most max_reclaims times per step, 3 by default, so a step that keeps killing its worker still runs out of attempts. If the agent no longer knows the task, the step fails with a retryable transport_error and the normal attempt rules apply. A step whose agent answered without a task, or that was cut off before the agent replied, is a new attempt like before. Custom agent steps are never resumed this way, so a custom agent step cut off mid-run is at most once until custom agent runs become resumable.

Rotating or regenerating a virtual key moves the runs that act as it to the new key, so in-flight runs keep running and their owner keeps seeing them.

Queue mode and workers​

By default every gateway and backend process runs steps. Queue mode moves step execution to dedicated worker processes, so long agent runs never share CPU with inference or the admin API and workers scale on their own. It needs a license with both the workflow_runner and workflow_queue_workers features.

The environment variable SPANWAY_WORKFLOW_RUNNER_ROLE picks the role of a process. embedded, the default, accepts runs and runs steps. producer accepts runs and serves every route but never runs steps. worker runs steps and serves only /health/liveliness, /health/readiness and /metrics. Start a worker by passing --workflow_worker --port 4002 after the image name, which sets the role for you, or start the image with the spanway-container worker command, which is what the Helm charts and the Terraform stacks do. Postgres stays the queue, so nothing else has to run, and no step content goes to Redis, metrics or worker rows.

A process refuses to start when its role is not one of the three, when it is a producer or worker without both the workflow_runner and workflow_queue_workers features, or when it is a worker with workflow_runner.enabled: false or no database. A worker that cannot work never reports ready.

The Helm chart, the monolith chart and the Terraform modules for AWS, GCP and Azure each have a workflowWorker or workflow_worker_* switch that adds a worker deployment and makes the other components producers, so the roles always agree.

Tenant limits​

Every run belongs to a tenant, its key's organization, else its team, else the key itself. A tenant may have at most default_tenant_max_running_steps steps running at once, 16 by default, and at most default_tenant_max_active_runs runs that are pending, running or paused, 200 by default. Both are checked in the same database transaction as the claim or the start, so concurrent workers or starts cannot overshoot them. A start or a resume beyond the active run limit answers 429 with a Retry-After header. On Spanway Cloud a plan can set its own workflow_max_running_steps and workflow_max_active_runs.

Ready steps are claimed fairly across tenants. Each poll takes the oldest ready steps of every tenant in turn, so a tenant with a long backlog cannot hold back a tenant with one step.

Metrics​

Each process that runs steps exports spanway_workflow_runner_steps_running, spanway_workflow_runner_saturation (running steps over capacity), spanway_workflow_runner_backlog_steps, spanway_workflow_runner_backlog_oldest_seconds, spanway_workflow_runner_backlog_per_worker, spanway_workflow_runner_claims_total by outcome, spanway_workflow_runner_fenced_total, spanway_workflow_runner_lease_renew_failures_total and spanway_workflow_runner_drain_released_total. None of them carries a tenant, run or agent label. spanway_workflow_runner_backlog_per_worker, ready steps over live workers, is the main autoscaling signal.

When the oldest ready step has waited longer than backlog_alert_seconds (300 by default) and no live process is running steps, for example because every worker is crash looping behind a producer only gateway, the runner raises a workflow_runner_backlog alert. It checks every minute, one pod sends it, and it repeats at most every 30 minutes. Without Redis each pod sends its own. The alert carries counts only.

GET /v1/workflows/runner/status shows the role of the process that answered, mode (queue while a live worker runs steps, else embedded), every live worker with its host, capacity, running steps and whether it is draining, and the ready step count with the age of the oldest one.

Size the database pool for max_concurrent_steps_per_pod times the worker count, since each running step holds a connection only while it writes but every worker polls and renews leases on its own.

Tracing and the run ledger​

Every step has its own trace id. The runner sends it as x-spanway-trace-id and as the session id of the call, so the gateway's spend logs carry it even when missing_session_id is omit, and the A2A agent receives it to attach its own traces. The messages the runner records for a step carry the same id. Each attempt also sends a W3C traceparent header whose trace id is the step's trace id written as 32 hex characters and whose span id is new for every attempt, so OpenTelemetry spans the agent emits land in the same trace. The call metadata carries workflow_attempt_id, which matches the attempt in the step history.

The run ledger for the run id shows the step calls, their spend, the run's events and its audit rows in one timeline. It looks up the Lens trace of the run and of every step (at most 50), so agent and tool spans of each step appear too.

Each step's spend is read from the spend logs of the run's own key only, so another key reusing a step's trace id cannot exhaust its budget. A step message is capped at 32,000 characters after the step outputs it uses are filled in.

A human approval policy can gate a step. The step then waits in awaiting_approval and the run in paused until someone decides, without holding a lease or using up an attempt, and a rejected or expired request fails the step.

The runner owns the status, events and messages of its runs. The generic PATCH /v1/workflows/runs/{run_id}, .../events and .../messages writes answer 409 for them, and reads work as before.

Step attempt history​

The runner keeps one row for every attempt of every step, and never rewrites an attempt once it has ended. A row records the attempt number, why it ran (initial, retry, reclaimed after another replica's lease ran out, resume, replay for a step a re-run runs again, or reused and pinned for a step a re-run or test run filled in without calling the agent), its outcome (succeeded, retrying, failed, blocked, cancelled, abandoned when its replica lost the lease, or reused and pinned), whether the agent was called at all, the error code, the cost the agent reported, the trace and span ids and the A2A task id. An attempt that a check refused before the agent was called, such as the kill switch or a revoked key, is recorded with invoked set to false. A resume starts a new generation, so attempt numbers restart from 1 without losing the earlier ones.

When the run keeps full content, the attempt also stores its message and the agent's answer, after credential shaped strings are redacted, encrypted with AES-256-GCM under a key derived with HKDF from SPANWAY_SALT_KEY (or the master key when that is unset), along with keyed digests and character counts. A metadata_only run stores character counts only, never content or digests. Without a salt or master key nothing is stored. A run that turns metadata_only midway, a run whose hold ends, and a user erased through a data subject request lose the stored attempt content at the same moment as the rest of the run's content. Attempts are deleted together with their run, so maximum_workflow_run_retention_period covers them.

Attempt content is encrypted with a key derived from SPANWAY_SALT_KEY when it is set, and from the master key otherwise. With a salt key set, rotating the master key through /key/regenerate leaves the stored content alone because its key does not change. Without one, the rotation re-encrypts the stored attempt content under the new master key, so restart the proxy with the new key right after rotating, since attempts captured in between stay under the old key and become unreadable. Content the old key can no longer open, for example after SPANWAY_SALT_KEY was changed by hand, is dropped during the rotation and shows as unreadable before that.

GET /v1/workflows/runner/runs/{run_id}/history returns every attempt grouped by step. It needs the workflow_history license feature as well as workflow_runner. Content is returned only with include_io=true, only for attempts captured in full, and only to the people who can see the run. A proxy admin or admin viewer reading the content of a run that is not theirs writes an exported audit row against the run.

curl "http://localhost:4000/v1/workflows/runner/runs/$RUN_ID/history?include_io=true" \
-H "Authorization: Bearer $SPANWAY_KEY"

Re-run from a step​

POST /v1/workflows/runner/runs/{run_id}/replay runs a stopped run again from one step as a new run linked to the original. The step and every step that depends on it, directly or through other steps, run again. Every other step is filled in with the output it had in the original run, without calling its agent, and costs nothing. The original run is left exactly as it happened, and its events record the replay. Resume keeps its meaning of continuing the same run. Re-running needs the workflow_history license feature as well as workflow_runner.

curl -X POST "http://localhost:4000/v1/workflows/runner/runs/$RUN_ID/replay" \
-H "Authorization: Bearer $SPANWAY_KEY" -H "Content-Type: application/json" \
-d '{"from_step": "write"}'

The new run acts as the caller's key with the same key rules as a start, so whoever re-runs a run pays for it under their own budgets and permissions, and every step that runs again goes through the agent checks for that key. A proxy admin can send "as_original_actor": true to run as the original run's key instead, which works only while that key is still valid and is audited as the admin acting for it. A re-run as the original key cannot use pins, so the admin's own pinned data never lands in a run that another user owns.

inputs defaults to {"kind": "original"}, which reuses the original run input, step messages and outputs. {"kind": "edited", ...} replaces them, with run_input, step_messages for steps that run again and upstream_outputs for steps that are reused. Edited messages are checked like a new plan, so a template that uses a step that does not run before it is refused. pins fills steps with pinned test data.

A re-run is refused with a 409 when the run is still running or has a step running, when it started before the gateway recorded its data policy, or when the original inputs it needs were removed because the run was metadata_only and its hold ended (send edited inputs instead). A reused step that did not succeed in the original run is refused with a 422 that names it, unless it is pinned or its output is in upstream_outputs. The caller's key must carry every data policy restriction the original run had (zero data retention, no training, code traffic rules), and a re-run of a metadata_only run is always metadata_only, otherwise the request is refused with a 409. The re-run names the same data subject as the original, so a data subject request reaches both. It keeps the original run's on_failure, which needs the workflow_retries license feature as it does on a start, and a re-run of a test_run is a test_run too. The response lists the new run with its replay_of_run_id, and which steps were reused, pinned and run again.

Pinned test data​

A pin is a step output you saved to use instead of calling the agent. POST /v1/workflows/runner/pins/new saves one from a succeeded attempt of one of your own runs whose output was kept, or as literal text.

curl -X POST "http://localhost:4000/v1/workflows/runner/pins/new" \
-H "Authorization: Bearer $SPANWAY_KEY" -H "Content-Type: application/json" \
-d '{"workflow_type": "triage", "step_key": "research", "source": {"kind": "attempt", "attempt_id": "att_01J..."}}'

Pin content is redacted for credential shaped strings and encrypted with the same key as attempt content, so pins also need a salt key or master key. A pin is kept only when content capture is on for the gateway (workflow_runner.capture_io and store_prompts_in_spend_logs) and for every key involved. A key whose data policy requires zero data retention, or whose policy cannot be read, cannot create pins, and neither can anyone pinning from a run whose key requires it. A dashboard session has no key of its own whose policy can be checked, so it can pin an attempt's output but not literal text. A pin from an attempt must name the workflow_type and step_key of that attempt, otherwise it is refused with a 422. A pin copied from an attempt keeps that run's data policy and data subject, so it can only be used by a key with the same restrictions and a data subject request for that user deletes it.

A start or a re-run takes pins, a map from step key to {"kind": "pin", "pin_id": ...}, {"kind": "attempt", "attempt_id": ...} or {"kind": "literal", "text": ...}. A pinned step is stored as succeeded with zero spend and its agent is never called. Pinning a step does not skip the steps before it, which still run unless they are pinned too, and pinning every step is refused. A pin saved for one workflow_type and step_key, and an attempt of one, can only fill that step of that workflow type. Every pin and reused step in a run must belong to the same data subject, otherwise the run is refused with subject_conflict, so a data subject request always reaches the run that holds that user's content. A run with a pinned step is marked test_run. Pins and attempts belong to whoever owns them, and anyone else gets a 404. GET /v1/workflows/runner/pins lists your pins without their content (admin viewers see every pin), and POST /v1/workflows/runner/pins/delete deletes one you own, or any pin for a proxy admin. Pins need the workflow_history license feature. They follow their key when it is rotated, and maximum_workflow_run_retention_period deletes them once they are older than it.

Who can do what​

ActionWho
Start a runAny role that can write, using a virtual key or a session naming one of the user's keys
See a run and its stepsThe run's key, any key or session of the same user, proxy admins and admin viewers
Cancel or resume a runThe run's key, the same user, or a proxy admin
See dead lettersThe run's key, any key or session of the same user, proxy admins and admin viewers
Requeue or discard a dead letterThe run's key, the same user, or a proxy admin
Re-run a run from a stepThe run's key, the same user, or a proxy admin, as the caller's own key
Create, use or delete a pinThe key or user that owns it, and a proxy admin can delete any pin
Release a halted agentProxy admins
Read the runner statusProxy admins and admin viewers

Admin viewers and internal user viewers can read but not start, cancel or resume runs unless a custom role grants workflows.write. workflows.read opens the read routes.

MethodPathPurpose
POST/v1/workflows/runner/startStart a run
GET/v1/workflows/runner/runsRunner runs you can see, newest first
GET/v1/workflows/runner/runs/{run_id}/stepsA run with its steps
GET/v1/workflows/runner/runs/{run_id}/historyEvery attempt of every step of a run
POST/v1/workflows/runner/runs/{run_id}/cancelCancel a run
POST/v1/workflows/runner/runs/{run_id}/resumeResume a failed or cancelled run
POST/v1/workflows/runner/runs/{run_id}/replayRe-run a stopped run from a step as a new linked run
GET/v1/workflows/runner/pinsYour pinned test data, without content
POST/v1/workflows/runner/pins/newSave a pin from an attempt or literal text
POST/v1/workflows/runner/pins/deleteDelete a pin
POST/v1/workflows/runner/agents/{agent_id}/releaseRelease a kill switch halt
GET/v1/workflows/runner/dead_lettersDead letters you can see, newest first
GET/v1/workflows/runner/dead_letters/{dead_letter_id}One dead letter with its step's attempts
POST/v1/workflows/runner/dead_letters/{dead_letter_id}/requeueResume the dead letter's run
POST/v1/workflows/runner/dead_letters/{dead_letter_id}/discardMark a dead letter as handled
GET/v1/workflows/runner/statusRunning, pending and ready steps, live workers, replicas holding leases and halted agents

Start, cancel, resume, re-run and the kill switch halt each write an audit row against the run, a release writes one against the agent, and creating or deleting a pin writes one against the pin without its content.

What a run stores​

A run decides when it starts whether it keeps full content or only metadata. It keeps full content only when store_prompts_in_spend_logs is on, turn_off_message_logging is off, workflow_runner.capture_io is true and no key, team or organization policy requires zero data retention. Otherwise the run is metadata_only. store_prompts_in_spend_logs is off by default, so on a default install every run is metadata_only. Turn it on to keep run inputs, step messages and outputs after a run ends.

A metadata_only run never stores the messages sent to or received from agents, which show as redacted-by-spanway. A step's error shows the fixed description of its error code, never the text the agent or upstream returned. The run input and each step's message template and output are kept only while the run needs them to pass outputs between steps. Once no step is running, a completed run has them replaced with redacted-by-spanway and its run output removed. A failed or cancelled run keeps them for workflow_runner.replay_hold_seconds (default 0) so it can be resumed with its original inputs, and is scrubbed after that. Resuming a run cancels its pending scrub, and a run that was already scrubbed cannot be resumed.

A run can only get stricter. If its key, team or organization starts requiring zero data retention while the run is going, the run switches to metadata_only and the messages and error text it already stored are redacted at once.

On Spanway Cloud a run needs a virtual key that belongs to an organization, and a start from any other key is refused with a 403.

Starting runs from triggers​

Workflow triggers start runs from signed webhooks, cron schedules, gateway events, chat messages and forms. A triggered run goes through the same start checks as POST /v1/workflows/runner/start, carries trigger_id, trigger_fire_id and trigger_kind in its metadata, and is started at most once per fire. Metadata keys that start with trigger_ are reserved, so a manual start cannot pose as a trigger.

Retention and data subject requests​

Set maximum_workflow_run_retention_period to delete runs, with their steps, attempts, dead letters, events and messages, that were not updated within that period. Runs never outlive the spend logs, so maximum_spend_logs_retention_period applies when it is shorter. A run the runner is still driving is never deleted. A pending, running or paused run counts as driven only until its deadline, or while one of its steps holds a live lease, so a run left open because the runner was turned off or the license lapsed is deleted like any other. Erasing a user through data subject requests deletes the runs that acted as them and the runs their keys stored. A run with a step still running at that moment is cancelled, its content is replaced with redacted-by-spanway, anything written to it afterwards is redacted too, and it names the user only by pseudonym. Exports include these runs. Pinned test data is deleted on the same period, counted from when it was saved, and erasing a user deletes the pins they or their keys own and the pins copied from runs that acted as them. A re-run names the same data subject as the run it came from, so erasing that user reaches it too.

Settings​

general_settings:
workflow_runner:
enabled: true # set false to stop this gateway from running steps and accepting new runs
poll_seconds: 2
lease_seconds: 30
max_concurrent_steps_per_pod: 16
capture_io: true # set false to keep only metadata for every run on this gateway
replay_hold_seconds: 0 # how long a failed or cancelled metadata_only run keeps its inputs, up to 604800
max_reclaims: 3 # resumes of a recorded A2A task before a reclaim counts as a new attempt
default_tenant_max_running_steps: 16
default_tenant_max_active_runs: 200
backlog_alert_seconds: 300 # alert when ready steps wait this long and nothing runs steps, 0 turns it off
max_call_depth: 4 # how deeply sub-workflows may nest, 0 to 4
max_expanded_steps: 500 # steps a run and all its sub-workflows may have together, 1 to 500

enabled is on by default. Turn it off on a gateway that should only serve model traffic: new runs are then refused with 409 The workflow runner is disabled on this gateway, steps already queued wait until a gateway with the runner on picks them up, and stored runs stay readable. max_call_depth and max_expanded_steps stop a workflow that calls itself, or a very large plan, from using up the runner. A run that goes past either is refused with 422 before it starts. Lower them on a shared gateway where teams write their own workflows. Platform admins change these settings in the config file.

Admin UI​

The Workflow Runs page under Agentic opens to proxy admins, admin viewers, org admins, internal users and internal user viewers, because every list on it is scoped to the caller the same way the API is. Internal users see their own runs, dead letters, saved workflows, triggers, approval requests and installs, plus whatever their teams share with them. The page has the tabs Runs, Saved workflows, Triggers, Variables, Dead letters, Approvals, Templates, Environments and Workers. Environments shows only to proxy admins, admin viewers and org admins, and Workers only to proxy admins and admin viewers. The selected tab is kept in the URL, so a link opens the same tab. Read-only roles (admin viewers and internal user viewers) see every tab they can open without any button that changes something, and each tab says so in a short note.

On the Runs tab, the Start run button builds a plan step by step or takes the JSON. You pick one of your own virtual keys as the key the run uses, because a dashboard session cannot run steps itself. Each agent step has a Retries section for the number of attempts, the first and longest wait, a total timeout and the error codes that are retried, a Custom agent step has a "Use the starting user's own credentials" box for per-user credentials, and the run has an On failure section that does nothing, sends an alert or starts a failure handler. A Saved workflow step picks a saved workflow and a version and fills its inputs. Halted workflows cannot be picked. The list shows runs started through the runner and runs stored through the workflow runs API together, newest first.

Each run opens a Steps tab with status, spend against budget as a meter and errors, with Cancel and Resume buttons where they apply. Resuming a run whose failure handler already ran asks you to confirm that the handler's work stays done. Every step lists its attempts with their origin, status, error, cost and duration, and marks an attempt that never reached the agent. A sub-workflow step shows the child run's spend against its budget. A succeeded attempt whose output was kept can be pinned. The run shows which run it replays and from which step, the replays made of it, and a Test run badge when pinned data fed it.

Replay from a step opens a sheet where you pick the key the replay runs as, the step to start from, whether to keep the original inputs or edit the run input and the messages of the steps that run again, and for each other step whether to run it as usual, use a saved pin or pin some text. You can delete a pin from the same sheet. The new run opens as soon as it starts.

The Saved workflows tab and the Triggers tab are described on the workflow definitions and workflow triggers pages.

The Dead letters tab lists dead letters by state with paging. A dead letter opens its attempts and a link to the run ledger, and can be requeued, which asks you to confirm when a failure handler already ran, or discarded with a reason.

The Approvals tab is an inbox of the approval requests you raised or may decide, with a Policies view next to it.

The Templates tab browses the workflow template catalog, installs, runs, upgrades and uninstalls templates.

The Environments tab reviews and applies environment plans.

The Workers tab shows the runner's role and mode, how many steps are ready and pending and how long the oldest has waited, and the health of each worker as draining, stale, busy or idle. Agents halted by the kill switch are listed there, and a proxy admin can release them.

Every tab names the enterprise features it needs when the license lacks them, instead of showing an error. The run ledger only shows step attempts and replay lineage when the license includes workflow_history, the same feature the history route needs.

Errors​

The runner routes answer {"detail": "<message>"}, or {"detail": {"step_key": "<step>", "message": "<message>"}} when one step is at fault. The same rows are in the error reference.

StatusWhat it meansFix
400 "The master key cannot start workflow runs; use a virtual key"Runs always act as a virtual key, so the master key is refused.Start the run with a virtual key.
400 "Name the virtual key the run should use in run_as_key"An Admin UI session started a run without picking a key.Send run_as_key, or pick a key under Run as key.
400 "A virtual key starts runs as itself; omit run_as_key"A virtual key sent run_as_key for another key.Leave run_as_key out.
400 "Workflow runs need a virtual key" or "A dashboard session key cannot run steps; pick a virtual key"The caller has no virtual key, or the chosen key is a dashboard session.Use a virtual key.
400 "Pins belong to a virtual key or a dashboard session"A pin was saved without a key.Save it with your own key.
403 workflow_runner license messageThe license lacks the workflow_runner feature, or a step needs workflow_subworkflows, workflow_retries or workflow_history.Add the feature to the license or ask sales@spanway.ai.
403 "run_as_key must be one of your own virtual keys"An Admin UI session named someone else's key.Pick one of your own keys.
403 "You may not call the agent of step ..."The run's key is not granted that agent.Grant the agent to the key or team, or start the run with a key that has it.
403 "The run's key cannot run steps: ..."The key is blocked, expired, over budget or disabled.Fix the key on the Virtual Keys page or start the run with another key.
403 "Your role can read workflow runs but not change them"A read only role tried to start, cancel or resume a run.Use a role with workflows.write.
403 "Only a proxy admin can replay a run as its original key"as_original_actor was sent by someone who is not a proxy admin.Replay as yourself, or ask a proxy admin.
403 "Only a proxy admin can release a halted agent"Releasing a kill switch is for proxy admins.Ask a proxy admin.
404 "Workflow run ... not found"The id is wrong or the run belongs to another key.Check the id on the Runs tab.
404 "Attempt ... not found" or "Pin ... not found"The attempt or pin does not exist, or is not yours.Check the id.
409 "The workflow runner is disabled on this gateway"workflow_runner.enabled is false.Turn it on, or start the run on a gateway that has it on.
409 "Only failed or cancelled runs can be resumed, not ..."The run is still running or already completed.Wait for it to stop, or replay it from a step instead.
409 "The kill switch fired for ..."An agent in the plan is halted on this gateway.Restore the agent and call POST /v1/workflows/runner/agents/{agent_id}/release.
409 "A proxy admin halted workflow definition ..."A proxy admin halted the saved workflow.Ask a proxy admin to release it, see halting a definition.
409 "Pins need a salt key or master key to encrypt their content" or "Pinned data needs a virtual key whose data policy and the gateway's capture settings keep content"Pinned data can not be stored safely, or the key keeps metadata only.Set SPANWAY_SALT_KEY, or use a key whose data policy keeps content.
409 "Only a succeeded attempt whose output was kept can be pinned" or "The attempt's output can no longer be read"The attempt has no stored output to pin.Pin another attempt, or write the pinned text yourself.
422 on a stepThe step plan is invalid, for example "the steps' depends_on form a cycle", an unknown placeholder, or sub-workflows nested deeper than max_call_depth.Fix the step named in step_key.
422 "Idempotency-Key was already used with a different request"The same Idempotency-Key came with another body.Use a new key for a new request.
422 "Metadata key ... is reserved for the gateway"Metadata names start with a prefix the gateway uses itself.Rename the metadata key.
422 "as_original_actor replays as the run's key; omit run_as_key"Both were sent on a replay.Send only one of them.
422 "workflow_type and step_key must match the attempt being pinned"A pin from an attempt named another workflow or step.Send the attempt's own workflow type and step.
429 "Your organization, team or key already has N active workflow runs"The tenant's active run limit is reached, and Retry-After says when to try again.Wait for running runs to finish or raise the tenant limit in the settings.
503The queue or the database behind the runner is unavailable.Check the workers on the Workers tab and the database connection, then retry.
Step failure code budget_exhausted, timeout or agent_errorThe step hit its budget or timeout, or the agent failed.Raise the step's budget or timeout, or read the agent's error in the dead letter.

Logs​

The runner writes these lines to the gateway log. None of them carries step inputs or outputs. The same rows are in the log reference.

LevelLineMeaningAction needed
INFOworkflow runner is not running steps in this process: <reason>This process only accepts runs, for example SPANWAY_WORKFLOW_RUNNER_ROLE=producer, or the runner is off.None when intended. Otherwise check workflow_runner.enabled and the process role.
WARNINGworkflow runner heartbeat failed: <error> or workflow runner could not record its heartbeat: <error>The process could not tell the database it is alive, so the Workers tab may show it as gone.Check the database if it repeats.
WARNINGworkflow runner could not renew its step leases: <error>Steps this process runs may be picked up by another replica after lease_seconds.Check the database and the load on this replica.
WARNINGworkflow step <step id> attempt <n> failed: <error>One attempt of a step failed. It is retried when the step has a retry policy.Read the step's error on the Runs tab.
WARNINGworkflow step <step id> could not record its A2A task: <error>The step runs, but a restart cannot resume its A2A task.Check the database.
ERRORworkflow runner: loading sub-workflow <id> failedA step that calls a saved workflow could not load it, and the step fails.Check that the definition and version still exist.
WARNINGworkflow run <run id> on_failure plan is invalid: <message>The compensating workflow of a failed run could not start.Fix the on_failure steps.
WARNINGworkflow run <run id> on_failure workflow not started, the license lacks workflow_error_handlingThe license does not include compensating workflows.Add the feature to the license.
WARNINGworkflow run <run id> failure alert was not sent: <error>The failure alert could not be delivered.Check the alerting integration.
WARNINGworkflow runner backlog check failed: <error>The backlog alert check could not run this time.Check the database if it repeats.
WARNINGworkflow worker <id> could not deregister: <error>A stopping worker could not remove itself, so it shows as stale until it expires.None.
WARNINGCould not register workflow runner metrics: <error>The runner metrics are missing from /metrics.Check that only one process registers them.