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

Open
daniel wants to merge 7 commits from feature/#2-flatten-priority-load-levels into develop
pull from: feature/#2-flatten-priority-load-levels
Owner

Part of #2 — phase 1 of the plan in that issue.

What this does

Replaces the per-load-level concurrency caps (2 high / 8 medium / 32 low) with a strict
single-job FIFO: the scheduler starts the next eligible queued job (oldest first,
respecting retry_at) only when nothing is running.

  • src/scheduler.zig: Options.limits, Active.level, counts[3], runningAt(),
    setLimits() and limitFor() removed; capacity check is now active.count() >= 1;
    tick() starts at most one job per pass.
  • src/service.zig: scheduler no longer receives cfg.load_levels; reload() no longer
    calls setLimits().
  • Tests: the three load-level limit tests are replaced by
    only one job runs at a time and jobs finish in FIFO order (asserts max concurrent = 1
    and that each job starts only after the previous one finished).

Plus a drive-by fix (separate commit): the liveness/search-path tests used
std.os.linux.getpid() (a raw Linux syscall — syscall 39 is sysctl on macOS) and a
hardcoded XDG path, so zig build test had three pre-existing failures on macOS. They now
use the portable proc.currentPid() / OS-aware expected paths and the suite is green on
both macOS and Linux.

Not in this PR

The rest of the load-level surface — LoadLevels config, --load-level, loadLevel
JSON/XML fields, .load files, deprecation warnings — is removed in follow-up PRs per the
plan in #2. The config still parses and is simply not applied to the scheduler.

Verified locally (macOS)

  • zig fmt --check ✅
  • zig build test — 150/150 ✅ (was 147/150 with the pre-existing env failures)
  • zig build e2e — all checks passed (incl. run over IPC is queued, service reload) ✅

CI should confirm the same on Linux (fmt, unit tests, e2e, cross-compile).

Part of #2 — phase 1 of the plan in that issue. ## What this does Replaces the per-load-level concurrency caps (2 high / 8 medium / 32 low) with a strict single-job FIFO: the scheduler starts the next eligible queued job (oldest first, respecting `retry_at`) only when nothing is running. - `src/scheduler.zig`: `Options.limits`, `Active.level`, `counts[3]`, `runningAt()`, `setLimits()` and `limitFor()` removed; capacity check is now `active.count() >= 1`; `tick()` starts at most one job per pass. - `src/service.zig`: scheduler no longer receives `cfg.load_levels`; `reload()` no longer calls `setLimits()`. - Tests: the three load-level limit tests are replaced by `only one job runs at a time and jobs finish in FIFO order` (asserts max concurrent = 1 and that each job starts only after the previous one finished). Plus a drive-by fix (separate commit): the liveness/search-path tests used `std.os.linux.getpid()` (a raw Linux syscall — syscall 39 is `sysctl` on macOS) and a hardcoded XDG path, so `zig build test` had three pre-existing failures on macOS. They now use the portable `proc.currentPid()` / OS-aware expected paths and the suite is green on both macOS and Linux. ## Not in this PR The rest of the load-level surface — `LoadLevels` config, `--load-level`, `loadLevel` JSON/XML fields, `.load` files, deprecation warnings — is removed in follow-up PRs per the plan in #2. The config still parses and is simply not applied to the scheduler. ## Verified locally (macOS) - `zig fmt --check` ✅ - `zig build test` — 150/150 ✅ (was 147/150 with the pre-existing env failures) - `zig build e2e` — all checks passed (incl. `run over IPC is queued`, `service reload`) ✅ CI should confirm the same on Linux (fmt, unit tests, e2e, cross-compile).
daniel added 2 commits 2026-11-11 20:50:04 +00:00
Replace the per-load-level concurrency caps (2 high / 8 medium / 32
low) with a strict single-job FIFO: the scheduler starts the next
eligible queued job only when nothing is running.

- Scheduler.Options loses 'limits'; Active loses 'level'; counts[3],
  runningAt(), setLimits() and limitFor() are removed; the capacity
  check is now active.count() >= 1.
- Service no longer passes cfg.load_levels to the scheduler and
  reload() no longer calls setLimits().
- Tests: the three load-level limit tests are replaced by a single
  'only one job runs at a time and jobs finish in FIFO order' test.

Part of issue #2. The LoadLevels config type, --load-level flag and
the loadLevel JSON/XML fields remain and are removed in follow-ups.
test: make liveness and search-path tests portable to macOS
CI / test (pull_request) Successful in 3m17s
8f3f61c86a
std.os.linux.getpid() is a raw Linux syscall (number 39), which maps to
a different syscall on macOS, so it returned a bogus pid (or killed the
test process with SIGSYS) when the suite ran on a Mac. Use the portable
proc.currentPid() in the proc and recovery tests, and make the config
search-path test expect the macOS user config dir on macOS.

This clears the three pre-existing environment failures so 'zig build
test' is green on both macOS and Linux.
daniel changed title from Phase 1 of #2: run only one job at a time, drop per-load-level limits to #2 Flatten priority (load levels): run only one job at a time 2026-11-11 21:10:32 +00:00
claude-dev added 1 commit 2026-11-12 10:07:40 +00:00
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.
claude-dev added 1 commit 2026-11-12 10:40:42 +00:00
daemon: flush deprecation warnings into the log at startup
CI / test (pull_request) Successful in 3m18s
3a4c4fa326
The re-exec'd daemon inherits the buffered stderr writer over
logs/zag.log from main.zig, so the deprecation warnings printed by
Context.loadConfigOnce stayed in the buffer until the process
exited and 'zag service logs' showed nothing right after starting
with an old config. Flush stderr right after printing the
warnings so they reach the log at startup, as the issue requires.

e2e now starts the daemon with a config that still carries the
deprecated load-level settings and asserts the warnings are in the
log while the daemon is running; the settings themselves are
ignored, so the effective config is unchanged for the rest of
the suite.
claude-dev added 1 commit 2026-11-12 10:53:04 +00:00
cli: assert --load-level stays out of run --help
CI / test (pull_request) Successful in 3m22s
5ee6b6021c
Last item of issue #2 phase 4 (CLI & output): the per-command help
test now checks that the removed flag does not resurface in the
help text.
claude-dev added 1 commit 2026-11-12 11:47:28 +00:00
e2e: assert config show --defaults has no load levels
CI / test (pull_request) Successful in 3m22s
18c77a6e96
Completes the last phase-6 item of issue #2: the defaults check now
explicitly asserts max_high_jobs is absent from the output, not just
that the old assertion is gone.
daniel left a comment
Author
Owner

Reviewed the full diff (all 6 commits) and ran the checks locally at branch head on macOS:

  • zig fmt --check OK
  • zig build test OK
  • zig build e2e OK (incl. the new serial: FIFO checks and the deprecated-config daemon checks)
  • cross-compile of all four release targets (x86_64/aarch64 linux-musl + macos) OK

Main issue: the PR description is stale. The "Not in this PR" section says the LoadLevels config, --load-level, the loadLevel JSON/XML fields, the .load files and the deprecation warnings are "removed in follow-up PRs per the plan in #2" and that "the config still parses and is simply not applied to the scheduler". In fact this PR removes all of those (commit 4abc94f "load levels: remove load levels from model, config, CLI, IPC, tests, docs", plus 3a4c4fa / 5ee6b60 / 18c77a6 for the deprecation-warning surface). The description reads as if it was written when the PR only contained the scheduler + macOS test-portability commits. Please update it (including the "150/150" test count) so it matches what actually gets merged.

The code itself looks good:

  • Back-compat is handled well in both directions: loadLevel in a run_job payload is ignored rather than rejected, old manifest.json files with a loadLevel field still parse (ignore_unknown_fields), and the new CLI tolerates loadLevel from an old daemon's job JSON.
  • Deprecated config/env handling is consistent: [load_levels] / max_concurrent_jobs / ZAG_LOAD_LEVELS_* / ZAG_SERVICE_MAX_CONCURRENT_JOBS all warn and are ignored; config validate correctly exits 0 for warnings-only files.
  • The scheduler change is minimal and the new unit test (max concurrent = 1 + strict start-after-finish) plus the e2e serial: checks cover it well.

Minor suggestions, nothing blocking:

  1. zag config install no longer writes the .load files, but it also doesn't remove the stale high/medium/low.load files from existing installs. They're inert now so it's harmless, but it would be a nice touch for install to clean them up (or at least mention it in the release notes).
  2. See the inline comment on config validate's human output.

Fix the description and this is good to merge.

Reviewed the full diff (all 6 commits) and ran the checks locally at branch head on macOS: - `zig fmt --check` OK - `zig build test` OK - `zig build e2e` OK (incl. the new `serial:` FIFO checks and the deprecated-config daemon checks) - cross-compile of all four release targets (x86_64/aarch64 linux-musl + macos) OK **Main issue: the PR description is stale.** The "Not in this PR" section says the `LoadLevels` config, `--load-level`, the `loadLevel` JSON/XML fields, the `.load` files and the deprecation warnings are "removed in follow-up PRs per the plan in #2" and that "the config still parses and is simply not applied to the scheduler". In fact this PR removes all of those (commit 4abc94f "load levels: remove load levels from model, config, CLI, IPC, tests, docs", plus 3a4c4fa / 5ee6b60 / 18c77a6 for the deprecation-warning surface). The description reads as if it was written when the PR only contained the scheduler + macOS test-portability commits. Please update it (including the "150/150" test count) so it matches what actually gets merged. The code itself looks good: - Back-compat is handled well in both directions: `loadLevel` in a `run_job` payload is ignored rather than rejected, old `manifest.json` files with a `loadLevel` field still parse (`ignore_unknown_fields`), and the new CLI tolerates `loadLevel` from an old daemon's job JSON. - Deprecated config/env handling is consistent: `[load_levels]` / `max_concurrent_jobs` / `ZAG_LOAD_LEVELS_*` / `ZAG_SERVICE_MAX_CONCURRENT_JOBS` all warn and are ignored; `config validate` correctly exits 0 for warnings-only files. - The scheduler change is minimal and the new unit test (max concurrent = 1 + strict start-after-finish) plus the e2e `serial:` checks cover it well. Minor suggestions, nothing blocking: 1. `zag config install` no longer writes the `.load` files, but it also doesn't remove the stale `high/medium/low.load` files from existing installs. They're inert now so it's harmless, but it would be a nice touch for `install` to clean them up (or at least mention it in the release notes). 2. See the inline comment on `config validate`'s human output. Fix the description and this is good to merge.
claude-dev added 1 commit 2026-11-12 14:38:34 +00:00
- reloadConfig: use a local ArrayList per reload instead of the shared
  ctx.config_deprecations — the previous approach could reallocate the
  backing array into the short-lived reload arena, causing use-after-free
  on successive reloads when warning counts grew between reloads
- fromDoc: replace unsafe @ptrFromInt/@offsetOf arithmetic with &@field,
  which is idiomatic Zig and carries no extra risk; remove the incorrect
  comment claiming @field materialises a copy
- problems(): fix the out.items.len == 0 range-check guard to count only
  non-warning (error) items so a deprecated setting no longer suppresses
  the range check for the rest of the document; add regression test
- deprecations now typed as []Problem throughout (env-var warnings carry
  key/message/is_warning like file-level ones) so callers have full context
- e2e: assert b1 never leaves QUEUED while a1 is running (true FIFO check)
- sections table shared by fromDoc and checkDoc eliminates drift risk
  between the two section lists; problemNodes refactored to ArrayList
  single-pass; isDeprecatedKey inlined; isDeprecatedEnvName comment added

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
All checks were successful
CI / test (pull_request) Successful in 3m20s
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/#2-flatten-priority-load-levels:feature/#2-flatten-priority-load-levels
git checkout feature/#2-flatten-priority-load-levels
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: samson-media/zag#3