7.9 Subprocess activities: the Go runner and the Python helper
The durable engine can now run Go activities with retries, heartbeats, and fenced leases (the task queue, the task protocol and workers, activities). But everything that matters to the platform’s users is Python: the corpus stages of the corpus pipeline in Data Engineering and the trainer from Build an LLM. Today {tinyllm} train is a command you type. If the laptop sleeps at step 9,000, the run is gone, and nothing records which checkpoint was last good.
Concepts from other sections (2)
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.
- OTLP/HTTP JSON: the OpenTelemetry export format used here, one
ExportTraceServiceRequestPOSTed to/v1/traces. Read more: 23.8 Serving metrics and tracing in AI Engineering - Heartbeat details: small progress data recorded with a heartbeat and handed to the next attempt so it can resume. Read more: 7.5 Activities
The obvious fix, starting the trainer from a Go activity with exec.Command and waiting, breaks three things at once. The server sees no heartbeats and fences the activity mid-run. A worker restart kills the child without a checkpoint, or worse, leaves it running. And a retry starts again from step 0 in a fresh directory. This section builds the bridge that avoids all three: a Go runner and a Python helper that keep one written contract, so that CorpusBuild and TrainRun can run Python work durably. With it in place, <system> train --spec specs/tiny.json survives a worker kill.
You will need the atomic checkpoints of Safetensors for every dtype, atomic checkpoints, and the token stream (its verify_step_dir decides when a checkpoint may be reported) and a working knowledge of exit codes and signals from Shell, git, make, processes in Programming and Algorithms. The interface between the two halves is written down in course/contracts/spec/subprocess-activity.md, with Python stubs in activity.pyi and telemetry.pyi and the span names in otel/semconv.md. The reference implementation is go/activities/subprocess.go (Subprocess.Run, Task, Heartbeat, Failure, WorkDir, Tail, Classify), python/tinyllm/io/activity.py (Activity, run, the exit codes), and python/tinyllm/io/telemetry.py (Tracer, parse_traceparent, OTLP/HTTP JSON export), wired into the worker by entry/go/cmd/worker/main.go.
Learning objectives
- Explain why the boundary between the platform and Python is a process, and what crosses it: files, environment variables, signals, and an exit code.
- Map every exit code to a retry verdict, and explain why a worker drain is not a cancellation even when the child exits 130.
- Turn checkpoints into heartbeat details so that a retry resumes instead of restarting, and keep the resume point alive until a newer one exists.
- Share one work directory across attempts safely with publish-by-rename,
DONE.jsonlast, and an exclusive lock.- Continue the activity’s trace into Python from
TRACEPARENTwithout ever letting telemetry fail the work.
In this part
Section titled “In this part”- Process contract and recovery: Define subprocess inputs, durable progress, termination, and telemetry.
- The Go subprocess runner: Trace process-group startup, monitoring, shutdown, and retry state in the runner.
- Python helper and exporter: Connect application progress/checkpoints to durable orchestration and export.
- Failure tests and integration: Challenge retry, timeout, checkpoint, and process-cleanup behavior.