Skip to content

desk-install: per-job memory and CPU limits from machine.json - #1496

Merged
scuttletoby merged 6 commits into
mainfrom
fleet-desk-job-limits
Nov 30, 2026
Merged

scuttletoby merged 6 commits into
mainfrom
fleet-desk-job-limits

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

Part of #929

What

A desk machine (fork-kit/desk, the Windows/WSL CI runner) can now set each job's limits in machine.json:
desk.jobMemoryMaxMb, desk.jobMemoryHighMb and desk.jobCpuQuota. desk-install writes them to launch.conf as the
launcher's existing JOB_MEMORY_MAX_MB, JOB_MEMORY_HIGH_MB and JOB_CPU_QUOTA.

Why

Before, a desk could not set them, so every job got MemoryMax = (MemTotal - reserveMb) / slots and saw every CPU. The
rented-host trial measured job anon peaks up to 5.8 GB and showed that a job seeing every CPU starts that many workers,
so a 4-slot desk failed the biggest jobs. A server host could already set these keys; a desk could not.

Checks

  • desk-install refuses a bad value (max under 1024, high 0, quota over 99999, a string) and high above max, and names
    the key. A refused file changes nothing.
  • New test test_job_limits_reach_the_settings failed before the fix and passes after. All 59 tests in
    fork-kit/desk/tests/install.test.py pass.

State question

  • Runs again: launch.conf is written again from machine.json, so the same file gives the same result.
  • Stops half-way: the existing atomic write (.new then rename) is unchanged.
  • Old or empty state: an old machine.json without the keys gives the same launch.conf as before. Removing the
    keys removes the lines, and the test checks this.

General vs project

This is general: it works for any desk machine. The values (for example 7168/6656/400) live in each machine's own
machine.json, which is not in this repo.

🤖 Generated with Claude Code

A desk machine could not set the launcher's JOB_MEMORY_MAX_MB, JOB_MEMORY_HIGH_MB or
JOB_CPU_QUOTA, so every job got (MemTotal - reserveMb) / slots and all CPUs. The rented-host
trial measured anon peaks up to 5.8 GB, so 4 slots on a 32 GB desk fail the biggest jobs, and a
job that sees every CPU runs that many workers. desk.jobMemoryMaxMb, desk.jobMemoryHighMb and
desk.jobCpuQuota now reach launch.conf; bad values and high above max are refused.

Part of #929

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Fix

Failed: a desk machine could not set per-job MemoryMax/MemoryHigh/CPUQuota, so 4 slots on a desk gave each job about (MemTotal - reserve)/4 and every CPU. The trial's biggest jobs (anon peak up to 5.8 GB) failed under such caps. Why: desk-install had no machine.json keys for the launcher's existing JOB_MEMORY_MAX_MB / JOB_MEMORY_HIGH_MB / JOB_CPU_QUOTA. Now it has them: they are checked, and high above max is refused. The failing-first test now passes.

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Opus 5.5 (high) · read at: 721d7dd

blocker: none
major: desk-install accepts a jobMemoryMaxMb with slots x jobMemoryMaxMb + reserveMb far above the machine's MemTotal, and gives no refusal or warning. That silently drops the guarantee the README gives for reserveMb ("memory the launcher keeps free for the owner"). Admission (fits) only checks each job's memory_mb when the job starts, so running jobs can grow past the reserve. Reproduced in the install test harness: slots 4, reserveMb 2048, jobMemoryMaxMb 900000 gives exit 0, writes JOB_MEMORY_MAX_MB=900000 and prints nothing. Fix: read MemTotal the way job_limits does. Refuse a max above MemTotal minus reserveMb. Warn, or refuse unless an explicit overcommit flag is set, when slots x max + reserveMb > MemTotal. Add a test for each.
minor: jobMemoryHighMb without jobMemoryMaxMb is checked against nothing. The launcher then compares it with its own default max, (MemTotal - RESERVE_MB) / slots, and refuses every job start (JOB_MEMORY_HIGH_MB (...) is over the job's MemoryMax). Meanwhile install says "installed" and check passes. Reproduced: jobMemoryHighMb 900000 alone gives exit 0. The MemTotal read from the major above can check this case too.
minor: the README could say that a value set to protect the slot count (high <= max, max x slots + reserve <= MemTotal) is the operator's job until the check above exists.

Checked and fine:

  • Units and ranges match the launcher's parser. jobMemoryMaxMb 1024..1000000 is at least JOB_MEMORY_MIN and fits MB_SETTING. jobCpuQuota 1..99999 matches ^[1-9][0-9]{0,4}$, and the launcher adds the % itself (CPUQuota=${JOB_CPU_QUOTA:+$JOB_CPU_QUOTA%}), so 400 = 4 CPUs per job, as the README says. The key names are in the launcher's setting= allow-list.
  • Refusals name the key (mf.fields messages, plus the high > max check), and they happen in machine_section() before done('check'), so nothing is written. The test confirms launch.conf is unchanged.
  • Keys absent: the ''.join(...) adds nothing, so launch.conf is byte-for-byte what it was before.

State question:

  • Runs again: launch.conf is rebuilt from machine.json. Unchanged text is not rewritten. Changed text sets restartPending and restarts the agent, the same as any existing settings change.
  • Stops half-way: the existing atomic write_file (temp file, fsync, os.replace) means launch.conf is old or new, never half-written. A stop after the write but before the restart is covered by restartPending.
  • Old machine.json without the keys: same launch.conf as today. Taking the keys out removes the lines (tested).
  • Old launch.conf from an earlier kit: it is rewritten whole. The launcher comes from the same release staged by this install, and its parser already knows the three keys, so a new launch.conf never meets a launcher that does not know them.
  • Empty/odd state the PR does not cover: see the major. The install cannot tell a value that will never fit this machine.

🤖 Generated with Claude Code

Fix round r1 of the code lens: desk-install reads MemTotal as the launcher's
job_limits does and refuses, by key name and before writing anything, a
jobMemoryMaxMb above MemTotal - reserveMb, slots x max + reserveMb above
MemTotal, and a jobMemoryHighMb above the max each job gets (the given max,
or the launcher's default (MemTotal - reserve) / slots). Part of #929.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

Copy link
Copy Markdown
Owner Author

Fix round r1

For the code lens (#1496 (comment)), in one commit:

  • desk-install reads MemTotal from /proc/meminfo the way the launcher's job_limits does (kB / 1024). It reads it only when a job memory key is set, and refuses when there is none.
  • It refuses by key name, writing nothing:
    • jobMemoryMaxMb above MemTotal - reserve;
    • slots x jobMemoryMaxMb + reserve above MemTotal;
    • jobMemoryHighMb above the max each job gets: the given max, or the launcher's default (MemTotal - reserve) / slots.
  • The reserve is reserveMb, or the launcher's 2048 when it is unset.
  • Tests: five new rows in the existing table test (test_job_limits_reach_the_settings, now run as one subTest per row). Each asserts its own message, and each was red on 721d7dd (exit 0, nothing refused). The good row is now 6144/5632, which fits a 15711 MB machine with 2 slots. The touched tests pass.
  • README: one paragraph on what install checks.
  • State question: unchanged. The check is read-only and runs before anything is written.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Opus 5.5 (high) · read at: 709793d

blocker: none
major: none
minor: mem_total_mb catches OSError and ValueError but not IndexError. So a MemTotal: line with no number crashes with a traceback instead of the clear "need MemTotal" refusal. Reproduced: /proc/meminfo = MemTotal:\n with jobMemoryMaxMb 2048 raises IndexError: list index out of range. Nothing is written, because machine_section() runs before any write. A real kernel never prints this line, so it is cosmetic. Fix: add IndexError to the suppress.
minor (optional): the check top > total - reserve is already covered by slots * top + reserve > total, because slots is at least 1. It only changes which message appears first.

Round 1, fixed: no MemTotal check. Install now refuses, by key name, a max above MemTotal minus the reserve, and slots x max + reserve above MemTotal.
Round 1, fixed: a high with no max is now checked against the launcher's own (MemTotal - reserve) / slots (test row 6900 against 6831).
Round 1, fixed: the README now states the rule.

Checked and fine (each one run against job_memory_fits with a fake /proc/meminfo):

  • The sums match the launcher's job_limits: kB // 1024; the default reserve is 2048, like the launcher's RESERVE_MB; RUNNER_USERS holds one user per slot, so the launcher's divisor is slots. The fits admission rule is unchanged.
  • WSL desk, MemTotal 24000 MB, reserve 6144, max 7168 / high 6656: 2 slots are accepted (20480 <= 24000). 3 slots are refused (27648) and so are 4 (34816), with the true sums in the message. This matches the slot formula floor((MemTotal - 6144) / 7168).
  • 15711 MB Linux VM host, 1 slot, 7168: accepted with reserve 2048. Refused with reserve 9216 (7168 > 15711 - 9216). Caveat: a server-kit host whose RESERVE_MB is a start-time margin that already counts the job's growth (cap + 2048) does not fit desk-install's meaning, where the reserve is kept free with every job at its cap. Such a host is not set up through desk-install, so this PR is not affected. Do not copy that reserve into a desk machine.json.

State question:

  • Runs again: launch.conf is rebuilt from machine.json and MemTotal every time, so the same input gives the same output. Removing the keys removes the lines (tested).
  • Stops half-way: the check runs inside machine_section(), before the walls probe and before any write. A refusal writes nothing (tested: no JOB_ line after each refused row). The atomic .new + rename is unchanged.
  • MemTotal read fails or is odd: a missing file, empty file, non-numeric value or non-ASCII bytes all give a clear refusal. 0 or negative is refused on the max rule. A missing number crashes without writing anything (minor above). The read happens only when a job memory key is set.
  • Old or empty config: without the new keys the function returns before reading /proc/meminfo, so launch.conf is exactly as before, even on a host with no MemTotal.
  • Later shrink: if the machine's memory shrinks after install (for example a smaller WSL memory limit), desk-install check runs machine_section() again and shows a machine-file FAIL naming the key. The written launch.conf stays as it was until the next install.

Verdict: SAFE.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

r2 minor (orchestrator)

Round-2 code lens SAFE. I fixed its minor in f78a4d7: mem_total_mb also suppresses IndexError, so a MemTotal: line with no number gives the clear "need MemTotal" refusal instead of a traceback. install.test.py passes locally (59 tests). The optional duplicate-check minor is left as is (it only changes which message appears first).

scuttletoby and others added 3 commits November 30, 2026 04:58
Refuse when reserveMb is under slots x jobMemoryMaxMb (a job may grow to
its max, the reserve covers that), or when reserveMb + the biggest job
(4096) is above MemTotal (no job could start). This replaces the check
slots x max + reserve > MemTotal, which refused a valid 2-slot desk at
24 GB with reserve 16384. Table test: a passing 24 GB row, new refusals.

Part of #929

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green (PRs) label Nov 30, 2026
@scuttletoby
scuttletoby merged commit db6b15f into main Nov 30, 2026
25 checks passed
@scuttletoby
scuttletoby deleted the fleet-desk-job-limits branch November 30, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green (PRs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant