Completes issue #2 on top of the phase-1 strict single-job FIFO scheduler. Removed: - Job.load_level / Manifest.load_level / CreateOptions.load_level and the manifest.json loadLevel field (old manifests still parse: unknown fields are ignored) - loadLevel in job JSON and <load_level> in XML output (field order shifts; old JSON still parses) - the [load_levels] config section, service.max_concurrent_jobs, ZAG_LOAD_LEVELS_*/ZAG_LOADLEVELS_*/ZAG_SERVICE_MAX_CONCURRENT_JOBS env vars, loadlevel.zig / loadclass.zig and the default .load files Friendly deprecation: old configs and environments still load fine. config validate and config show report the removed settings as non-fatal warnings (validate exit 1 stays reserved for real errors) and the CLI/daemon logs them once at startup. --load-level is gone from zag run; old IPC clients sending loadLevel are simply ignored. e2e: wait_state is now portable to macOS bash 3.2 (it silently skipped three checks before) and a serial-execution check asserts the second job stays QUEUED while the first runs and both finish in FIFO order. README and AGENTS.md document the deviation from barn.
5.3 KiB
AGENTS.md
Guidance for AI coding agents working in zag, the Zig port of the
barn Java job daemon. See README.md for the user-facing description.
Toolchain
- Zig 0.16.0 (
zig build,zig build test). The 0.16 std API differs from older releases (std.Io,std.process.Init); look atsrc/main.zigandsrc/daemon.zigfor working examples. - Library code lives in
src/and is exposed throughsrc/root.zig;src/main.zigis the thin binary entry point oversrc/cli.zig.
Porting rules
- Reference implementation:
../barn/src/main/java/com/samsonmedia/barn/. - Implement the documented behaviour (README,
../barn/docs/), not barn's bugs. - Keep CLI flags, JSON/XML output field order, config defaults and the on-disk job
directory layout compatible with barn (
zagreplacesbarnin names and paths). - Port specs from barn's unit tests alongside each module (
testblocks). - Intentional deviation (issue #2): zag runs only one job at a time (strict FIFO);
barn's load levels are gone. Old
[load_levels]/max_concurrent_jobssettings andZAG_LOAD_LEVELS_*env vars still load, are reported as non-fatal warnings, and ignored.
Layout
| Path | Purpose |
|---|---|
src/duration.zig |
\d+[mhdwMHDW] duration parser |
src/timestamp.zig |
ISO-8601 instant formatting/parsing (barn-compatible) |
src/state.zig |
Job states and the transition state machine |
src/jobid.zig |
job- + 8 hex job ids |
src/fsutil.zig |
Atomic writes, trimmed reads, advisory FileLock |
src/jsonpretty.zig |
Streaming JSON writer matching Jackson INDENT_OUTPUT layout |
src/toml.zig |
Parser for barn's TOML subset ([section], key = value, arrays) |
src/job.zig |
Job, Manifest, ExitCode types |
src/dirs.zig |
On-disk layout under the base dir |
src/statefiles.zig |
One-value-per-file job state (atomic) |
src/repository.zig |
Job create/find/transition/retry persistence, manifest.json I/O |
src/config.zig |
Config structs, defaults, TOML loading/merging, ZAG_* env overrides, validation, deprecated-setting warnings |
src/defaults.zig, src/defaults/ |
Default zag.conf embedded in the binary |
src/retry.zig |
Retry decision and backoff/jitter delay |
src/proc.zig |
Spawn with log redirection, process-group signals, liveness |
src/runner.zig |
Runs one job: heartbeat, timeout, kill, completion, retry |
src/recovery.zig |
Startup crash recovery of orphaned running jobs |
src/scheduler.zig |
Strict single-job FIFO scheduling, thread per job, killJob |
src/usage.zig |
ps/nvidia-smi sampling, usage.csv, summaries |
src/cleanup.zig |
Automatic and manual (zag clean) cleanup planning |
src/jobjson.zig |
Job JSON (shared by CLI --output=json and IPC) |
src/ipc.zig |
NDJSON-over-Unix-socket server and client |
src/service.zig |
Daemon core: recovery, scheduler, IPC handlers, cleanup timer, reload |
src/daemon.zig |
pid file, foreground run loop + signals, detached start, stop (TERM/KILL) |
src/output.zig |
JSON/XML rendering of a value tree, human helpers (bytes, ages, local time, colour) |
src/args.zig |
Option parser (long/short, =/separate values, --, stop-at-positional) |
src/query.zig |
Job listing filter shared by the daemon and offline CLI |
src/logging.zig |
Timestamped stderr logging with a runtime level |
src/cli.zig |
CLI dispatch, shared Context, help text |
src/cli_jobs.zig |
run, status, describe, usage, kill, clean |
src/cli_admin.zig |
service ..., config ..., autocompletion |
src/main.zig |
Binary entry point |
test/e2e.sh |
End-to-end smoke test (zig build e2e) |
src/servicemgr.zig |
systemd unit / launchd plist generation, install detection, manager commands |
Platforms
Linux and macOS only. Windows support was dropped on purpose, and building for a Windows target
fails with a clear compile error (src/root.zig). A few builtin.os.tag == .windows branches remain in
the code from the port; new code does not need to handle Windows.
Build notes
-
Branches:
mainis the default (same as the other submodules; the mono repo'smake updatepullsorigin main);developis the working branch. Mergedevelopintomainto publish docs andinstall.sh. -
build.ziglinks libc (forlocaltime_r) and defaults Linux builds tox86_64-linux-muslso the binary is static and does not depend on the host's crt files (the host linker fails on newer gcc.sframesections). -
Width/fill on a signed integer prints a leading
+({d:0>2}of ani64); cast to unsigned first. -
zig build e2erunstest/e2e.shagainst the built binary; CI runszig fmt --check, unit tests, the e2e test and a cross-compile of all four release targets (.github/workflows/ci.yml). -
Releases: tag
vX.Y.Z(must equal.versioninbuild.zig.zon);.github/workflows/release.ymlbuilds the static binaries and publishes them to Gitea, then updates the Homebrew formula insamson-media/homebrew-tapwhen theTAP_TOKENsecret is set (.github/ci/render-formula.sh). -
Gotchas: never return a struct holding a pointer into itself (e.g. an
Allocatingwriter plus ajsonpretty.Writerover it) -- initialise it in place (Payload.initincli_jobs.zig).