Skip to content

fix(skills/bounding-heavy-commands): stop smaller commands from starving a command that needs many slots - #61

Merged
sourcehawk merged 3 commits into
fix/queue-memory-accountingfrom
fix/queue-line-lock
Sep 30, 2026
Merged

sourcehawk merged 3 commits into
fix/queue-memory-accountingfrom
fix/queue-line-lock

Conversation

@sourcehawk

@sourcehawk sourcehawk commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

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.lock while 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

  • Before a waiter tries for slots, it takes a blocking lock on line.lock and 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.
  • A waiter whose --exclusive names are held stays out of the line, so a head never blocks the line on a name.
  • A head that sees no slot come free for 300 seconds leaves the line and joins again. So a command that does not end, such as a server whose own client waits in the line, cannot hold the line forever.
  • The skill says that waiting commands take turns in a line: only the head tries for slots, so the commands behind it do not take the slots that it waits for. It also says that the line has no fixed order and that a head yields after 5 minutes with no free slot.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Non-FIFO locking still permits starvation, and the documentation overstates the ordering guarantee.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

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.

Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Copilot AI balanced review requested due to automatic review settings September 30, 2026 00:58
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 122f84f (review 5360222651). No suppressed findings.

  • Non-FIFO flock acquisition can starve blocked large commands: applied in 73648b4 by narrowing the claim in the skill and the PR body. See the thread.
  • Qualify ordering guarantee when measurement yields the line: applied in 73648b4.

Comment gate (comment_growth.py): the recorded review base left the history in the rebase after the #58 fix, so the gate compared with the parent branch. The self-evaluated fallback applies: this session could not dispatch an agent. This round added, changed, or removed no code comment, so there is no flag of this round. The only flag on #64 is the module usage text, which the PR grew before the review to document --check. That is text that users read, and it stays as it is.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation matches the narrowed guarantees and includes comprehensive unit and process coverage.

Review effort: Balanced
Findings: None

Resolved since last review (2)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation matches the narrowed guarantees and includes comprehensive concurrency and process-level coverage.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation and documentation are consistent, with comprehensive coverage of the new concurrency behavior.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation, documentation, and comprehensive tests consistently address slot overtaking without introducing unresolved issues.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation and tests consistently cover the documented queue behavior and failure modes.

Review effort: Balanced
Findings: None

Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation and tests consistently enforce the documented head-of-line reservation behavior.

Review effort: Balanced
Findings: None

sourcehawk and others added 3 commits September 30, 2026 11:21
…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>
@sourcehawk
sourcehawk merged commit 7f23210 into main Sep 30, 2026
10 checks passed
@sourcehawk
sourcehawk deleted the fix/queue-line-lock branch September 30, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A bounded command that needs many slots can wait forever while smaller commands keep starting

2 participants