Flatten priority (load levels): run only one job at a time #2

Open
opened 2026-11-11 19:45:35 +00:00 by daniel · 0 comments
Owner

Summary

Flatten the priority feature (load levels: high/medium/low classification with per-level concurrency limits 2/8/32) so that only one job runs at a time — strict FIFO by created_at.

Decisions (locked):

  1. Full removal of the load-level system: enum, classifier, .load files, [load_levels] config section, --load-level CLI flag, loadLevel JSON/XML fields, LOAD column in zag status.
  2. service.max_concurrent_jobs removed too (already deprecated).
  3. Friendly deprecation: old configs containing [load_levels] or max_concurrent_jobs still load fine; config validate and config show report them as non-fatal warnings, and the daemon logs them once at startup. ZAG_LOAD_LEVELS_* / ZAG_SERVICE_MAX_CONCURRENT_JOBS env vars are likewise detected, warned about, and ignored.
  4. web/ is out of scope — no changes there (consequences documented at the bottom).

Feature footprint

Area Files
Model + classification src/loadlevel.zig, src/loadclass.zig, src/job.zig (Job.load_level, Manifest.load_level)
Concurrency src/scheduler.zig (limits, counts[3], runningAt, setLimits, limitFor)
Config surface src/config.zig (LoadLevels, [load_levels] section, ZAG_LOAD_LEVELS_* env, validation, problems()), src/defaults/zag.conf, src/defaults/*.load, src/defaults.zig
CLI src/cli_jobs.zig (--load-level/-l on run, LOAD column in status), src/cli_admin.zig (config show/install, autocompletion, service-start wiring), src/cli.zig (help test)
IPC/daemon src/service.zig (loadLevel payload, Options.classifier, reload→setLimits)
Output src/jobjson.zig (loadLevel JSON field), src/output.zig (<load_level> XML)
Persistence src/repository.zig (CreateOptions.load_level, manifest.json loadLevel)
Docs/tests README.md, AGENTS.md, test/e2e.sh, unit tests

Implementation plan

Phase 1 — Scheduler: strict single-job FIFO (src/scheduler.zig)

  • Delete Options.limits, counts[3], runningAt(), setLimits(), limitFor(); Active loses level.
  • Capacity check: active.count() >= 1 → AtCapacity. Everything else (scheduler file lock, tick loop, stop(), killAll, killJob, retry-at skip, FIFO-by-created_at) stays.
  • Tests: replace the three limit tests with never more than one running at a time + FIFO completion order tests; keep retry/kill/single-scheduler tests.

Phase 2 — Job model & persistence

  • src/job.zig: drop load_level from Job and Manifest.
  • src/repository.zig: drop CreateOptions.load_level; manifest writer drops loadLevel; reader tolerates old manifests (unknown fields already ignored).
  • src/jobjson.zig: drop loadLevel from writeJob and RawJob (old JSON still parses; JSON field order shifts — note in docs).
  • src/output.zig: drop <load_level> XML element + update the XML-shape test.

Phase 3 — Config surface (src/config.zig, src/defaults/)

  • Delete LoadLevels; remove load_levels from Config, validate(), fromDoc(), known_sections, checkSection/problems(), and both env-section aliases (load_levels/loadlevels). Remove max_concurrent_jobs field + its validation entry.
  • Deprecation detection (new):
    • Problem gains a deprecated: bool (or a separate warnings list); problems() special-cases section load_levels and key service.max_concurrent_jobs → warning: "deprecated: only one job runs at a time; remove it from your config" instead of "Unknown section/key".
    • config.load() gains an optional diagnostics-out (same Diagnostic pattern already used): when a loaded file contains either, it records a warning. Callers: daemon startup logs it once (std.log.warn); config validate prints it but does not fail (exit 1 stays reserved for real errors); config show prints a warning line above the effective config.
    • applyEnvironment() special-cases ZAG_LOAD_LEVELS_* / ZAG_LOADLEVELS_* / ZAG_SERVICE_MAX_CONCURRENT_JOBS → warning + ignore instead of silent no-match.
  • src/defaults/zag.conf: delete [load_levels] section + the deprecated max_concurrent_jobs comment.
  • Delete src/defaults/{high,medium,low}.load, their entries in src/defaults.zig (files = zag.conf only), and delete src/loadlevel.zig, src/loadclass.zig + their src/root.zig exports.

Phase 4 — CLI & output

  • src/cli_jobs.zig: drop --load-level/-l (opts + usage + run_job IPC payload + runOffline classifier); remove LOAD column from printStatusTable.
  • src/cli_admin.zig: configNode/cmdConfigShow lose [load_levels] (plus the new deprecation warning line); config install installs only zag.conf (usage text updated); autocompletion drops the -l|--load-level case and the flag from run opts; service-start wiring (~line 129) no longer builds a Classifier.
  • src/cli.zig: help test now asserts --load-level is absent from run --help.

Phase 5 — IPC/daemon (src/service.zig)

  • Options: delete classifier; schedulerOptions: delete .limits.
  • hRunJob: delete loadLevel parsing/validation (old clients sending the field are simply ignored — protocol stays backward-compatible).
  • reload(): delete setLimits call. Delete the "load level is auto-classified or overridden" test; drop .load_levels from the harness config.

Phase 6 — Tests & e2e

  • Update all unit tests listed in phases 1–5 (config defaults/embedded/env/validate/problems; repository manifest round-trip; jobjson layout; output XML).
  • Add config tests: doc with [load_levels] → problems() returns 1 deprecation, cmdConfigValidate exits 0; same for the max_concurrent_jobs key and ZAG_LOAD_LEVELS_MAX_HIGH_JOBS env.
  • test/e2e.sh:
    • config show --defaults no longer asserts max_high_jobs = 2 (assert it is absent);
    • install --show asserts zag.conf, not high.load;
    • new: config with [load_levels] → config validate exits 0 and prints the deprecation note;
    • new serial-execution check: two sleep jobs via IPC → second stays QUEUED while first is RUNNING, both finish in FIFO order.

Phase 7 — Docs

  • README.md: delete the "Load Levels" section, the load_level table row, and the --load-level override paragraph; fix "Migration from barn" (env example ZAG_LOAD_LEVELS_MAX_HIGH_JOBS works, the .load-lists bullet, the config show bullet) and add explicit deviation notes: one job runs at a time, no load levels / loadLevel field, deprecated sections accepted-but-ignored with a warning.
  • AGENTS.md: drop the loadlevel.zig/loadclass.zig layout rows, update the defaults row, note the intentional barn deviation.

Phase 8 — Verify

  • zig fmt --check, zig build test, zig build e2e, release cross-compile (per CI).
  • Manual smoke: config install --show, config show --defaults, config validate on an old conf (exit 0 + deprecation note), daemon start with an old conf (one warning line), two sequential zag run calls serialize.

Consequences for web/ (out of scope — no changes made)

  • ZagJob DTO: loadLevel ?? 'MEDIUM' → synced jobs will always appear MEDIUM (harmless).
  • Breaking: if a user submits load_level in the web UI, ZagClient::run appends --load-level=… and the new zag exits 2 → that job fails to start. ZagJob model's load_level column stops being meaningful.
  • Future follow-up (separate repo/PR, not part of this issue): drop ZagLoadLevel, the load_level request param in Run.php, the loadLevel arg in ZagClient::run, and the DTO/model fields.

Risks

  • Throughput change is intentional: up to 32 parallel downloads now serialize into one — pipeline wait times will grow.
  • Breaking for anything parsing zag's JSON/XML or using --load-level — only web/ does, today.
  • Old on-disk jobs keep working (lenient manifest/JSON parsing); automatic cleanup removes them over time.
  • No cluster actions involved; pure code + docs in zag/, one PR.
## Summary Flatten the priority feature (load levels: `high`/`medium`/`low` classification with per-level concurrency limits 2/8/32) so that **only one job runs at a time** — strict FIFO by `created_at`. **Decisions (locked):** 1. **Full removal** of the load-level system: enum, classifier, `.load` files, `[load_levels]` config section, `--load-level` CLI flag, `loadLevel` JSON/XML fields, LOAD column in `zag status`. 2. **`service.max_concurrent_jobs` removed** too (already deprecated). 3. **Friendly deprecation**: old configs containing `[load_levels]` or `max_concurrent_jobs` still load fine; `config validate` and `config show` report them as **non-fatal warnings**, and the daemon logs them once at startup. `ZAG_LOAD_LEVELS_*` / `ZAG_SERVICE_MAX_CONCURRENT_JOBS` env vars are likewise detected, warned about, and ignored. 4. **`web/` is out of scope** — no changes there (consequences documented at the bottom). ## Feature footprint | Area | Files | |---|---| | Model + classification | `src/loadlevel.zig`, `src/loadclass.zig`, `src/job.zig` (`Job.load_level`, `Manifest.load_level`) | | Concurrency | `src/scheduler.zig` (`limits`, `counts[3]`, `runningAt`, `setLimits`, `limitFor`) | | Config surface | `src/config.zig` (`LoadLevels`, `[load_levels]` section, `ZAG_LOAD_LEVELS_*` env, validation, `problems()`), `src/defaults/zag.conf`, `src/defaults/*.load`, `src/defaults.zig` | | CLI | `src/cli_jobs.zig` (`--load-level/-l` on `run`, LOAD column in `status`), `src/cli_admin.zig` (`config show`/`install`, autocompletion, service-start wiring), `src/cli.zig` (help test) | | IPC/daemon | `src/service.zig` (`loadLevel` payload, `Options.classifier`, `reload`→`setLimits`) | | Output | `src/jobjson.zig` (`loadLevel` JSON field), `src/output.zig` (`<load_level>` XML) | | Persistence | `src/repository.zig` (`CreateOptions.load_level`, manifest.json `loadLevel`) | | Docs/tests | `README.md`, `AGENTS.md`, `test/e2e.sh`, unit tests | ## Implementation plan ### Phase 1 — Scheduler: strict single-job FIFO (`src/scheduler.zig`) - Delete `Options.limits`, `counts[3]`, `runningAt()`, `setLimits()`, `limitFor()`; `Active` loses `level`. - Capacity check: `active.count() >= 1 → AtCapacity`. Everything else (scheduler file lock, tick loop, `stop()`, `killAll`, `killJob`, retry-at skip, FIFO-by-`created_at`) stays. - Tests: replace the three limit tests with **never more than one running at a time** + **FIFO completion order** tests; keep retry/kill/single-scheduler tests. ### Phase 2 — Job model & persistence - `src/job.zig`: drop `load_level` from `Job` and `Manifest`. - `src/repository.zig`: drop `CreateOptions.load_level`; manifest writer drops `loadLevel`; reader tolerates old manifests (unknown fields already ignored). - `src/jobjson.zig`: drop `loadLevel` from `writeJob` and `RawJob` (old JSON still parses; JSON field order shifts — note in docs). - `src/output.zig`: drop `<load_level>` XML element + update the XML-shape test. ### Phase 3 — Config surface (`src/config.zig`, `src/defaults/`) - Delete `LoadLevels`; remove `load_levels` from `Config`, `validate()`, `fromDoc()`, `known_sections`, `checkSection`/`problems()`, and both env-section aliases (`load_levels`/`loadlevels`). Remove `max_concurrent_jobs` field + its validation entry. - **Deprecation detection (new)**: - `Problem` gains a `deprecated: bool` (or a separate warnings list); `problems()` special-cases section `load_levels` and key `service.max_concurrent_jobs` → warning: *"deprecated: only one job runs at a time; remove it from your config"* instead of "Unknown section/key". - `config.load()` gains an optional diagnostics-out (same `Diagnostic` pattern already used): when a loaded file contains either, it records a warning. Callers: daemon startup logs it once (`std.log.warn`); `config validate` **prints it but does not fail** (exit 1 stays reserved for real errors); `config show` prints a warning line above the effective config. - `applyEnvironment()` special-cases `ZAG_LOAD_LEVELS_*` / `ZAG_LOADLEVELS_*` / `ZAG_SERVICE_MAX_CONCURRENT_JOBS` → warning + ignore instead of silent no-match. - `src/defaults/zag.conf`: delete `[load_levels]` section + the deprecated `max_concurrent_jobs` comment. - Delete `src/defaults/{high,medium,low}.load`, their entries in `src/defaults.zig` (`files` = `zag.conf` only), and **delete `src/loadlevel.zig`, `src/loadclass.zig`** + their `src/root.zig` exports. ### Phase 4 — CLI & output - `src/cli_jobs.zig`: drop `--load-level/-l` (opts + usage + `run_job` IPC payload + `runOffline` classifier); remove LOAD column from `printStatusTable`. - `src/cli_admin.zig`: `configNode`/`cmdConfigShow` lose `[load_levels]` (plus the new deprecation warning line); `config install` installs only `zag.conf` (usage text updated); autocompletion drops the `-l|--load-level` case and the flag from `run` opts; service-start wiring (~line 129) no longer builds a `Classifier`. - `src/cli.zig`: help test now asserts `--load-level` is **absent** from `run --help`. ### Phase 5 — IPC/daemon (`src/service.zig`) - `Options`: delete `classifier`; `schedulerOptions`: delete `.limits`. - `hRunJob`: delete `loadLevel` parsing/validation (old clients sending the field are simply ignored — protocol stays backward-compatible). - `reload()`: delete `setLimits` call. Delete the "load level is auto-classified or overridden" test; drop `.load_levels` from the harness config. ### Phase 6 — Tests & e2e - Update all unit tests listed in phases 1–5 (`config` defaults/embedded/env/validate/problems; `repository` manifest round-trip; `jobjson` layout; `output` XML). - Add `config` tests: doc with `[load_levels]` → `problems()` returns 1 *deprecation*, `cmdConfigValidate` exits **0**; same for the `max_concurrent_jobs` key and `ZAG_LOAD_LEVELS_MAX_HIGH_JOBS` env. - `test/e2e.sh`: - `config show --defaults` no longer asserts `max_high_jobs = 2` (assert it is absent); - `install --show` asserts `zag.conf`, not `high.load`; - **new**: config with `[load_levels]` → `config validate` exits 0 and prints the deprecation note; - **new serial-execution check**: two `sleep` jobs via IPC → second stays `QUEUED` while first is `RUNNING`, both finish in FIFO order. ### Phase 7 — Docs - `README.md`: delete the "Load Levels" section, the `load_level` table row, and the `--load-level` override paragraph; fix "Migration from barn" (env example `ZAG_LOAD_LEVELS_MAX_HIGH_JOBS works`, the `.load`-lists bullet, the `config show` bullet) and add explicit deviation notes: **one job runs at a time**, **no load levels / `loadLevel` field**, deprecated sections accepted-but-ignored with a warning. - `AGENTS.md`: drop the `loadlevel.zig`/`loadclass.zig` layout rows, update the `defaults` row, note the intentional barn deviation. ### Phase 8 — Verify - `zig fmt --check`, `zig build test`, `zig build e2e`, release cross-compile (per CI). - Manual smoke: `config install --show`, `config show --defaults`, `config validate` on an old conf (exit 0 + deprecation note), daemon start with an old conf (one warning line), two sequential `zag run` calls serialize. ## Consequences for `web/` (out of scope — no changes made) - `ZagJob` DTO: `loadLevel ?? 'MEDIUM'` → synced jobs will always appear `MEDIUM` (harmless). - **Breaking**: if a user submits `load_level` in the web UI, `ZagClient::run` appends `--load-level=…` and the new zag exits 2 → that job fails to start. `ZagJob` model's `load_level` column stops being meaningful. - Future follow-up (separate repo/PR, not part of this issue): drop `ZagLoadLevel`, the `load_level` request param in `Run.php`, the `loadLevel` arg in `ZagClient::run`, and the DTO/model fields. ## Risks - Throughput change is intentional: up to 32 parallel downloads now serialize into one — pipeline wait times will grow. - Breaking for anything parsing zag's JSON/XML or using `--load-level` — only `web/` does, today. - Old on-disk jobs keep working (lenient manifest/JSON parsing); automatic cleanup removes them over time. - No cluster actions involved; pure code + docs in `zag/`, one PR.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: samson-media/zag#2