Skip to content

Commit ebcc7d9

Browse files
sourcehawkclaude
andcommitted
fix(skills/bounding-heavy-commands): read the queue state of the check after the cap probe
The check counted the free slots and read the line before it probed the cap, and a probe can take up to 15 seconds per try. The slots and the line could then be half a minute old when the check answered. The probe now comes first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6a01bb4 commit ebcc7d9

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,13 +1338,14 @@ def check(
13381338
uid = os.getuid()
13391339
directory = lock_directory(environ, uid)
13401340
ensure_lock_directory(directory, uid)
1341+
unit = "%s-%d-%06x" % (PREFIX, os.getpid(), random.randrange(16 ** 6))
1342+
# The probe can take seconds, so the state of the queue is read after it.
1343+
choice = None if settings.no_cap else choose_cap_prefix(settings.slot_mib, None, unit, probe_cap)
13411344
# A waiter tries for slots only while it holds the turn lock, so a count under that lock never makes a free slot look held to it.
13421345
free_slots = _free_slots(directory, count, wait=False)
13431346
line = _try_lock(os.path.join(directory, "line.lock"))
13441347
if line is not None:
13451348
os.close(line)
1346-
unit = "%s-%d-%06x" % (PREFIX, os.getpid(), random.randrange(16 ** 6))
1347-
choice = None if settings.no_cap else choose_cap_prefix(settings.slot_mib, None, unit, probe_cap)
13481349
scopes = scope_parent_directory(choice[1]) if choice is not None else None
13491350
skip = [name for name in (own_scope_name(),) if name is not None]
13501351
if read_outstanding is None:

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,25 @@ def held(parent, skip):
21202120
bounded_run.check(options.budgets, self.environ, read_available=lambda: 9000)
21212121
self.assertEqual(skips, [[]])
21222122

2123+
def test_the_slots_and_the_line_are_read_after_the_cap_probe(self):
2124+
self.environ.pop("BOUNDED_RUN_NO_CAP")
2125+
events = []
2126+
real_free_slots = bounded_run._free_slots
2127+
2128+
def probe(prefix):
2129+
events.append("probe")
2130+
return None
2131+
2132+
def free_slots(*arguments, **keywords):
2133+
events.append("slots")
2134+
return real_free_slots(*arguments, **keywords)
2135+
2136+
options = bounded_run.parse_arguments(["--check"])
2137+
with mock.patch.object(bounded_run, "probe_cap", probe), mock.patch.object(bounded_run, "_free_slots", free_slots):
2138+
bounded_run.check(options.budgets, self.environ, read_available=lambda: 9000)
2139+
self.assertEqual(events[-1], "slots")
2140+
self.assertIn("probe", events)
2141+
21232142
def test_no_held_line_without_a_cap(self):
21242143
self.hold("slot-000.lock")
21252144
self.assertFalse(any(line.startswith("check held") for line in self.check(["2G"])))

0 commit comments

Comments
 (0)