Runner-backed execution
Runner-backed execution lets the server assign a task to a separate runner process while keeping task state, dispatch decisions, and final task lifecycle on the server. The runner pulls work, runs it through a configured executor, and sends status and output back through the runner API. The server-side dispatch and state model is described in Automation execution; this page focuses on the boundary with external runners.
Execution boundary
The server is the authority for task assignment and task state. An external runner is the worker boundary: it receives the task data needed for execution, runs the task in its own environment, and reports progress without owning the server-side task record.
The boundary has these responsibilities:
| Server | Runner |
|---|---|
| Selects a registered runner with matching scope, tags, liveness, and capacity | Pulls assigned work from the runner API |
| Builds the task payload and decrypts the access keys needed for that task | Hydrates the payload and creates the task executor |
| Accepts status, logs, commit data, and workflow outputs | Produces status, logs, commit data, and workflow outputs |
| Finalizes the task and starts downstream server work | Stops execution when the server rejects a stale or finished job |
This separation means the server can complete a remote task on any node that receives the runner report. The node that first dispatched the task does not need to stay alive for task completion.
References: services/…/RemoteJob.go• L204-283 api/…/runners.go• L162-180 services/…/TaskPool.go• L539-603
Runner registration
Runner registration creates the server identity that a runner uses for later polling. The command can take a registration token from a flag, a configured file, or standard input, then stores the returned runner token in a token file or the runner configuration.
The start command can auto-register when the runner has no token. It retries registration until the server is available, then starts the job pool. The Docker runner wrapper enables this mode when it receives a registration token and supplies a default token-file location when no runner token location is set.
References: cli/…/runner_register.go• L25-110 cli/…/runner_start.go• L21-50 deployment/…/runner-wrapper• L18-28 services/…/job_pool.go• L614-738
Runner job pool
The runner job pool is the runner-side control loop. It keeps a short queue of accepted jobs, starts each job, tracks jobs that are in progress, polls the server for more work, and sends progress at regular intervals.
The runner uses two server-facing exchanges:
- A job check returns new jobs and the current server view of assigned jobs.
- A progress report sends status and new log records, then receives acknowledgements and any jobs that must stop.
The runner includes its process start time in these requests. A changed start time tells the server that the runner restarted and may have lost its in-memory jobs. The pool uses one shared authenticated HTTP client for these exchanges. Connection, handshake, response-header, and response-body waits have a configured limit, so a silent server cannot stop the poll loop and its heartbeat. Progress uploads can continue while logs are sent.
The pool accepts a job only once. It skips jobs already queued or running, then places new work in its queue. It also applies server status changes to current jobs and stops jobs that the server no longer accepts. A one-off runner exits after its accepted jobs finish. Pool state is protected while the run loop, poll loop, and job goroutines access it, so progress reporting can run at the same time as queue and job changes.
This diagram shows how a task moves between the server and the runner job pool.
sequenceDiagram
participant S as Server task API
participant P as Runner job pool
participant E as Runner executor
P->>S: Check for assigned jobs
S-->>P: New job data and current statuses
P->>P: Queue job and create running-job record
P->>E: Run task
loop While task is active
P->>S: Send status and log progress
S-->>P: Acknowledge logs or request termination
end
E-->>P: Return terminal result
P->>S: Send terminal status and result data
S-->>P: Accept result or identify stale job
References: services/…/job_pool.go• L31-107 services/…/job_pool.go• L110-158 services/…/job_pool.go• L349-479 services/…/job_pool.go• L481-598 services/…/job_pool.go• L740-895 services/…/job_pool_test.go• L245-338 services/…/job_pool_test.go• L514-688
Executor factory
The executor factory turns runner configuration into a long-lived executor provider and turns each received job into one executor. The provider holds strategy-wide resources, while the executor represents one task.
The configured strategy can be:
- Local execution on the runner host.
- Kubernetes-backed execution.
- Docker-backed execution.
An empty executor setting uses local execution. An unknown setting prevents the runner from accepting jobs until its configuration is corrected. Before the per-task executor is created, the runner wires the access keys sent with the task into the repository, host, inventory, and vault data.
The factory keeps the job pool independent of the execution strategy. A new strategy can provide the same task lifecycle without changing server dispatch or runner progress handling.
References: services/…/executor_factory.go• L14-110 services/…/executor.go• L8-83
Running-job tracking
Each accepted runner job has a running-job record between queue removal and server acknowledgement of its terminal status. The record is the shared point for execution status, task logs, commit information, host statistics, and workflow outputs.
The record supports concurrent task execution and progress reporting. It snapshots progress for a report, keeps unacknowledged log records for the next report, and sends captured result data with the matching final status. It removes the job from the pool after the server accepts a terminal status. If the server says that a job is already finished or no longer belongs to the runner, the runner kills the local execution and removes the record.
Workflow outputs travel with the success status. The server validates them before it persists success so downstream workflow steps do not see a successful task with missing or invalid output data. Host statistics travel with the final status when the executor provides them. Executors that do not capture workflow outputs report that limit in the task log.
References: services/…/running_job.go• L18-46 services/…/running_job.go• L127-203 services/…/job_pool.go• L161-187 services/…/job_pool.go• L546-597 services/…/types.go• L49-81 api/…/runners.go• L447-520
Remote task dispatch
The server represents runner-backed work as an asynchronous remote job. The task pool first selects a runner from project and global runners, then filters by active state, registration, tag or default scope, online status, and parallel capacity.
When a runner is selected, the server may send a start webhook. It then assigns the runner ID to the task and returns control to the task pool. The runner later asks for the task data. The server prepares the payload at that point, including decrypted task access keys and optional task JWT data, so the runner receives the complete execution context.
MCP server tokens are part of this task context. The server sends each token as a decrypted access key for that job instead of placing the token in the serialized inventory or in the shared access-key map for the whole poll response. This keeps a token paired with the task's saved MCP server URL, even when two queued tasks use the same access-key ID after a server edit. If the token is not decrypted, the server fails that dispatch rather than send a job with incomplete access.
The server does not wait for the remote process in the dispatch call. A progress request can arrive at any server node, which updates task state and starts finalization when the reported status is terminal. This lets task completion continue even if the node that made the assignment stops.
References: services/…/RemoteJob.go• L112-158 services/…/RemoteJob.go• L204-283 api/…/runners.go• L96-180 api/…/runners.go• L184-283 api/…/runners.go• L386-424 api/…/runners_mcp_test.go• L24-124
Remote task finalization
Remote finalization converts a runner result into the normal server-side task completion flow. It persists the terminal task state, records the end reason and actor, runs the finish webhook when available, starts autorun children, and releases task-pool state.
Several signals can request finalization:
- A runner reports a terminal status.
- A remote task reaches its server-side time limit.
- A user force-stops the task.
- Reconciliation decides that the runner is lost.
The state store allows only one finalizer for a task. In high-availability mode, the finalizer also checks the database before it performs completion work. These guards prevent duplicate finish actions when a timeout, runner report, and another server node race.
References: services/…/TaskPool.go• L539-603 services/…/TaskPool.go• L799-817 services/…/RemoteJob.go• L286-312 api/…/runners.go• L567-574
Runner reconciliation
Runner reconciliation repairs tasks when the server view of a runner no longer matches the runner's ability to execute work. It runs over the tasks owned by the current server node and uses runner heartbeat and process start data to choose a safe action.
| Condition | Server action |
|---|---|
| A starting or waiting task has an offline or deleted runner | Clear the assignment and return the task to the queue |
| A running task exceeds the runner recovery window | Mark the task failed and finalize it as runner-lost |
| A running task belongs to a runner that restarted after the task started | Fail it at once because the runner lost its in-memory job |
| A starting task belongs to a restarted runner | Keep it eligible for the runner to pull again |
| A task has no runner after a server restart and no live dispatch exists | Return it to the queue |
Reconciliation does not treat a short loss of heartbeat as proof that a running process stopped. The separate offline and task-failure windows give a runner time to reconnect before the server fails work. In high-availability mode, a cluster-wide finalize lock and database checks make requeue and failure decisions idempotent.
References: services/…/runner_reconciler.go• L16-101 services/…/runner_reconciler.go• L104-189 services/…/runner_reconciler.go• L216-375 api/…/runners.go• L103-149
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the runner request and response contracts aligned across registration, job checks, progress reports, termination replies, and optional workflow outputs or host statistics.
- Keep runner process start tracking aligned with reconciliation rules. A restart must fail running jobs but allow starting jobs to be pulled again.
- Keep assignment clearing and queue insertion atomic from the task pool's point of view. A stale runner must not pull a task after it is reassigned.
- Keep remote finalization safe for reports, timeouts, force stops, and high-availability races.
- Keep executor providers consistent with access-key hydration so every execution strategy receives the same task context.
- Keep per-job MCP token keys separate from the shared response keys. A task's token must stay paired with the URL snapshot in that task.
- Keep auto-registration token sources and token persistence aligned with the runner wrapper and both runner start modes.
- Keep request deadlines and shared-client behavior intact. A stuck server must not stop runner heartbeats or create a new connection on every poll.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Runner stops polling before a starting task begins | The task can remain assigned to a runner that cannot pull it | Reconciliation requeues starting and waiting tasks after the offline window |
| Runner restarts while a task is running | The runner's in-memory job record is gone | The changed process start time makes reconciliation fail the running task |
| A stale runner reports after reassignment | Two runners could execute the same task | The server rejects the old assignment and tells the old runner to stop |
| A terminal report races with timeout or force stop | Duplicate finish actions or conflicting task state | Finalization locks and database re-checks allow one completion path |
| Executor configuration is invalid | The runner starts but cannot construct task executors | Provider creation fails at startup and dispatch rejects jobs cleanly |
| An MCP token is not decrypted before dispatch | The runner would lack the credential required by the task's MCP server | The server fails dispatch instead of sending an incomplete job |
| MCP tokens from queued tasks share one response-level key map | One task could receive another task's token for its saved MCP URL | The server keeps MCP tokens in each job's own access-key map |
| A runner reports invalid workflow outputs | Downstream workflow steps could consume bad data | The server validates outputs before accepting task success |
| The server accepts a connection but stops sending a response | The poll loop can stop sending heartbeats and the runner can appear offline | Transport and response-body deadlines bound server waits |
| Registration returns no runner token | The runner cannot authenticate future requests | Registration rejects the response before saving it |
Key files
| File | Why to read it |
|---|---|
| services/…/RemoteJob.go | Shows runner selection, asynchronous dispatch, webhooks, and remote timeout behavior |
| api/…/runners.go | Shows the server-side runner authentication, poll, progress, task payload, access-key, and termination boundary |
| services/…/job_pool.go | Shows the runner-side queue, polling, progress, registration, and termination loop |
| services/…/executor_factory.go | Shows how runner configuration selects per-task execution strategies |
| services/…/executor.go | Defines the provider and executor contracts shared by runner strategies |
| services/…/running_job.go | Shows the in-memory status, log, commit, host, and output record for one running job |
| services/…/runner_reconciler.go | Shows recovery rules for offline, restarted, deleted, and lost runners |
| services/…/TaskPool.go | Shows remote finalization and release of server-side task state |
| services/…/types.go | Defines the job, progress, state, result, and registration data exchanged across the runner boundary |
| services/…/job_pool_test.go | Summarizes the pool guarantees for concurrency, connection reuse, deadlines, outputs, and token persistence |
| services/…/running_job_test.go | Summarizes running-job guarantees for status, logs, progress snapshots, outputs, and concurrent access |
| api/…/runners_mcp_test.go | Shows that MCP tokens stay private to each dispatched job and fail dispatch when missing |
| cli/…/runner_register.go | Shows the supported registration token sources and runner registration options |
| cli/…/runner_start.go | Shows startup and retry behavior for automatic registration |
deployment/docker/runner/runner-wrapper | Shows how the Docker runner selects normal or auto-registration startup |