B.10.1 What the System Does After Pass 8
After Pass 8 the data pipeline and training run as workflows (CorpusBuild, TrainRun, and EvalSuite) on the course’s own durable engine, with durable and worker charts autoscaled by KEDA and control-plane traces. The durable engine runs workflows to completion through the CLI, locally and on kind. As optional depth, the durable log survives leader kills and partitions on three Raft replicas. Everything from earlier passes keeps working. This page gives the commands the finished solution runs, what each produces, and why each piece is needed.
Concepts from other sections (8)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- KEDA: an operator that scales workloads on external metrics by creating and driving an HPA. Read more: 10.7 Durable and worker images and charts in Systems Engineering
- StatefulSet: a workload controller that gives each Pod a stable name and its own persistent claim, with ordered rollout. Read more: 10.7 Durable and worker images and charts in Systems Engineering
- Kill loop: a seeded loop that crashes the system at many points and checks every promise at the end. Read more: 3.7 Resilience tests in Software Engineering
- SIGKILL: an uncatchable signal that ends a process between two instructions, leaving only what is on disk. Read more: 12.3 The durable server is SIGKILLed in a loop during a corpus build in Systems Engineering
- task queue: the durable server’s routing key; only pollers of queue
agentreceiveAgentRuntasks. Read more: 10.8 The agent image and chart in Systems Engineering - Poison task: a task that fails the same way on every attempt, so retries cannot fix it. Read more: 12.4 A poison task lands in the dead-letter queue in Systems Engineering
- RPC: a remote call presented as a local function call through a generated stub. Read more: Chapter 3: RPC and Protocols in Systems Engineering
- Linearizability check: verification that every acknowledged write is present, in order, as if executed on a single copy. Read more: 12.13 A Raft partition (optional) in Systems Engineering
The engine is the durable-orchestration chapter of AI Engineering, from the append-only event log, the workflow service, and the task queue through workers, activities, deterministic replay, timers, signals and sagas, and subprocess activities, to the workflows CorpusBuild and TrainRun and EvalSuite. Around it are the durable and worker charts, control-plane observability, resilience tests, and two drills: the durable server SIGKILLed in a loop and a poison task. The optional depth is Raft high availability with the Raft partition drill.
Workflows run to completion, locally and on kind
Section titled “Workflows run to completion, locally and on kind”The durable server, the worker, and the Python activities the worker execs run workflows to completion through the system’s own CLI. A start is idempotent, the history is recorded, CorpusBuild produces the same corpus as the direct {corpus} run of Pass 3, and a short TrainRun finishes. On kind, the durable StatefulSet and the KEDA-scaled workers carry a queue burst with control-plane traces, and the drills durable-kill9 and poison-task are resolved.
The point of the pass is that failures do not change results. Under a kill loop (500 tl.test.Append activities with SIGKILLs of {durable}, {worker}, and the Python children), every effect lands exactly once in an effects sink. CorpusBuild under kills of both services produces the same corpus as an uninterrupted run, and TrainRun under kills of the worker reaches the same steps and final loss. The same invariants hold one level down, in the sections themselves: the event log is tested under a kill loop, the task queue with a poison task and a stale lease, workers and activities under a kill loop with the effects sink, deterministic replay with the server killed mid-workflow and replayed, and subprocess activities with a worker SIGKILLed mid-activity that resumes from its checkpoint.
Why this matters: corpus builds and training runs take hours. Running them as durable workflows means that a crash, a deploy, or a preempted node costs a retry from the last recorded step, not the whole run, and the history says exactly what happened.
The workflow verbs
Section titled “The workflow verbs”The solution defines the Pass 8 verbs of the ctl role under “Verbs of later passes” in cli-roles.md. Every verb keeps the rules of that page: exit 2 on a usage error, exit 1 on an RPC error with its gRPC code and message on stderr, and the last stdout line is one JSON object. --durable <host:port> names the server (default $TL_DURABLE_ADDR, else 127.0.0.1:7233). Status names drop the proto prefix: RUNNING, COMPLETED, FAILED, CANCELED, CONTINUED_AS_NEW.
{ctl} wf start <type> --id <workflow id> [--input-json <json>] [--queue <q>] [--wait] [--json] StartWorkflow (task queue default "default", input the JSON bytes, default null); with --wait, DescribeWorkflow until the run is not RUNNING. Final line: {"workflow_id", "run_id", "started", "status", "result"} where started is StartWorkflowResponse.started and result is the run's result parsed as JSON (null until COMPLETED). SleepDemo is registered with the durable timers: input JSON is an integer duration in milliseconds and its result is the fired time. tl.test.Batch (input N) runs N tl.test.Append activities with the SDK's activity ids 1 to N, so the effects sink receives the keys "<workflow id>/1" to "<workflow id>/N"; each append holds 100 ms after its effect (a kill then lands between effect and completion); its result is N. --wait polls through a server that answers Unavailable while it restarts, for up to 2 minutes in a row.
{ctl} wf describe <workflow id> --json DescribeWorkflow. Final line: {"workflow_id", "run_id", "status", "history_length", "pending_activities", "dead_lettered"} (the last two are counts).
{ctl} wf history <workflow id> --json GetHistory, every page: one JSON line per event {"event_id", "type"} (type is the HistoryEvent attribute name, e.g. "WorkflowExecutionStarted"), then a final line {"events": N, "first": "<type>", "last": "<type>"}.
{ctl} wf dlq list <queue> --json ListDeadLetters, every page: one JSON line per dead letter {"task_id", "workflow_id", "activity_type", "attempts"}, then {"queue", "count"}.
{ctl} wf dlq redrive <queue> (--all | <task id>...) --json RedriveDeadLetter. Final line: {"queue", "redriven"}.
{ctl} data build --config <corpus toml> --id <workflow id> [--wait] [--json] Starts CorpusBuild on the config. With --wait, the final line is the CorpusBuild result: Pass 3's RUN-<dataset>-<version> object (the same keys and values as {corpus} run) plus "workflow_id" and "status".
{ctl} train --spec <file> --id <workflow id> [--wait] [--json] Starts TrainRun on a train spec (formats/train-spec.schema.json). A spec without "out" gets out = "runs/<workflow id>", so a run resumes only its own checkpoints. With --wait, the final line is {"workflow_id", "status", "steps", "final_loss", "ckpt"}; the loss is the run directory's final.json, the same after a retry that resumed from the final checkpoint.How the solution is wired
Section titled “How the solution is wired”The entry points are under go/cmd, and the charts under deploy/helm:
[entry].durable, [entry].worker, [entry].ctl[services.durable] health = "http://127.0.0.1:{health_port}/healthz"; its config template puts the WAL under {data}[services.worker] after = ["durable"], argv --queue default --durable 127.0.0.1:{durable.grpc_port} --test-activities plus queue data for CorpusBuild, and an artifacts root of {data} (the subprocess contract's /artifacts), so the files land in {worker.data}specs/tiny.json the TrainRun spec: a few hundred thousand parameters, 20 steps, its data the tokens CorpusBuild wrote (paths relative to the artifacts root: "tokens/bytes/small/train-00000.bin")[deploy] as for Pass 7's production deploy, plus services.durable = "statefulset/<system>-durable" and services.worker = "deploy/<system>-worker"; the durable NodePort is 30733 (set up with the kind cluster's port mappings)The port mapping comes from the kind cluster and local registry, and the StatefulSet and worker Deployment from the durable and worker charts.
Optional depth: three Raft replicas survive leader kills and partitions
Section titled “Optional depth: three Raft replicas survive leader kills and partitions”The durable server with --replicas 3, three nodes of the Raft implementation talking tl.raft.v1, carries the durable kill loop: workflows run while the leader is killed and partitioned away, every acknowledged append survives, and the client history is linearizable.
It is worth being precise about what is demonstrated and what is not. The Raft section’s tests check the raft package in-process: a seeded simulation with partitions, drops, reordering, crash-restarts, and a linearizability check over the client history, plus a leader kill with 20 acknowledged appends. On kind, the StatefulSet runs three Ready replicas that complete a workflow through the NodePort. A full kill loop against three local replicas (killing a named replica and cutting links between them while workflows run) is not part of the solution yet.
On kind, the durable chart renders replicas: 3 with [durable].raft.enabled, raft.id taken from the pod ordinal, and the peers <system>-durable-<i>.<system>-durable-headless:7234, using the headless Service of the durable chart. A follower answers a client RPC with UNAVAILABLE and the trailer tl-raft-leader (defined in proto/tl/raft/v1/raft.proto). The ctl retries against the leader it names, so --durable 127.0.0.1:30733 reaches whichever pod the NodePort picks.
Pass 9 uses these workflows to train and release the capstone.