Introducing a new way to review your PRs.

Read the announcement

semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform/OpenTofu/Terragrunt, PowerShell and other DevOps tools.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / automation-execution

Automation execution

Automation execution turns a project template or workflow node into a tracked task. The task moves through validation, queueing, dispatch, execution, log capture, cancellation or recovery, and terminal completion while the system keeps its database state and runtime state aligned.

Execution model

Task creation

The task pool is the entry point for work started by a user, schedule, integration, autorun, or workflow. It validates the task against its template, stores a waiting task, loads the template resources and runtime context, and chooses a local or runner-backed job before placing the task in the queue. Task-supplied secret values stay in a task-bound encrypted store until dispatch. Creation records the source trigger and relevant parent or source link in audit data, with system actors used for scheduled work and the task runner used for execution events.

References: services/…/TaskPool.go• L1143-1173 services/…/TaskPool.go• L1244-1317 services/…/TaskPool.go• L1319-1376

Queue dispatch

The queue holds tasks that are ready but not yet running. The task pool removes a task only after it passes system, project, and template concurrency limits, then claims it by task ID so one node starts it even when several high-availability nodes share the queue. A claimed task enters the running set and receives a starting status.

The main state locations are:

LocationMeaning
queueThe task waits for capacity and a dispatch path.
runningThe task has been claimed and is being prepared, executed, or reported by a runner.
DatabaseThe durable record of status, timestamps, runner assignment, logs, and results.

References: services/…/TaskPool.go• L355-414 services/…/TaskPool.go• L495-536 services/…/task_state_store.go• L94-114

Execution paths

After dispatch, the task follows one of two execution paths. Local execution uses a synchronous executor on the server process or configured local host. Runner-backed execution uses an executor on an online runner and returns control to the server while the runner reports progress and completion.

Both paths use the same task job contract. The executor prepares the inputs, runs the automation tool, captures task results, and cleans up temporary resources. Local execution exposes these phases as preparation, run, and cleanup, while runner-backed execution completes them on the runner and sends the result back to the server. Agent tasks use the same task boundary but receive prompt values without placing secrets on their command line.

This diagram shows how a template or workflow node becomes a task and how either execution path produces a shared terminal result.

flowchart LR
    A[Template or workflow node] --> B[Create waiting task]
    B --> C[Shared task queue]
    C --> D{Execution path}
    D --> E[Local executor]
    D --> F[Runner dispatch]
    F --> G[Runner job pool]
    E --> H[Task logs and status]
    G --> H
    H --> I{Terminal result}
    I --> J[Persist completion]
    I --> K[Progress workflow or autorun]

The local and runner-backed paths share task status, log, cancellation, and completion contracts. Their detailed lifecycles are described in local automation execution, runner-backed execution, and agent task execution. The wider state machine is described in task orchestration and state.

References: services/…/TaskRunner.go• L193-240 services/…/TaskPool.go• L1333-1379 services/…/executor.go• L18-46 services/…/local_executor.go• L837-878 services/…/local_executor.go• L1057-1272 services/…/RemoteJob.go• L204-283

Task lifecycle

Preparation and start

Preparation resolves the template's repository, inventory, environment, credentials, task parameters, and workflow context. A managed inventory becomes a task-local inventory from its enabled hosts and variables, while project host mappings supply credentials to the task's connections. The local executor then validates paths, prepares the repository and inventory, installs access material, and builds the environment and arguments for the selected app. Survey values targeted at the process environment stay in environment variables; other values become task inputs, while agent secrets remain outside the command line. The selected executor then prepares its working inputs and moves the task from starting to running; a preparation error records a failed task instead of starting incomplete work.

References: services/…/TaskRunner.go• L231-320 services/…/TaskRunner.go• L605-700 services/…/local_executor.go• L1057-1253 services/…/local_executor.go• L1311-1414 services/…/local_executor_inventory.go• L14-36 services/…/managed_inventory.go• L30-56

Log and status capture

Logs and status changes use the task as the common record of progress. Local execution sends output into the task logger. A runner sends status, commit data, and log records back to the server, where log records are batched into task output rows and may advance stage data for the task view. Ansible tasks also produce a per-host result document; the server validates it and stores host counters as a separate task result, including when the automation tool fails. Local workflow tasks can also produce an output document, which is collected after a successful run and made available to completion.

References: services/…/TaskPool.go• L416-493 services/…/TaskRunner.go• L117-140 services/…/TaskRunner.go• L399-419 services/…/local_executor.go• L919-1054 services/…/task_hosts.go• L121-175 services/…/semaphore_hosts.py• L44-57 api/…/runners.go• L489-520 services/…/job_pool.go• L537-654

Completion

Completion is the single point that records the end time, persists the terminal status, creates the task event, records the audit result, releases queue and concurrency state, and notifies workflow orchestration. It also records the actor and end reason for the completion, while a shared guard ensures that recovery and runner reports cannot complete the same task twice. Local execution stores workflow outputs before success is persisted, while runner-backed execution sends its output document to the server for validation before the same finalization step. Successful build tasks can also create autorun child tasks. Host counters remain supplemental: a malformed or missing host document is logged without changing the task result.

References: services/…/TaskRunner.go• L356-419 services/…/TaskRunner.go• L421-460 services/…/TaskRunner.go• L462-498 services/…/TaskPool.go• L539-603 services/…/TaskPool.go• L615-655 services/…/local_executor.go• L1021-1054 services/…/local_executor_test.go• L188-251 services/…/TaskPool_audit_test.go• L83-202

Status alerts

Status alerts notify external channels after a task reaches a reported result. Templates can suppress success and error alerts independently, while an approval wait is not treated as either result. Scheduled alerts name the schedule as the author and include a task link only when the configured web host can produce an absolute URL; missing task version or message data does not leave empty separators in the alert.

References: services/…/alert_test.go• L17-97 services/…/alert_test.go• L174-239 services/…/alert_test.go• L243-307

Control and recovery

Cancellation

Cancellation changes the task state and prevents more work from being accepted. A waiting task is marked stopped and removed from the queue. An active local task receives a kill request and always runs executor cleanup. A remote task is marked stopping or stopped on the server, and the runner is told to stop the process through the next progress exchange; a forced remote stop is finalized at once because no later runner report is required.

References: services/…/TaskPool.go• L799-868 services/…/TaskPool.go• L990-1087 services/…/local_executor.go• L113-125 services/…/local_executor.go• L837-878 services/…/local_executor.go• L1256-1272 api/…/tasks.go• L74-115 services/…/job_pool.go• L657-686

Runner loss recovery

Runner liveness separates a task that has not started from a task that is already running. A task still in starting or waiting is returned to the queue when its runner becomes unavailable. A running task fails after the recovery window or immediately when a runner restart proves that its in-memory job was lost. Shared finalization guards prevent a late runner report and a recovery action from completing the same task twice.

References: services/…/runner_reconciler.go• L16-101 services/…/runner_reconciler.go• L104-189 services/…/runner_reconciler.go• L216-320 services/…/TaskPool.go• L539-575

Runner progress exchange

A runner polls the server for new jobs and sends progress at a regular interval. The server supplies the task context and required access keys only after runner authentication and preparation. The runner executes the job through its executor, then returns status and log records; the server rejects stale or finished reports and tells the runner to stop jobs that the server no longer accepts.

References: api/…/runners.go• L95-180 api/…/runners.go• L183-278 api/…/runners.go• L381-531 services/…/job_pool.go• L363-535 services/…/types.go• L11-75

Workflow coordination

Workflow task progression

A workflow run groups related tasks and uses task completion as its handoff point. A workflow task carries its run identity into the execution environment, and completion notifies the workflow service so it can choose the next node, create an approval, follow a failure path, or finish the run. The open-source build keeps this service as a safe no-op boundary; the workflow feature supplies the active orchestration behavior where enabled.

References: services/…/TaskRunner.go• L425-435 services/…/TaskRunner.go• L449-460 services/…/TaskRunner.go• L555-578 services/…/local_executor.go• L307-332 services/…/local_executor.go• L1225-1244 pro/…/workflow_svc.go• L10-49

Workflow outputs

Workflow outputs are data passed from one completed task to later workflow nodes. The execution path captures or receives the output document, validates it on the server, and stores it before the task reaches success so the next node never reads a success state without its declared outputs. Local execution only collects outputs after the app reports success and the task remains in the running state; cleanup closes the capture even when preparation or execution stops early.

References: services/…/local_executor.go• L935-960 services/…/local_executor.go• L1021-1054 services/…/local_executor.go• L1256-1272 services/…/TaskRunner.go• L375-396 services/…/TaskPool.go• L615-644 api/…/runners.go• L494-505

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep local and runner-backed jobs aligned with the shared terminal status and finalization contract.
  • Preserve the order that workflow outputs are stored before a success status is visible to workflow progression.
  • When changing runner assignment or liveness rules, check both requeue behavior for starting tasks and failure behavior for running tasks.
  • When changing task cancellation, keep queue removal, runner emergency-stop replies, and shared runtime cleanup consistent.
  • When changing task creation inputs, preserve the boundary that keeps survey secrets out of the task row and runner-independent API data.
  • When changing task audit events, preserve the source trigger, initiating actor, end reason, and single completion event across normal, stopped, preparation-error, and runner-loss paths.
  • When changing inventory preparation, keep managed-inventory validation, enabled-host selection, and the local inventory form aligned.
  • When changing local executor preparation, keep repository paths, inventory paths, access mappings, app arguments, and process environment based on the same task inputs.
  • When changing survey variable targets or value formatting, keep environment delivery separate from extra-variable delivery and preserve JSON values for lists and objects.
  • When changing agent task preparation, keep prompt values out of process arguments while preserving the task and workflow identity environment.
  • When changing Ansible host statistics, keep the callback document version, counter names, size limit, and stored host rows compatible.
  • When changing status alerts, keep success and error suppression independent and keep scheduled-task author and link formatting valid for external message clients.

Important failure modes

TriggerConsequenceGuard
All matching runners are offline or at capacityThe task returns to waiting instead of failing or retrying in a hot loop.RemoteJob returns the busy error and the task pool requeues it for a later pass.
A runner disappears while a task is startingThe task can remain stuck without reassignment.The runner reconciler returns starting tasks to the shared queue.
A runner disappears after execution startsThe task can report success without a live executor.The reconciler fails the task after the recovery window or after a detected runner restart.
A runner reports success with invalid workflow outputsDownstream nodes can receive incomplete or unsafe data.The server validates outputs before it accepts the terminal success status.
Managed inventory variables or host variables are invalidThe task fails during preparation and does not start the automation tool.Inventory data is parsed before it is rendered into the task's static inventory.
A local task uses an invalid playbook path or unsupported inventory credentialThe task fails before the automation tool starts.Local preparation validates paths and checks that inventory credentials support the requested use.
A survey list or object is passed as a plain stringThe app receives a value that it cannot parse as the intended collection.Local argument and environment preparation preserves collection values as JSON.
A survey variable is targeted at both environment and extra variablesThe task receives duplicate or conflicting values.Environment-target variables are removed from extra variables before process environment creation.
An agent secret is added to command argumentsProcess inspection can expose the secret.Agent preparation passes prompt values separately and includes only permitted arguments on the command line.
Ansible does not write a valid host statistics documentThe task's per-host view is absent or incomplete, but the task can still succeed or fail normally.Host data is size-limited and validated separately; storage errors only add a task log message.
A force stop reaches the server while the runner is offlineThe runner can continue its local process after the server has ended the task.The progress response lists terminated jobs and the runner emergency-stops them.
Two completion signals race across high-availability nodesDuplicate events, autorun tasks, or leaked runtime state can result.The shared finalization guard and persisted end time make completion idempotent.
A configured web host is not an absolute URLA Telegram alert is sent without a clickable task link.Alert formatting omits the link unless the host can form a valid absolute URL.

Key files

FileWhy to read it
services/…/TaskPool.goShows task creation, queue claims, concurrency limits, cancellation, and shared finalization.
services/…/TaskRunner.goShows the common task lifecycle, status changes, logging, outputs, workflow handoff, and completion audit.
services/…/executor.goDefines the shared preparation, execution, cleanup, output, and host-result contract for task executors.
services/…/local_executor.goShows the local preparation, input delivery, tool run, output capture, and cleanup boundary.
services/…/local_executor_inventory.goShows how credentials and inventory files become runtime inputs for local tasks.
services/…/managed_inventory.goShows how enabled managed hosts and inventory variables become task inventory data.
services/…/task_hosts.goShows the host-result document boundary and its conversion to stored per-host counters.
services/…/semaphore_hosts.pyShows the Ansible callback contract that produces per-host counters.
services/…/RemoteJob.goShows runner selection, remote dispatch, timeout, and asynchronous completion.
api/…/runners.goShows runner polling, job delivery, progress validation, and terminal report handling.
services/…/job_pool.goShows runner-side job execution and progress delivery to the server.
services/…/runner_reconciler.goShows recovery decisions when runners go offline, restart, or disappear.
pro/…/workflow_svc.goShows the workflow orchestration boundary that receives task completion and provides workflow context.