Repository navigation
The queue does not count processors, so bounded commands together can oversubscribe the CPU #72
Description
Problem
The queue of bounding-heavy-commands counts memory and not processors. The commands that it runs together can ask for more processors than the machine has. A command with --cpus gets a CPU quota of that many processors, but the queue does not add the quotas of the running commands, so their sum can pass the number of processors. A command without --cpus gets no CPU quota at all.
This cannot freeze a machine, which is why the queue counts memory first. It makes every command and every agent session slow at the same time. On a 16-processor laptop with more than a dozen agent sessions, the load average was 26 to 36, and tasks waited for a processor 37% of the time (the some line of /proc/pressure/cpu, averaged over 5 minutes). Memory pressure was near zero. One bounded envtest suite ran three API servers at 70 to 85% of a processor each, beside other bounded builds and a bounded command with no quota.
Approach
- A command without
--cpusgets a default quota, for example half the machine's processors, in the same way that a command without--memorygets a default budget. - The line of A bounded command that needs many slots can wait forever while smaller commands keep starting #54 admits a command only when its
--cpus, added to the--cpusof the running bounded commands, is at most the number of processors. Where the hard cap is available, the running commands' quotas can be read from eachbounded-run-*scope'scpu.max, as The queue can give out more memory than the machine has, and the machine froze #55 readsmemory.max, with no state file. --check(Let an agent see the queue before it chooses which measured row of a command to run #57) reports the processors in use and whether a row's--cpusfits now, so that a smaller row can be chosen when processors are the limit.
Whether the second item is worth it is part of the work. Oversubscribed CPU is shared fairly by the kernel, so a queue on processors changes when each command finishes more than how much work the machine does. Measure the wall time of a batch of commands with and without it before merging.
Acceptance criteria
- A command without
--cpusruns under a default CPU quota where the hard cap is available. - If the processor count is added: a test with fake
cpu.maxfiles shows that a command waits while the running quotas and its own pass the number of processors, and starts when they do not. - The skill's text about
--cpusand the wait matches. - The tests pass on Linux and macOS.
Context
Observed on 2026-09-30 while the stack #58 to #71 was under review. Related: #55 (memory counting), #57 (--check).
Activity
feat(skills/bounding-heavy-commands): give a run without --cpus a quo…
feat(skills/bounding-heavy-commands): give commands a default CPU quo…
fix(skills/bounding-heavy-commands): stop bounded commands from takin…
sourcehawk commentedon Oct 6, 2026
Result: the queue does not count processors
Two items of this issue are done:
--cpusa quota of half the processors.--checkshowcpus-used,cpus-headroom, andcpus-free, and the skill uses them to choose a row.The second item, a wait for processors, does not ship. I measured it as the issue asks, and it costs more than it gives.
How I measured
A script started each batch of bounded commands at the same moment, through the real wrapper, on a 16-processor machine. In one mode, each command entered the wrapper at once. In the other mode, the script let a command enter only when its
--cpus, added to the--cpusof the running commands, was 16 or less, or when no command ran. That is the rule of the second item. A probe started/bin/trueevery 0.5 s and recorded the time, as a stand-in for a program outside the queue. Other agent sessions ran on the machine at the same time. Each batch ran two times, in the opposite order the second time.some)--cpus 8, each uses its quota--cpus 8; the suite uses 1 processorA second run of the mixed batch with the wait took 386.9 s. A spike of load from another session came during that run, so the table does not use it.
What the numbers show
When each command uses its whole quota, the wait does not change the total time. The commands end at different times, not all at the end, so the mean end is 10 to 24% earlier, and the probe waits about half as long.
When a quota is larger than the use, the wait keeps processors idle. A run without
--cpusgets half the processors, also when its tool runs one process. The unit test suite in the table is such a command, and the third run of it waited for processors that the second run did not use. The total time was about 23% longer, and the mean end was about 50% longer. Agents that each run such a suite at the same time would take turns for no reason.The quota of a command tells the limit, not the use. So a wait that adds quotas helps one kind of command and harms the other.
The skill text about
--cpusand the wait still matches: the wrapper waits for its turn and for memory, not for processors, andcpus-freeguides only the choice of a row.