Skip to content

Commit 5430ca6

Browse files
sourcehawkclaude
andcommitted
fix(skills/bounding-heavy-commands): count the larger of two unused-budget reads around the free memory in the check
The wait now reads the unused budgets before and after the free memory and counts the larger value. The check does the same, so its answer does not start a command that the wait would hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b734057 commit 5430ca6

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,8 +1347,10 @@ def read_outstanding() -> Optional[int]:
13471347
return None if scopes is None else unused_budget_mib(scopes, skip)
13481348

13491349
if settings.free_mib is None:
1350-
outstanding = read_outstanding()
1350+
before = read_outstanding()
13511351
available = read_available()
1352+
after = read_outstanding()
1353+
outstanding = None if before is None or after is None else max(before, after)
13521354
else:
13531355
available, outstanding = settings.free_mib, None
13541356

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,12 @@ def test_a_budget_larger_than_the_queue_needs_every_slot_and_the_memory_of_the_q
20572057
lines = self.check(["64G"], available=9300)
20582058
self.assertEqual(lines[1], "check budget=65536M slots=4 headroom=0M starts=yes")
20592059

2060+
def test_counts_the_larger_of_the_unused_budgets_read_before_and_after_the_free_memory(self):
2061+
unused = [100, 900]
2062+
options = bounded_run.parse_arguments(["--check"])
2063+
bounded_run.check(options.budgets, self.environ, read_available=lambda: 6000, read_outstanding=lambda: unused.pop(0))
2064+
self.assertIn(" unused=900M ", self.lines[0])
2065+
20602066
def test_counts_the_unused_budgets_beside_the_scope_of_the_probe(self):
20612067
self.environ.pop("BOUNDED_RUN_NO_CAP")
20622068
output = "0::/user.slice/app.slice/bounded-run-1-000000-probe.scope\n"
@@ -2071,7 +2077,7 @@ def unused(parent, skip):
20712077
mock.patch.object(bounded_run, "unused_budget_mib", unused), \
20722078
mock.patch.object(bounded_run, "held_commands", return_value=[]):
20732079
self.assertEqual(bounded_run.check(options.budgets, self.environ, read_available=lambda: 9000), 0)
2074-
self.assertEqual(calls, ["/sys/fs/cgroup/user.slice/app.slice"])
2080+
self.assertEqual(set(calls), {"/sys/fs/cgroup/user.slice/app.slice"})
20752081
self.assertIn(" unused=700M ", self.lines[0])
20762082

20772083
def test_names_each_held_command_after_the_state_line(self):

0 commit comments

Comments
 (0)