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, andFinished(naming the code it ran) is sent until the master acknowledges it. - Parse jobs parse a root’s
.pyfiles 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 saysDraining(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
StartedandFinished(seecrate::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/procit 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.
- Agent
Settings - The agent’s configuration.
- Node
Identity - A worker as a node of its deployment (decisions 121-123).
- Parse
Code - The copies of the other roots a parse sees (decision 102).
- Process
Executor - Runs attempts and parse jobs as processes.
Enums§
- Session
End - 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 theDeregisteronce 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_GROUPfor 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(scriptordag) 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
backoffand all of it, picked byseed(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.