Skip to content

feat(skills/bounding-heavy-commands): let agents see the queue to choose a row and name what holds it - #64

Merged
sourcehawk merged 13 commits into
feat/measure-whole-projectfrom
feat/queue-check
Sep 30, 2026
Merged

sourcehawk merged 13 commits into
feat/measure-whole-projectfrom
feat/queue-check

Conversation

@sourcehawk

@sourcehawk sourcehawk commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Description

Closes #57

With a table of measured rows per command (#53), an agent had to choose a row before each run and had nothing to choose with. It guessed, and when the queue was full nobody could see what held it. The wrapper gets --check, which reports the state of the queue without taking a reservation: free slots, free and unused memory, the line, each running bounded command, and for each given budget whether a run of that budget would start now. The skill uses it to choose the largest row that would start now, or the default row when none would. The chosen row still goes through the queue, because a check is a snapshot and not a reservation.

Changes

  • bounded_run.py --check [--memory <budget>]... prints fixed-form lines: check slots=... free-slots=... free=... unused=... line=..., then one check held unit=... budget=... used=... age=... dir=... command=... line per running bounded command, then one check budget=... slots=... headroom=... starts=<yes|no> line per budget, with the headroom that the wait keeps beside that budget. It exits 0 and holds no lock when it returns.
  • The run and the check use one memory test, memory_fits, so they cannot disagree about when a budget fits.
  • Skill: before a run of a command with more than one row, run the check with the budgets of its rows and choose the largest row that would start now; otherwise use the default row and let it wait. A subagent gets the rows and the check line and chooses at each run, because a check made at dispatch time is stale by the time the subagent runs.
  • Skill: after a long wait, the agent names the held commands, with their directory and age, when it tells the user that the machine is full. The rule that each dispatch prompt carries tells a subagent to do the same in its report. It never stops a held command. One new red-flag row covers "the check says it would start, so I'll run the plain command".

Challenges

The check counts free slots only while it holds the turn lock that waiters use for their own tries, so it never makes a free slot look held to a real waiter. When a waiter holds that lock, the count is - and no budget reports starts=yes. The held lines come from the bounded-run-* scopes in the slice that the cap probe finds, so where there is no hard cap there are no held lines.

Related

Testing

TDD with temp lock directories, injected memory readers, and fake cgroup and proc trees. The tests cover the counts with slots held by the test, a command taking every free slot after a check, a busy line, a busy turn lock, the per-budget answers, a whole-queue budget, the held lines (probe scopes skipped, unreadable fields shown as -, a scope that ends while it is read, a long command and a directory with a line break each kept on one line, and control characters printed as ?), and the option errors. In the RED baseline, an agent with rows at 2, 4, and 8 CPUs on a busy machine picked the middle row by guess. With the change, a fresh agent ran the check with the three budgets, chose the largest row that would start, fell back to the default row when none would, and rejected the plain command. A live check on the shared machine named the command that held the queue, with its directory and age.

🤖 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

Nested checks can misreport memory availability, and held-command reporting is incomplete for some paths.

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

Open (2)
What changed in this PR

Adds queue inspection so agents can select measured command rows and report queue holders.

Changes:

  • Adds --check queue-state reporting.
  • Documents row selection and wait diagnostics.
  • Adds unit and process-level tests.
File Description
SKILL.md Defines check-based selection and reporting.
bounded_run.py Implements queue checks and held-command details.
test_bounded_run.py Tests check output, locking, and argument handling.

💡 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 8d3a934 (review 5360224971). No suppressed findings. The summary line of the review names nested checks, but no finding goes with it.

  • Normalize working directory before embedding in held records: fixed in e7d4aa9, with a test.
  • Include long-wait diagnostic in the mandatory subagent prompt: applied in 7620764.

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

🟡 Changes recommended

Check-mode synchronization can report incorrect availability, and parsing regresses a valid exclusive name.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (2)

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

Copy link
Copy Markdown
Owner Author

Review round on 7620764 (review 5360290361). No suppressed findings.

  • Misclassifies --check when used as an exclusive filename: fixed in cf28048, with a test.
  • Check resource snapshot without memory.lock causes false starts=yes: declined. See the thread: the check is a snapshot by design, and a wrong starts=yes in the sub-second window only makes a run wait in the queue.

Comment gate: this round added, changed, or removed no code comment on this layer. Self-evaluated fallback: this session could not dispatch an agent.

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

The reported headroom is inconsistent with budget decisions, and the fallback row conflicts with issue #57’s acceptance criteria.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
Resolved since last review (2)

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

Copy link
Copy Markdown
Owner Author

Review round on cf28048 (review 5360362265). No suppressed findings.

Comment gate: this round added, changed, or removed no code comment on this layer. Self-evaluated: this session could not dispatch an agent.

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

The hard-cap test decorator was displaced, causing hard-cap tests to run on unsupported platforms while no-cap check tests are skipped.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (2)

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

Cap probing can make the reported slot and line snapshot up to roughly 30 seconds stale.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 08:57
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 2d86e2b (review 5363900120). No suppressed findings.

  • Snapshot queue state after cap-support probing: fixed in 59816d4, with a test.

Comment gate, self-evaluated because this session could not dispatch an agent: one new inline comment, "The probe can take seconds, so the state of the queue is read after it." It stays, because it gives the reason for the order, which the code cannot show.

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

🔵 Needs a closer look

Check mode can undercount reserved memory when invoked from within a bounded scope.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Count current bounded scope in --check queue summary

skills/​bounding-heavy-commands/​scripts/​bounded_run.py:1353

When --check runs inside an existing bounded scope, skipping own_scope_name() omits that running command's unused reservation. The global queue summary can therefore report starts=yes even though an independent wrapper would count that reservation and wait (for example, 6000 MiB free, 3072 MiB unused, 1024 MiB headroom, and a 2048 MiB budget). Count every bounded scope here; probe scopes are already filtered by _bounded_scopes.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 09:06
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 59816d4 (review 5363987415). The review has no inline findings.

  • Previously missed, on bounded_run.py:1353, "Count current bounded scope in --check queue summary" (no thread): fixed in 0632eb3. The check now counts the unused budget of every bounded scope, also the one that the check runs in. New test: test_a_check_inside_a_bounded_command_counts_its_unused_budget_too.

Comment gate, self-evaluated because this session could not dispatch an agent: one new inline comment, "A wrapper that starts on its own counts every bounded scope, also the one that this check runs in." It stays, because it gives the reason for the empty skip list, which the code cannot show.

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

🔵 Needs a closer look

The fixed-form holder output has ambiguous, spoofable field boundaries.

Review effort: Balanced
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Medium severity Encode dir and command to prevent ambiguous record field boundaries

skills/​bounding-heavy-commands/​scripts/​bounded_run.py:817

Encode the dir and command values before placing them in this fixed-form record. Printable paths and arguments may legally contain the delimiter text command=; for example, a working directory named /tmp/x command=fake produces multiple indistinguishable field boundaries, so an agent can misidentify what holds the queue. Use an unambiguous representation such as JSON strings or percent-encoding, and update the documented format and tests accordingly.

@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 0632eb3 (review 5364092912). The review has no inline findings.

  • Previously missed, on bounded_run.py:817, "Encode dir and command to prevent ambiguous record field boundaries" (no thread): declined, no change. This is the third round on the encoding of the held line; the earlier rounds folded line breaks and turned control characters into ?. The command field is the last field, so the only ambiguity left is a working directory whose name contains the text command=. Every scope that the check lists belongs to the same user who runs the check, so nothing crosses a trust boundary. The line is a diagnostic that the agent names to the user, not a record that code acts on. JSON or percent-encoding would make the plain paths that agents quote to users harder to read in every normal case, to guard against a directory name that the user would have to make on purpose.

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 stated workflow and includes thorough coverage of its concurrency and diagnostic behavior.

Review effort: Balanced
Findings: None

sourcehawk and others added 13 commits September 30, 2026 11:21
…fore it chooses a measured row

A command in the record can have a row for each --cpus, and an agent must choose one before each run. It had nothing to choose with: the skill tells it that looking at the load does not protect the machine, so an agent with rows at 2, 4, and 8 processors on a busy machine chose the middle row by guess.

The wrapper now has a check mode, --check [--memory <budget>]..., that runs no command and holds no lock when it returns. It prints the slots, the free slots, the free memory, the unused budgets of the running commands, the headroom, and whether a command waits in the line. For each budget it prints the slots that it needs and whether a run of that budget would start now, with the same memory test as the wait. It counts the slots under the turn lock without a wait, so it never makes a free slot look held to a waiter.

The skill tells an agent to run the check before a run of a command with more than one row, to choose the largest row that would start now, and to choose the default row and let it wait when none would. The check is a snapshot, so the chosen row still goes through the queue. A subagent gets the rows and the check line, and chooses the row itself before each run.

Closes #57

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… queue in the check

When the queue is full, every session waits and no one can see what holds it. The user has to ask, and the agent has no way to answer: the skill tells it not to look for the process that holds a lock file.

The kernel already knows. Each running bounded command is a scope in the slice that the probe finds. The check now prints one held line for each such scope, with its budget, the memory it uses, its age, its working directory, and its command without the prefix that the wrapper adds. A field that cannot be read is '-', and a scope that ends while it is read is skipped. Without the hard cap there are no scopes, so there are no held lines.

The skill tells an agent to run the check after a long wait and to name the held commands in its message to the user. It says that the held lines are the way to name what holds the queue, and that a held command belongs to another session or to the user, so the agent never stops it.

Refs #57

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mand on one line

A path name can hold a line break, so a held line of the check could split in two, and the second part could read as a line of its own. The directory now gets the same whitespace folding as the command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a long wait

The rules for the wait tell an agent to run the check after a long wait and name the held commands, and a subagent tells its dispatcher. The rule that a dispatch prompt must carry said only to report the length of the wait, so a subagent that follows its prompt did not run the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n can stand

The parser took any --check before the '--' as the check option, also when it was the value of another option, such as the name of --exclusive --check. It now skips the value of each option that takes one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t on its line of the check

The first line of the check printed the headroom of a small budget, while each starts answer used the headroom of its own budget, which is 0 for a budget of the whole queue. So a check could print headroom=1024M and starts=yes for a budget that the free memory holds only without that headroom. The headroom now stands on each budget line, and the first line no longer has one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he free memory in the check

The wait reads them in this order, so that a command that grows between the two reads can only make the free memory look smaller. The check now reads them in the same order, so its answer does not start a command that the wait would hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e hard-cap tests

The process tests of the check went in between the skip decorator and HardCapTest. So the check tests, which run with no cap, were skipped where no cap exists, and the hard-cap tests ran there and failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…udget 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>
…eld command as a question mark

The held lines of the check folded whitespace but kept other control characters, so an argument or a path with a terminal escape sequence went to the terminal as it was and could change what the check showed. Each character that is not printable is now a question mark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ns inside among the held commands

The check skipped its own scope for the held lines as it does for the count of unused budgets. So a check run from inside a bounded command did not name that command, although the held lines name every running bounded command. The held lines now skip only the probe scopes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k 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>
…s in among the unused budgets

A check run from inside a bounded command left that command's unused budget out, so it could answer starts=yes where a wrapper that starts on its own counts that budget and waits. The check now counts every bounded scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcehawk
sourcehawk merged commit a3a67a6 into main Sep 30, 2026
5 checks passed
@sourcehawk
sourcehawk deleted the feat/queue-check 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.

Let an agent see the queue before it chooses which measured row of a command to run

2 participants