Repository navigation
fix(skills/bounding-heavy-commands): stop smaller commands from starving a command that needs many slots - #61
Conversation
07c1dbc to
122f84f
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Non-FIFO locking still permits starvation, and the documentation overstates the ordering guarantee.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds line-based coordination intended to prevent large bounded commands from being starved by smaller arrivals.
Changes:
- Adds
line.lock, exclusive-name bypassing, and a 300-second yield. - Adds fairness, interruption, and crash-recovery tests.
- Updates queue behavior documentation.
| File | Description |
|---|---|
skills/bounding-heavy-commands/SKILL.md |
Documents waiter ordering. |
skills/bounding-heavy-commands/scripts/bounded_run.py |
Implements line-lock coordination. |
skills/bounding-heavy-commands/scripts/tests/test_bounded_run.py |
Tests ordering and lock recovery. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Review round on 122f84f (review 5360222651). No suppressed findings.
Comment gate ( |
73648b4 to
55f46fe
Compare
55f46fe to
dc79f77
Compare
dc79f77 to
44aec30
Compare
44aec30 to
c940707
Compare
c940707 to
070820f
Compare
…aking a waiting command The wrapper kept no order among waiting commands. A command that needs many slots started only when all of them were free at the same moment, so a steady stream of smaller commands could keep it waiting for as long as the stream went on. A first measurement, which needs every slot, was the worst case, while the skill told agents that the queue puts commands in sequence. Waiters now take a blocking flock on an empty line.lock before they try for slots, and keep it until they hold their slots. Only the waiter at the head of the line tries; the others block in the kernel, which also releases the line lock of a waiter that dies. A waiter behind others logs that it waits behind other commands in the line. Two cases would stop the whole line, so the head does not keep it there. A waiter checks its exclusive names before it enters the line and leaves the line when a name is taken, so a server that holds a name does not block the commands of other names. The head also leaves the line when no slot comes free for 300 seconds, so a server that holds a slot cannot block its own client behind a command that needs that slot. reserve.lock and the all-or-nothing try stay, so an older copy of the wrapper still shares the slots safely. Closes #54 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t of inherited locks The layer below added a lock file for the memory check, so the lock directory now holds six files in this test: two slots, the name, the reserve turn, the line, and the memory check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… what it does not The skill said that a large command is never overtaken by smaller commands that arrive after it, and that the commands after a first measurement wait behind it. The kernel gives the line lock to its waiters in no fixed order, and a head with no free slot for 5 minutes lets the others try first. What holds is narrower: only the head tries for slots, so the commands behind it do not take the slots that it waits for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
070820f to
fafe4ea
Compare


Description
Fixes #54
A bounded command that needs many slots could wait forever while smaller commands kept starting, because waiters tried for slots with no order and the first to try at the right moment won. Waiters now take turns in a line: a waiter holds a lock on an empty
line.lockwhile it tries for its slots, so a command that arrives later cannot take the free slots ahead of the one at the head. A small command can now wait behind a large one even when a slot is free; that is the cost of the guarantee.Changes
line.lockand keeps it until it holds its slots. Only the head of the line tries. The others block in the kernel, which also releases the lock of a waiter that crashes.--exclusivenames are held stays out of the line, so a head never blocks the line on a name.Challenges
The line alone would deadlock with a server run through the wrapper. The server holds slots or an exclusive name, the head waits for them, and the server's own client waits behind the head, while the agent stops the server only after the client ends. The exclusive-name check and the head's time limit remove that cycle. As a result, the progress guarantee holds only while some slot comes free at least once every 300 seconds. The line also has no fixed order: the kernel gives the lock to its waiters in no set order, and a new caller can win it before a blocked one. So a large command reaches the head by chance at each handover, not by its time of arrival. Once it is the head, no smaller command takes the slots that it waits for.
Related
Testing
TDD. Process tests hold at least one slot at all times with a stream of 1-slot commands, and check that a command which needs all the slots, and a first measurement with no
--memory, start within 30 seconds. They failed before the change: about 180 small commands started while the large one waited. Other tests check that killing the waiter at the head of the line does not block the next one, that the lock directory then holds only empty files, and that SIGINT to a waiter blocked in the line ends it with 130. Unit tests with a fake clock cover the head's time limit, and a fake held name covers the exclusive-name check. The new tests passed 5 more times in a row. The full suite passes on Python 3.14; macOS was not run locally, and CI covers it.🤖 Generated with Claude Code