Skip to content

Commit 116ff61

Browse files
sourcehawkclaude
andcommitted
fix(skills/bounding-heavy-commands): print the headroom of each budget on its line of the check
The first line of the check printed the headroom of a small budget, while each starts answer used the headroom of its own budget, which is 0 for a budget of the whole queue. So a check could print headroom=1024M and starts=yes for a budget that the free memory holds only without that headroom. The headroom now stands on each budget line, and the first line no longer has one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f66a67f commit 116ff61

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

‎skills/bounding-heavy-commands/SKILL.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ bounded-run: row label=<name> cpus=<n> budget=<n>M peak=<n>M exact=<yes|no> exit
5959
A check prints its lines in a fixed form too:
6060

6161
```
62-
bounded-run: check slots=<n> slot=<n>M free-slots=<n> free=<n>M unused=<n>M headroom=<n>M line=<free|busy>
62+
bounded-run: check slots=<n> slot=<n>M free-slots=<n> free=<n>M unused=<n>M line=<free|busy>
6363
bounded-run: check held unit=<name> budget=<n>M used=<n>M age=<n>s dir=<directory> command=<command>
64-
bounded-run: check budget=<n>M slots=<n> starts=<yes|no>
64+
bounded-run: check budget=<n>M slots=<n> headroom=<n>M starts=<yes|no>
6565
```
6666

67-
The first line gives the slots of the queue and their size, the slots that are free now, the free memory, the unused budgets of the running commands, and the headroom. `line=busy` means that a command waits in the line. Each `held` line is one bounded command that runs now: its budget, the memory it uses, how long it has run, its working directory, and its command. The held lines need the hard cap, so without it there are none. Each `budget` line is one `--memory`, in the order given: the slots that it needs, and `starts=yes` when a command of that budget would start now. A `-` means that the check cannot read or count the value at that moment.
67+
The first line gives the slots of the queue and their size, the slots that are free now, the free memory, and the unused budgets of the running commands. `line=busy` means that a command waits in the line. Each `held` line is one bounded command that runs now: its budget, the memory it uses, how long it has run, its working directory, and its command. The held lines need the hard cap, so without it there are none. Each `budget` line is one `--memory`, in the order given: the slots that it needs, the headroom that the wait keeps free beside that budget, and `starts=yes` when a command of that budget would start now. A `-` means that the check cannot read or count the value at that moment.
6868

6969
The exit code of the wrapper is the command's exit code. Exit code 125, with a `bounded-run:` line that names a fault and with no line for the budget and the peak, means that the wrapper itself failed (see §When the wrapper cannot run).
7070

‎skills/bounding-heavy-commands/scripts/bounded_run.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
running bounded command where the hard cap is available, and one line for
2525
each --memory, in the order given:
2626
27-
bounded-run: check slots=N slot=MIBM free-slots=N|- free=MIBM|- unused=MIBM|- headroom=MIBM line=free|busy
28-
bounded-run: check held unit=NAME budget=MIBM|- used=MIBM|- age=Ns|- dir=PATH|- command=TEXT|-
29-
bounded-run: check budget=MIBM slots=N starts=yes|no
27+
bounded-run: check slots=N slot=<n>M free-slots=N|- free=<n>M|- unused=<n>M|- line=free|busy
28+
bounded-run: check held unit=NAME budget=<n>M|- used=<n>M|- age=Ns|- dir=PATH|- command=TEXT|-
29+
bounded-run: check budget=<n>M slots=N headroom=<n>M starts=yes|no
3030
3131
A '-' stands for a value that the check cannot read or count here. starts=yes
3232
means that a run of that budget would start now. It is not a reservation.
@@ -1321,21 +1321,21 @@ def read_outstanding() -> Optional[int]:
13211321
outstanding = read_outstanding()
13221322
else:
13231323
available, outstanding = settings.free_mib, None
1324-
headroom = headroom_mib(settings.total_mib, 0, most)
13251324

13261325
def mib(value: Optional[int]) -> str:
13271326
return "-" if value is None else "%dM" % value
13281327

1329-
log("check slots=%d slot=%dM free-slots=%s free=%s unused=%s headroom=%dM line=%s" % (
1328+
log("check slots=%d slot=%dM free-slots=%s free=%s unused=%s line=%s" % (
13301329
count, settings.slot_mib, "-" if free_slots is None else free_slots, mib(available), mib(outstanding),
1331-
headroom, "free" if line is not None else "busy"))
1330+
"free" if line is not None else "busy"))
13321331
for held in held_commands(scopes, skip) if scopes is not None else []:
13331332
log("check held " + held)
13341333
for budget in budgets:
13351334
needed = slots_needed(budget, settings.slot_mib, count)
1335+
headroom = headroom_mib(settings.total_mib, min(budget, most), most)
13361336
starts = (line is not None and free_slots is not None and free_slots >= needed
1337-
and memory_fits(min(budget, most), available, outstanding, headroom_mib(settings.total_mib, min(budget, most), most)))
1338-
log("check budget=%dM slots=%d starts=%s" % (budget, needed, "yes" if starts else "no"))
1337+
and memory_fits(min(budget, most), available, outstanding, headroom))
1338+
log("check budget=%dM slots=%d headroom=%dM starts=%s" % (budget, needed, headroom, "yes" if starts else "no"))
13391339
return 0
13401340

13411341

‎skills/bounding-heavy-commands/scripts/tests/test_bounded_run.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,17 +1918,17 @@ def check(self, budgets=(), available=16384, outstanding=None):
19181918

19191919
def test_reports_the_slots_the_memory_and_the_line(self):
19201920
self.assertEqual(self.check(), [
1921-
"check slots=4 slot=2048M free-slots=4 free=16384M unused=- headroom=1024M line=free",
1921+
"check slots=4 slot=2048M free-slots=4 free=16384M unused=- line=free",
19221922
])
19231923

19241924
def test_a_budget_of_the_whole_queue_starts_when_the_memory_of_the_queue_is_free(self):
1925-
self.assertEqual(self.check(["8G"], available=8192)[-1], "check budget=8192M slots=4 starts=yes")
1925+
self.assertEqual(self.check(["8G"], available=8192)[-1], "check budget=8192M slots=4 headroom=0M starts=yes")
19261926

19271927
def test_the_free_memory_for_the_tests_replaces_the_measured_one(self):
19281928
self.environ["BOUNDED_RUN_FREE_MIB"] = "4096"
19291929
lines = self.check(["2G"], available=0, outstanding=65536)
19301930
self.assertIn(" free=4096M unused=- ", lines[0])
1931-
self.assertEqual(lines[-1], "check budget=2048M slots=1 starts=yes")
1931+
self.assertEqual(lines[-1], "check budget=2048M slots=1 headroom=1024M starts=yes")
19321932

19331933
def test_counts_the_slots_that_running_commands_hold(self):
19341934
self.hold("slot-000.lock")
@@ -1949,37 +1949,37 @@ def test_a_waiter_in_the_line_makes_the_line_busy_and_no_budget_starts(self):
19491949
self.hold("line.lock")
19501950
lines = self.check(["2G"])
19511951
self.assertTrue(lines[0].endswith(" line=busy"), lines)
1952-
self.assertEqual(lines[1], "check budget=2048M slots=1 starts=no")
1952+
self.assertEqual(lines[1], "check budget=2048M slots=1 headroom=1024M starts=no")
19531953

19541954
def test_a_count_of_slots_that_another_command_takes_at_that_moment_is_not_given(self):
19551955
self.hold("reserve.lock")
19561956
lines = self.check(["2G"])
19571957
self.assertIn(" free-slots=- ", lines[0])
1958-
self.assertEqual(lines[1], "check budget=2048M slots=1 starts=no")
1958+
self.assertEqual(lines[1], "check budget=2048M slots=1 headroom=1024M starts=no")
19591959

19601960
def test_each_budget_gets_its_slots_and_its_answer_in_the_order_given(self):
19611961
self.hold("slot-000.lock")
19621962
self.hold("slot-001.lock")
19631963
lines = self.check(["2G", "4096M", "5G"])
19641964
self.assertEqual(lines[1:], [
1965-
"check budget=2048M slots=1 starts=yes",
1966-
"check budget=4096M slots=2 starts=yes",
1967-
"check budget=5120M slots=3 starts=no",
1965+
"check budget=2048M slots=1 headroom=1024M starts=yes",
1966+
"check budget=4096M slots=2 headroom=1024M starts=yes",
1967+
"check budget=5120M slots=3 headroom=1024M starts=no",
19681968
])
19691969

19701970
def test_a_budget_starts_only_when_the_free_memory_less_the_unused_budgets_and_the_headroom_holds_it(self):
19711971
lines = self.check(["2G", "4G"], available=6000, outstanding=900)
1972-
self.assertEqual(lines[0], "check slots=4 slot=2048M free-slots=4 free=6000M unused=900M headroom=1024M line=free")
1973-
self.assertEqual(lines[1:], ["check budget=2048M slots=1 starts=yes", "check budget=4096M slots=2 starts=no"])
1972+
self.assertEqual(lines[0], "check slots=4 slot=2048M free-slots=4 free=6000M unused=900M line=free")
1973+
self.assertEqual(lines[1:], ["check budget=2048M slots=1 headroom=1024M starts=yes", "check budget=4096M slots=2 headroom=1024M starts=no"])
19741974

19751975
def test_a_budget_starts_when_the_free_memory_cannot_be_read_as_the_wait_does(self):
19761976
lines = self.check(["2G"], available=None)
19771977
self.assertIn(" free=- ", lines[0])
1978-
self.assertEqual(lines[1], "check budget=2048M slots=1 starts=yes")
1978+
self.assertEqual(lines[1], "check budget=2048M slots=1 headroom=1024M starts=yes")
19791979

19801980
def test_a_budget_larger_than_the_queue_needs_every_slot_and_the_memory_of_the_queue(self):
19811981
lines = self.check(["64G"], available=9300)
1982-
self.assertEqual(lines[1], "check budget=65536M slots=4 starts=yes")
1982+
self.assertEqual(lines[1], "check budget=65536M slots=4 headroom=0M starts=yes")
19831983

19841984
def test_counts_the_unused_budgets_beside_the_scope_of_the_probe(self):
19851985
self.environ.pop("BOUNDED_RUN_NO_CAP")
@@ -2690,8 +2690,8 @@ def test_prints_the_check_lines_on_the_error_stream_and_exits_0(self):
26902690
self.wait_for_event("start", "holder")
26912691
code, output, errors = self.check(["--memory", "2G", "--memory", "4G"])
26922692
self.assertEqual((code, output), (0, ""), errors)
2693-
self.assertRegex(errors, r"^bounded-run: check slots=2 slot=2048M free-slots=1 free=(\d+M|-) unused=- headroom=1024M line=free\n")
2694-
self.assertRegex(errors, r"\nbounded-run: check budget=2048M slots=1 starts=(yes|no)\nbounded-run: check budget=4096M slots=2 starts=no\n$")
2693+
self.assertRegex(errors, r"^bounded-run: check slots=2 slot=2048M free-slots=1 free=(\d+M|-) unused=- line=free\n")
2694+
self.assertRegex(errors, r"\nbounded-run: check budget=2048M slots=1 headroom=1024M starts=(yes|no)\nbounded-run: check budget=4096M slots=2 headroom=0M starts=no\n$")
26952695
holder.kill()
26962696

26972697
def test_a_command_starts_at_once_after_the_check(self):

0 commit comments

Comments
 (0)