Skip to content

Commit 2cc67eb

Browse files
sourcehawkclaude
andcommitted
fix(skills/bounding-heavy-commands): keep the first failed exit code when an interrupt ends the wait of a later row
A signal while a row runs comes back as that row's exit code, but a signal while a row waits in the queue raises KeyboardInterrupt. That went past the rows loop to main(), which returned 130 and lost the failure of an earlier row. The loop now catches it and returns the first failed code, or 130. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5157850 commit 2cc67eb

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,12 @@ def bounded(options: Options, environ: Mapping[str, str]) -> int:
10191019
row = Options()
10201020
row.memory, row.cpus, row.exclusive, row.measure, row.label, row.command = (
10211021
memory, cpus, options.exclusive, True, options.label, options.command)
1022-
code, suggested = bounded_once(row, environ)
1022+
try:
1023+
code, suggested = bounded_once(row, environ)
1024+
except KeyboardInterrupt:
1025+
# A signal while a row runs comes back as its exit code. A signal while it waits in the queue raises.
1026+
log("interrupted while waiting; the rows from --cpus %d are not measured" % cpus)
1027+
return result or 130
10231028
if code in STOP_CODES:
10241029
log("stopped by a signal; the rows after --cpus %d are not measured" % cpus)
10251030
return result or code

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,21 @@ def test_a_stop_signal_after_a_failed_row_keeps_the_first_exit_code(self):
18221822
self.assertEqual(code, 1)
18231823
self.assertEqual(len(self.runs), 2)
18241824

1825+
def test_an_interrupt_while_a_later_row_waits_keeps_the_first_exit_code(self):
1826+
real_once = bounded_run.bounded_once
1827+
calls = []
1828+
1829+
def once(options, environ):
1830+
calls.append(options.cpus)
1831+
if len(calls) == 2:
1832+
raise KeyboardInterrupt
1833+
return real_once(options, environ)
1834+
1835+
with mock.patch.object(bounded_run, "bounded_once", once):
1836+
code = self.run_bounded(["--measure-rows", "8,4,2"], [(1, 1000)])
1837+
self.assertEqual(code, 1)
1838+
self.assertEqual(calls, [8, 4])
1839+
18251840

18261841
class WrapperProcessCase(unittest.TestCase):
18271842
"""Runs the script as a process, with two slots of 2 GiB and no hard cap."""

0 commit comments

Comments
 (0)