Skip to content

Jobs

Workers process two job kinds: flake jobs and build jobs. The sections below document the messages, the reports, and failed, aborted and lost jobs.

  • The server delivers work as AssignJob { job_id, assignment_id, job, cluster } messages.
  • Echo the assignment_id in JobUpdate, JobCompleted, JobFailed, BuildProgress and EvalProgress. Reports with a stale assignment_id will be rejected by the server.
  • Workers accept a re-sent AssignJob for a job already in progress. Reports for that job then echo the new assignment_id.
  • Only cluster members receive a cluster field.
  • Reports of a session go into a queue of 64 events, off the session's read loop. Reports apply in arrival order.

Flake Jobs

Flake jobs fetch and evaluate a flake. The server can pick the steps at queue time.

Situation Steps
An idle evaluation-only worker is available, and the evaluation is no cluster member [FetchFlake], then a follow-up job [EvaluateFlake, EvaluateDerivations] on the Cached source
Otherwise All three steps in a combined job
Field Meaning
steps FetchFlake, EvaluateFlake, EvaluateDerivations
source Repository { url, commit }, or Cached { store_path } for a follow-up job or a gradient build upload
wildcards Attribute patterns to evaluate
timeout_secs Optional limit, sent as None by the server today
input_overrides Flake input overrides of the task
input_update Set for a flake update

Fetch

  1. Clone the repository. Skip the clone for a Cached source.
  2. Run the flake update generator for a job with input_update.
  3. Serialise the tree at the pinned commit as a NAR, without a nix process. Add the NAR to the store as <narHash>-source, the path of nix flake prefetch for the same tree.
  4. Leave out inputs with an override. Overrides apply at evaluation. Override names without a matching input end up as EvalMessage warnings.
  5. Pull missing locked inputs from the Gradient cache. Fetch the rest with builtins.fetchTree in an eval worker.
    • Inputs of the same second-level domain (such as github.com) download in sequence. Different domains download in parallel.
    • Failed inputs drop out with a warning.
  6. Report FetchResult { flake_source }.
  7. Upload the source and the inputs with a Push cache query. Upload and evaluation steps of the same job run side by side.

  8. Upload failures fail the whole flake job.

  9. Fetch-only jobs send JobCompleted after the upload, with EvalProgress resent meanwhile.
  10. The server can then queue the follow-up job. Evaluations without a flake_source fail instead.

Evaluate

Step Worker action
EvaluateFlake Status EvaluatingFlake only, no work
EvaluateDerivations Eval cache pull, attribute discovery, closure walk, eval cache push
  • Eval Cache: Before discovery, workers pull the evaluation cache segments they lack. New rows travel up as segments every 30 s, plus once after a successful evaluation. See Shared Eval Cache.
  • Eval Cache Segments: Segments each belong to one cache. Pulls read segments from every readable cache of the project. Pushes write into the first writable cache. Compaction can then copy the result into the other writable caches.
  • Attribute Failures: Workers send them as EvalMessage { level: Error, source: "nix-eval:<attr>" } before the last EvalResult.
  • Import From Derivation: Workers send ImportRequest { drv_paths } during discovery and wait for ImportResult.
  • Missing Inputs: Workers send InputRequest { request } for an input in neither the store nor the cache, and wait for InputResult. The server can send the download as FetchInput to a worker with network. That worker can push the input under the fetch_id and answer with InputFetched.
  • Walk: Workers walk an entry point as soon as discovery returned it.
  • Waves: Waves hold up to 256 of the most recently found derivations. Leaf derivations then come early in the walk, and their builds can start mid-evaluation.
sequenceDiagram
    participant W as Worker
    participant S as Server
    loop each wave with unvisited dependencies
        W->>S: QueryKnownDerivations { drv_paths }
        S->>W: KnownDerivations { known }
    end
    loop every 500 derivations with reported or known inputs
        W->>S: CacheQuery { Push } + uploads (.drv files, sources)
        W->>S: JobUpdate { EvalResult { derivations } }
    end
    W->>S: JobUpdate { EvalResult { derivations, warnings } }
    W->>S: JobUpdate { EvalStats }
    W->>S: JobCompleted
  • Derivations in known have complete closures in the graph. Workers skip their subtrees.
  • Workers treat a failed QueryKnownDerivations as an empty known. Full rewalks get an empty known too.
  • Batches upload their .drv files and input sources before their EvalResult message. Builds can start during the walk.
  • Input .drv files travel with the batch walking the input.
  • Walk and batch uploads run side by side. Uploads of consecutive batches overlap.
  • Batch uploads come before the EvalResult message for each batch. Batches go out when they reach 500 derivations or 1 MiB during traversal. A derivation can only join a batch, if each input derivation is in that batch, in an earlier batch of the job, or in known.
  • Workers query and upload each path no more than once per evaluation, apart from the input upload of the fetch step.
  • The server can store each batch in the graph and move each startable build to Queued right away.
  • Consecutive EvalResult batches of a job, already waiting in the session queue, reach the graph writer together. Limits of the merge: 5000 derivations, and no other event in between.
  • Evaluations in EvaluatingFlake or EvaluatingDerivation turn Building on JobCompleted.
  • EvalResult errors (no derivation matched, a failed listing) become error messages. Error messages fail the evaluation at the end.

Build Jobs

Each build job contains a single BuildSpec and maps to one shared build (a derivation_build).

kind Condition Work performed
Build Default Prefetch the inputs, then build the derivation with the Nix daemon
Substitute Outputs exist in an upstream cache Fetch the outputs without a Nix store
Download Fixed-output derivation on the builtin system Download the file without a Nix store
  • Substitute and Download jobs can run on any worker, since these use the builtin system.
  • Build jobs also receive drv_path, outputs, is_fixed_output, timeout_secs and max_silent_secs from the spec.
  • Defaults: build.defaultTimeoutSecs (14400) and build.defaultMaxSilentSecs (3600).

  • Check for an abort request first. Then report Building, before anything that can fail.

  • If all outputs already exist in the local store, skip prefetch and build. Report BuildOutput { substituted: true } and upload the outputs anyway.
  • Prefetch: Read the .drv, drop inputs already present in the store, and fetch the remaining ones over the transfer protocol.
  • Run the build through the daemon. Stream the log as LogChunk messages.
  • Report BuildOutput with the outputs, hydra-build-products and metrics.
  • Upload the outputs, then send JobCompleted. An upload failure marks the job as Transient.

Reports

JobUpdate kind Effect on the server
Fetching, EvaluatingFlake, EvaluatingDerivations Evaluation status
FetchResult { flake_source } Store the fetched source in evaluation.flake_source
EvalResult Store a batch of derivations in the graph
EvalStats Evaluation metrics
InputUpdateResult Flake update candidate lock and bumped inputs
InputSources Repository and branch of each tracked flake input (protocol 56 and later). These details match a push to the input repository.
InputUpdateExpansion Input names matched by a glob in a discover_only pass. A new evaluation per name
Building { build_id } Build turned Building. Already aborted builds get AbortJob instead
BuildOutput Output sizes, build products, metrics, the substituted flag
Stage(Prefetch / Build / Upload) Live stage of the job in the worker pool, used for the estimated time. Prefetch and Build apply to the Build kind only
Compressing No change. Workers no longer send it
  • EvalProgress messages hold one download row per flake input during fetch, and the live thunk count during evaluation.
  • Download rows appear only with a missing input. Eval workers download the inputs themselves, with at most 1 download per second-level domain.
  • JobCompleted and JobFailed hold the phase timeline shown on the Job Board.
  • Build metrics also hold the number of concurrent builds on the worker, the cores of the build and the worker's CPU score.

Failures

BuildFailureKind Result
Transient Retried up to build.maxAttempts (3), backoff build.retryBackoffSecs (30 s) doubling. Builds available in a cache take the substitution miss path after the last attempt
Permanent Failed. Builds needing the failed build turn DependencyFailed
Timeout Timed out. Builds needing the timed-out build turn DependencyFailed
SubstituteUnavailable Re-queued. Built normally after build.substituteMissEscalationThreshold (2) misses
InputsUnavailable Self-heal, see below
CorruptEvalCache Purging the evaluation cache segments and re-queuing the evaluation. A repeat within one hour of the purge, or with nothing to purge: evaluation Failed. For builds: Permanent
Aborted Aborted by the server. No cascade
Canceled Stopped by the worker. Re-queued without using an attempt, see Worker Stop
  • InputsUnavailable: An input listed by the cache was missing. Causes are an uncached path, 404/410 on the URL, NarUnavailable or a NAR hash mismatch.
    • The server can delete the outdated cache row and object, reset the producing build and retry.
    • Inputs still present but without a producer stay in place.
    • Builds fail permanently after build.inputsUnavailableMaxLoops (3) loops. InputsUnavailable failures also use up attempts. Attempts and loops both default to 3. Attempts run out first.
  • DependencyFailed can spread upward over the dependency graph from Permanent and Timeout failures, across evaluations.
  • Eval Job Outage: Eval jobs failing Transient re-queue the evaluation, up to build.maxAttempts (3) attempts. Abandoned dispatches stay out of this count.
    • Typical causes are a dropped server connection, or an object PUT or CacheQuery without an answer.
  • Out of Memory: Builds killed by the kernel for memory count as Transient, whatever kind the worker sent. The attempts close with the reason Oom.
    • Out-of-memory failures only return to FailedTransient without consuming build.maxAttempts if the attempt has a known project and BuildMetrics.build_cores is above 1 and below every earlier kill of that derivation in the same project. Other kills consume one attempt. The next attempt can reduce the core count by one third.
    • A kill at 1 core can end the build as FailedPermanent with the message ran out of memory with 1 core.
    • Out-of-memory builds from workers without a core count use up attempts like other Transient failures.
  • Builds Larger Than Every Worker: Builds wait for a larger connected worker available to the project when they exceed the total RAM of the worker at the largest core step. They run there at that step. Builds wait for that largest worker when predicted RAM is above the capacity of all workers. They wait for that worker even with 1 core and RAM proportional to the core count. Smaller workers accept neither kind. Such builds can fail only through an out-of-memory kill. Only attempts from releases before 2.1 have reason NotEnoughResources.
  • Evaluations end Completed, or Failed with a build in Failed, Aborted or DependencyFailed, or with an error message present.

Cluster Members

Cluster members reach workers in an AssignJob with cluster = { attempt, role, index, hold_secs }.

Event Worker
AssignJob with cluster The worker reserves the slot without running the job, then accepts it. A second member of the same attempt gets rejected
StartCluster { attempt, roster } The worker starts the held member. The roster opens the member's signal route
ClusterSignal from the server The worker delivers the signal to the inbox of the running member of that attempt. After that member finished, the worker drops signals. No executor reads the inbox yet
ClusterSignal to the server The worker forwards signals on the wire only. The server handles routing. No executor sends signals yet. to = None reaches all other started members
AbortCluster { attempt } The worker drops a held member without a report and aborts a running member with JobFailed { Aborted }
AbortJob for a held member The worker releases the slot and reports JobFailed { Aborted } with aborted by server
No StartCluster within hold_secs The worker releases the slot and reports JobFailed { Aborted } with cluster start timed out. The check runs on the 10 s heartbeat, so detection can lag by up to 10 s
Worker stop The worker releases all held members the same way, with worker draining
  • Held members count against eval.maxConcurrent / build.maxConcurrent like running jobs.
  • Held exec members lease a guest address first and accept with AssignJobResponse.endpoint set to that address. Workers reject the member with No free guest addresses in `exec.subnet.v4` on a full subnet.
  • Versions 11 and later of the guest protocol include GuestNetworkIpv6 in RunJob.network.ipv6_configuration, with an address, a prefix length and a gateway. Workers fill this field only when worker configs set option exec.subnet.v6. Agents below protocol 11 receive no IPv6 configuration and use IPv4 only.
  • Exec job executors get the roster and the lease from the worker on StartCluster. The executor can build the cluster context from the roster endpoints and JobContext.master_port.
  • Duplicate roster addresses fail the node with Two nodes have guest address <address>. Assign a unique exec.subnet.v4 to each exec worker.
  • hold_secs: the server's scheduler.clusterPrepareTimeoutSecs (30 s) plus a 10 s margin.

Split Evaluation Members

A cluster member with the role split-evaluation-primary or split-evaluation-companion can evaluate part of one flake (gradient-worker/src/executor/eval_split.rs).

Member Steps
Primary Fetch the flake as usual. Push the inputs during planning, then send EvalSourceReady. Ask with EvalShardRequest { have_source = true }. On Plan: plan the shards, report the plan errors, upload the new eval cache rows, send EvalShardsPlanned. Then take shards
Companion Ask with have_source = false until Source arrives. Fetch that store path from the cache. Then take shards
Taker loop Per shard: pull new eval cache segments, pull drv_paths in one batch, list the shard across the local subprocesses, stream EvalResult batches. The next request can carry finished with the deferred sets
End Finished: send EvalStats, then JobCompleted
  • A Wait response can pause a member for retry_after_ms (1000 ms). A member with a running shard can poll again after the pause. That member can also poll sooner when the shard completes.
  • Only the primary can report EvaluatingFlake and EvaluatingDerivations.
  • A 30 s flush timer uploads new eval cache rows while shards are running, up to 4 segments at a time. One final upload follows the last shard.
  • Message shapes: Split Evaluation Messages.

Abort and Lost Workers

  • API Abort: The evaluation receive the status Aborted. Pending jobs of the evaluation leave the queue.
  • AbortJob messages arrive at the evaluation job. A running build with no other evaluation behind it can also get one.
  • All evaluations that wanted the build take part in the decision, Completed and Failed ones included. Dispatching evaluations don't take part.
  • Newer Evaluation: A task with hard_abort concurrency abort the older evaluation of the branch in the same way as an API abort. A task with soft_abort cancel only its eval job.
    • A task with auto concurrency act like hard_abort. The abort take place after the newer evaluation moved to Building.
  • Unbuildable Evaluation: An evaluation with no worker for its systems also finish Aborted.
  • Workers stop the daemon build at once and answer with JobFailed { Aborted }.
  • Assignments of an unconfirmed abort close as abandoned after 5 min.
  • Reclaim Grace: A disconnected worker keeps its open assignments for proto.assignmentReclaimGraceSecs (600 s). A grace can't outlast the remaining maxLifetime of a worker that disconnected from a running server.
    • Workers list their running jobs in RunningJobs after the reconnect. The server reattaches each listed assignment, and the job continues.
    • The unreclaimed-job-sweep pass checks every 10 s on every server instance. A job can outlast the grace by up to 10 s.
    • Open assignments left by a server restart get the full grace.
    • Cluster members, server-dialed sessions and a grace of 0 skip the wait.
    • A worker back after the grace receive AbortJob for its listed jobs. That loss can increase the lost-worker streak by one at most.
  • Lost Worker: A job without a reclaim within the grace has a lost worker. A job missing from RunningJobs has one at once. Open assignments close as abandoned.
    • Each build in Building return to Queued. Its running attempt close as Aborted with the reason WorkerLost.
    • A build with 10 lost workers in a row finish FailedPermanent. An attempt closed in any other way reset the row. A requeue after an ended cluster attempt do not count as a lost worker.
    • Running evaluations move to Waiting and back into the queue.
    • An evaluation with 10 recorded eval dispatches fail on the next lost worker. Dispatches of all outcomes count, fetch-only and canceled jobs included.

Worker Stop

sequenceDiagram
    participant W as Worker
    participant S as Server
    Note left of W: SIGTERM
    W->>S: JobFailed with Aborted (held cluster members)
    W->>S: Draining
    Note left of W: aborting all running jobs
    W->>S: JobFailed with Canceled
    W-xS: close
  • Workers first release the cluster members that they hold. They then send Draining and abort all running jobs. Exec jobs keep running with stopGuestsWithWorker = false and resume after a restart.
  • Canceled jobs report JobFailed { Canceled } together with the phase timeline. Transient failures during shutdown (a lost nix-daemon connection, for example) also report as Canceled. All other failures keep their kind.
  • Workers wait up to 5 s for these reports.
  • Jobs without a report within the 5 s re-queue with the closed session, as for a lost worker.
  • Canceled builds return to Queued. Their attempts close as Aborted and stay out of build.maxAttempts and the substitution miss count.
  • Canceled eval jobs return their evaluation straight to Queued.
  • Their assignments close as abandoned. These stay out of build.maxAttempts, but still count toward the 10 eval dispatches above.