Skip to main content

Module agent

Module agent 

Source
Expand description

The worker agent’s main loop: one control stream to the master, attempts and parse jobs, heartbeats and code watching (see archive/PROJECT.md, Worker lifecycle and Task assignment).

  • Connecting: the agent waits for each root’s first content hash (it settles too), registers with them and with the attempts it still runs or hasn’t had acknowledged, then follows the master’s decisions for those (continue, ack, kill).
  • Assignments: a free slot, an assignment that reads and the task’s code on this worker at the hash the master expects, or a rejection with the reason; then Started, the attempt runs, and Finished (naming the code it ran) is sent until the master acknowledges it.
  • Parse jobs parse a root’s .py files and upload the result, if the root still has the job’s hash (otherwise a newer hash was or will be reported).
  • The connection drops: attempts keep running, and the agent connects again with backoff (up to 30 s).
  • Shutdown (SIGTERM): the agent drains (see crate::drain): it says Draining (again after any reconnect), rejects new assignments, gives the running attempts until the termination grace period ends, interrupts the rest, and deregisters once the master has their results. A second request interrupts at once.
  • The journal on disk backs Started and Finished (see crate::journal): an attempt that can’t be recorded is rejected, and on start the agent reports the results its previous incarnation had and stops the processes it left running. Without /proc it warns once and leaves them.

The work itself goes through an Executor: processes in production (ProcessExecutor), something simpler in tests.

Structs§

Agent
The worker agent.
AgentSettings
The agent’s configuration.
NodeIdentity
A worker as a node of its deployment (decisions 121-123).
ParseCode
The copies of the other roots a parse sees (decision 102).
ProcessExecutor
Runs attempts and parse jobs as processes.

Enums§

SessionEnd
Why a session with the master ended.

Constants§

ALIVE_INTERVAL
How often the agent’s loop beats at least (liveness, see Agent::beat).
DEREGISTER_WAIT
How long a deregistered agent waits for the master to end the stream, at most: until the drain’s deregister_by (B237) by default, longer than any grace period. A stalled master still takes the Deregister once it reads again, the worker then shown offline (B242: a worker gone after 5 s dropped the unsent frame with its connection, and was shown disconnected).
DRAIN_TICK
How often a drain checks its deadline and whether it is done.
FIRST_BACKOFF
The first wait after the master connection drops; it doubles up to MAX_BACKOFF, and starts again here after a session in which the master registered the worker.
LARGEST_TASKS
The largest running tasks a heartbeat names (decision 463): what a node’s panel lists; the rest are in tasks_bytes.
MAX_BACKOFF
The longest wait between attempts to reach the master.
MAX_RESENDS
How many times a result is sent again over one session before the agent gives the session up and reconnects: its registration’s journal then settles the result (acknowledged, or sent again on Continue), and no session queues more copies of a result than this.
MAX_RESEND_GAP
The most heartbeats between two sends of an unacknowledged result: the gap doubles from one (B41), so a long stall of the master queues a few copies of each result, not one a heartbeat.
MEMORY_EXCEPTION
The exception named in the error summary of an attempt killed over its memory budget.
ORPHAN_GRACE
How long a process left running by a previous incarnation has between SIGTERM and SIGKILL.
RESULTS_PER_GROUP
Something happened in the background. The most results kept in the journal as one group (M4B.5): each a thread writing its file meanwhile.
STARTS_PER_GROUP
The most assignments whose journal records are written as one group (M5.1b), as many as RESULTS_PER_GROUP for the same reason: each a thread writing its file meanwhile.
START_FAILED
The error kind of an attempt whose process couldn’t be started.
UNSENT_ANSWERS
How many connections jobs’ answers the agent keeps while no master listens.

Traits§

Executor
Runs attempts and parse jobs.

Functions§

fold_hash
A root’s hash as reported, of its kind: a script root or a DAG root. A reported hash made from a root’s content hash: kind (script or dag) and the reported hashes of the script roots it uses, by name, folded in (decision 301; B167).
jittered
A backoff with jitter: between half of backoff and all of it, picked by seed (so many workers losing the master at once don’t come back in lockstep).
reconnect_cap
The longest wait between two tries to reach the master: max, but at most half the master’s worker lease once it has told it (B168), so a worker still alive reaches a master back from a restart before that master’s lease on it runs out; else the master would take it for lost and move its cleanups with only the handles it got (a handle registered while the master was away left behind).
with_memory
Adds what the watchdog saw to an attempt’s Finished: its peak memory, and for one killed over its budget the error summary saying so.

Type Aliases§

Spawned
Told the identity of an attempt’s process once it is spawned, and whether it was forked from a fork server: the task’s, then each try of its cleanup’s.
TaskEnded
Told a task’s result when its process has ended and its cleanup starts (decision 229).