Queue and job lifecycle
Armada uses queues to control where jobs enter the scheduling system and how they compete for cluster capacity. The server keeps queue policy and job state in persistent stores, the scheduler turns job and executor updates into state changes, and query services expose the resulting job and run view to clients. See Submission and queue management for the parent view and Submission API for the submission contract.
System model
The lifecycle has three related objects: a queue accepts jobs and supplies scheduling rules, a job represents the requested work, and a job run represents one attempt to execute that work. A job can have several runs because a failed or returned attempt can cause the scheduler to try again.
The server publishes state changes as event sequences. The event stream is the durable hand-off between scheduling decisions and the database view used by later scheduler cycles, executors, and clients.
When Armada processes a job, the main stages are:
- Submission places the job in its queue.
- Validation checks whether the job can run.
- Scheduling creates a run and leases it to an executor.
- The executor reports placement and run progress.
- The scheduler either completes the job, cancels it, fails it, or puts it back in the queue.
- Query services read the stored job and run state.
Queue configuration
Queue definition
A queue is the control point for admission and scheduling policy. Its definition includes a name, access rules, priority factor, resource limits, labels, and a cordoned flag; it can also name retry policies in precedence order. The queue model is shared by the queue API and the scheduler so that the same definition guides both users and scheduling.
Queue state is persistent. Retry policy attachments are stored as queue relationships rather than inside the serialized queue definition, which keeps the attachment order available to the scheduler and lets queue updates replace the full attachment list.
References: pkg/…/queue.go• L10-18 pkg/…/submit.proto• L179-207 internal/…/queue_repository.go• L201-259
Queue operations
The queue service manages creation, update, deletion, listing, and cordon state. Writes require the matching administrative permission and validate the queue before persistence; reads return the current definition without changing scheduling state.
Cordoning stops new validation and scheduling work from entering the queue. It does not by itself terminate jobs that already have a run. Queue-wide cancel and preempt requests are published as control-plane events, so the scheduler applies them to matching jobs and runs during its normal event flow.
The scheduler reads queue data through a refreshed cache. A refresh failure leaves the last successful view in place, while an unavailable cache with no prior view prevents operations that need queue data from making a decision.
References: internal/…/queue_service.go• L46-245 internal/…/queue_service.go• L257-334 internal/…/queue_cache.go• L13-66 internal/…/queue_cache.go• L31-80
Job lifecycle
Job and run states
A job state describes the overall request, while a run state describes one execution attempt. The job is queued when it is eligible for scheduling, becomes leased when a run is assigned, and reaches a terminal state when it succeeds, fails, or is cancelled.
The scheduler treats these transitions as one consistent model:
| Object | Active states | Terminal states | Return path |
|---|---|---|---|
| Job | Queued, leased, pending, running | Succeeded, failed, cancelled | A failed recoverable run can make the job queued again |
| Job run | Leased, pending, running | Succeeded, failed, preempted, cancelled, returned | A returned run can lead to a new run |
Only one terminal state is kept for a run. A job is terminal when one of its job-level terminal flags is set, and terminal jobs are no longer considered for scheduling. The scheduler also tracks a queued-state version so that a lease or requeue update cannot move the stored job backward.
References: pkg/…/submit.proto• L97-109 pkg/…/job.proto• L9-20 internal/…/job.go• L101-129 internal/…/job_run.go• L83-155
Scheduler state cycle
The scheduler keeps an active in-memory view of jobs and runs, but the database remains the source of state updates. Each cycle reads the initial state or changes after serial cursors, reconciles those changes, creates event sequences, and advances the cursors only after publish succeeds.
This cycle lets state reported by executors drive job transitions while letting scheduling decisions create new runs. A leader alone publishes scheduling decisions. A non-leader can keep its view current without producing new scheduling events.
The flow below shows how persistent state, scheduling, and event publication meet.
flowchart LR
DB[(Scheduler database)] -->|initial or changed jobs and runs| Sync[State reconciliation]
Sync --> Decisions[Job transition decisions]
Decisions -->|leader only| Schedule[Capacity and queue scheduling]
Schedule --> Events[Event sequences]
Decisions --> Events
Events -->|published| DB
Events --> Executor[Executor-facing lease and control events]
DB --> Query[Query API]
References: internal/…/scheduler.go• L54-61 internal/…/scheduler.go• L294-318 internal/…/scheduler.go• L319-472 internal/…/scheduler.go• L475-558
State reconciliation
Reconciliation combines direct job changes with run changes and applies them to the scheduler view. A new job enters as queued; validation, cancellation, reprioritisation, run progress, and terminal results then update the job or its latest run.
Run state is reported as a set of facts rather than as a free-form transition request. Reconciliation applies new facts, removes conflicting terminal flags, and records which transitions occurred. This makes the scheduler state safe to use for both scheduling and event generation.
The event ingester applies the same event sequence to persistent state. Submission creates a queued job, a lease clears the queued state and creates a run, run events update progress, and terminal job errors or success update the job state.
References: internal/…/reconciliation.go• L17-63 internal/…/reconciliation.go• L65-149 internal/…/reconciliation.go• L151-315 internal/…/instructions.go• L93-148 internal/…/instructions.go• L151-329
Retry decisions
Retry policy selection
Retry policy selection starts with the policy attached to the job's queue. If the queue has no attachment, the scheduler can use one configured default policy; if neither exists, it uses the legacy failure behavior.
The scheduler evaluates only the first policy listed for a queue. The policy cache refreshes compiled policies from the retry-policy API and keeps the last good set when the API is unavailable. A missing or invalid cached policy does not invent a retry decision; it returns control to the legacy path.
Gangs and jobs marked fail-fast are also outside policy-driven retry. Their special handling protects gang-wide coordination and honors the job's request to stop after a failure.
References: internal/…/scheduler.go• L1049-1112 internal/…/scheduler.go• L1138-1183 internal/…/cache.go• L12-24 internal/…/cache.go• L39-99
Retry budget evaluation
For a policy-controlled failure, the retry engine makes a fixed sequence of checks: it needs an error, it checks the global retry cap, it matches the error category and subcategory against ordered rules, and it checks the policy retry limit. A rule or default action then grants a retry or produces a terminal failure reason.
Retry limits count retries after the first genuine failure. Preempted and lease-returned runs do not consume this failure budget. Lease expiry is treated as a genuine failure because the executor stopped reporting while the run was active.
| Decision input | Result |
|---|---|
| Retry rule or retry default within both limits | Requeue the job for a new run |
| Fail rule or fail default | End the job with a terminal error |
| Policy retry limit reached | End the job with the policy limit reason |
| Global limit reached or set to zero | End the job without another policy retry |
| No usable policy or excluded job | Use legacy behavior |
References: internal/…/engine.go• L17-46 internal/…/engine.go• L46-103 internal/…/job.go• L854-897 internal/…/configuration.go• L352-369
Requeue outcomes
When a retry is granted after a failed run, the scheduler keeps the job identity, marks the job queued, advances its queued-state version, and emits a requeue event. A later scheduling decision creates a new run. A policy can also change retry placement or memory, but the scheduler abandons the retry if the changed job cannot fit any node.
The event stream marks a policy-driven retry with a non-terminal job error before the requeue event. A terminal policy result keeps the original run error and adds the policy reason, so clients can distinguish the cause from the decision.
Lease expiry follows the same broad choice. The scheduler marks the old run as failed, then either requeues it under a policy or fails the job when no retry is allowed. Legacy lease-return behavior remains separate from policy evaluation.
References: internal/…/scheduler.go• L1318-1495 internal/…/scheduler.go• L855-901 internal/…/scheduler.go• L1535-1647
Executor-facing state
Lease exchange
Executors represent target clusters and report their node capacity and current run placement to the scheduler. The lease stream returns new job runs to lease and control messages for runs that must be cancelled or preempted; the same exchange acts as an executor heartbeat.
For each lease, the scheduler provides the job run identity, queue and job-set context, executor placement, and the job data needed to start the workload. A run remains associated with its executor and node so later reports can update the right job attempt.
References: pkg/…/executorapi.proto• L13-37 pkg/…/executorapi.proto• L54-103 pkg/…/executorapi.proto• L106-116 internal/…/job_repository.go• L25-63
Executor reports
Executor reports move a run through leased, pending, running, and terminal outcomes. The scheduler does not treat a report as a complete job result until it reconciles the run with the job and applies the corresponding job-level transition.
If an executor stops heartbeating past the configured timeout, the scheduler expires jobs assigned to it. Without a policy retry, the job fails; with a policy retry, the expired run is terminated and the job is requeued. This protects the system from keeping work attached to a lost cluster.
Executor settings and executor-wide cancel or preempt requests use control-plane events. They change how the scheduler treats future leases or matching active runs rather than changing the queue definition.
References: internal/…/job_run.go• L22-75 internal/…/scheduler.go• L1535-1647 internal/…/executor.go• L40-217 pkg/…/executor.proto• L9-39
Query paths
Job status queries
The Query API reads the job and run view from the Lookout database. It maps stored state values to public job and run states, returns unknown for an absent or unmapped state, and limits the number of identifiers accepted in one request.
Clients can query a compact status map, full job details, run details by run ID, or job status by queue, job set, and external job URI. Full job details can optionally include the stored job specification and all runs, while the normal status path returns only the current job state.
References: internal/…/doc.go• L1-13 internal/…/query_api.go• L17-42 internal/…/query_api.go• L58-144 internal/…/query_api.go• L175-250 pkg/…/job.proto• L36-139
Stored state views
Job detail queries read the job record and use its latest run ID to connect the job to run history. Error queries prefer a job-level error and fall back to the latest run error, which gives clients one useful failure view without requiring them to join records themselves.
The active-queue query groups queues by pool from jobs and runs that are still active. This view helps clients see which queues currently have work associated with each scheduling pool; it is not a list of configured queues.
References: internal/…/query.sql.go• L72-99 internal/…/query.sql.go• L178-260 internal/…/query.sql.go• L263-345 internal/…/query.sql.go• L347-412 internal/…/query_api.go• L253-321
Event stream relationship
The job-set event stream exposes the history that leads to the query view. It checks queue and watch permissions, reads events from a requested position, and can either stop at the current end or continue watching for new events.
Some internal events exist only to keep scheduler and database state aligned. Public conversion exposes the client-facing submission, lease, run, success, error, cancellation, and preemption events while omitting internal coordination events such as requeue markers.
References: internal/…/event.go• L41-67 internal/…/event.go• L85-152 internal/…/conversions.go• L13-77 pkg/…/events.proto• L64-109
Change checklist
When these files or sections are changed, remember to consider these:
- Keep queue retry-policy attachment order consistent across the queue API, queue persistence, scheduler queue cache, and retry-policy selection.
- Keep queued-state version handling aligned between scheduler requeue or lease events and the event-ingester updates. A mismatch can make a valid state update look stale.
- Keep run terminal-state precedence consistent between executor reports, scheduler reconciliation, stored job-run state, and public state mapping.
- When changing retry limits or failure classification, update both the failure-count rules and lease-expiry handling. These paths must agree on which runs consume retry budget.
- When adding an executor-facing run state, update the executor protocol, event ingestion, scheduler reconciliation, and Query API state maps together.
- Preserve the query contract for latest-run errors and optional job or run expansion when changing Lookout query fields.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Queue cache has no successful refresh | The scheduler cannot use queue settings for validation or retry-policy lookup | Keep the queue cache refresh service running and inspect its refresh warnings |
| Queue references a policy missing from the policy cache | The job uses legacy failure behavior instead of a policy decision | Confirm policy API health and cache refresh success |
| Retry policy grants a mutated job that fits no node | The scheduler fails the job instead of requeueing it forever | Check node fit for resource and placement mutations |
| Executor misses heartbeats past the timeout | Active runs on that executor expire and either fail or requeue | Monitor executor heartbeats and set the timeout for the cluster failure model |
| Event publication fails after state generation | Scheduler cursors do not advance, so the next cycle regenerates the updates | Restore event transport and allow the next cycle to replay the unchanged window |
| Stored job or run state has no public mapping | Query clients receive UNKNOWN even when the record exists | Update state maps whenever stored or protocol states change |
Key files
| File | Why to read it |
|---|---|
| internal/…/queue_service.go | Queue management and queue-wide control requests |
| internal/…/queue_repository.go | Persistent queue definitions and retry-policy attachments |
| internal/…/scheduler.go | Scheduler cycle, state decisions, retries, leases, and expiry |
| internal/…/job.go | Job state rules, run history, attempts, and failure counts |
| internal/…/job_run.go | Run state and executor-facing run facts |
| internal/…/reconciliation.go | Conversion of stored job and run changes into scheduler state |
| internal/…/engine.go | Ordered retry decision rules and retry budgets |
| pkg/…/executorapi.proto | Lease exchange and executor report contract |
| internal/…/instructions.go | Application of event sequences to persistent job and run state |
| internal/…/query_api.go | Public job status and detail query paths |
| internal/…/query.sql.go | Stored job, run, error, and active-queue query shapes |
| pkg/…/job.proto | Public job and run state values and query RPCs |