Skip to content

feat(skills/bounding-heavy-commands): measure every heavy command of a project in one run before agents need them - #63

Merged
sourcehawk merged 14 commits into
feat/bound-before-measure-tablefrom
feat/measure-whole-project
Sep 30, 2026
Merged

sourcehawk merged 14 commits into
feat/bound-before-measure-tablefrom
feat/measure-whole-project

Conversation

@sourcehawk

@sourcehawk sourcehawk commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Description

Closes #56

Heavy commands were measured one at a time, when an agent first needed each one, in the middle of feature work on a busy machine. Each first measurement took the whole queue at a random moment, and a project's record filled up unevenly. When a project has no record, discovery now covers every heavy command of the project, and the agent writes one command line that measures all of them at several --cpus values and asks the user to run it. The wrapper gets --measure-rows, which measures one command's rows largest first and passes each row's suggested budget to the next, so that line needs no state between calls.

Changes

  • --measure-rows N,N,... measures one command at each --cpus value, largest first. The largest row uses the call's --memory, and each smaller row uses the suggested budget of the row before it. After a failed row, the next row keeps the failed row's --memory, so a failed run's peak is never used as a budget.
  • --label NAME tags the output. Each measurement prints one row line in a fixed form: bounded-run: row label=<name> cpus=<n> budget=<n>M peak=<n>M exact=<yes|no> exit=<code>.
  • Discovery: with no record, find every heavy command, plan rows at all, half, and a quarter of the processors (half is the default row, and a command with self-bound: none, or one that reuses its own output such as a build, gets that row only), and write one ;-joined line with a --measure-rows call per command, each with a label of its own. The agent asks the user to run it, and does not run it unasked. When the user ran it in a terminal, the agent asks for the row lines and the end of each command's output.
  • While the user decides, a heavy command the agent needs runs at half --cpus with no --memory. If the user declines, discovery falls back to measuring on demand, as before.
  • Two new red-flag rows: measuring only the command needed now, and running the measurements unasked.

Challenges

A row that exits with a stop code (129, 130, 131, 143) ends the remaining rows of that call. But Ctrl-C on the ;-joined line ends only the current wrapper call: the wrapper exits normally with 130 rather than dying from the signal, so the shell moves on to the next command, and the user presses Ctrl-C once per command.

Related

Testing

TDD for the script. The tests cover parsing (rows sorted largest first and deduplicated, and bad rows, including digits that are not ASCII, labels, and option combinations rejected), the exact row line, the chain of budgets between rows, a failed row, a stop signal ending the rows, and a stop after a failed row keeping the first failed exit code. They also run a real process over two rows. In the RED baseline, an agent in a project with six heavy commands measured only the unit tests at a --cpus it picked, and left five commands without an entry. With the change, a fresh agent wrote one line that measured all six commands at three --cpus values, with the port name of the integration suite. It asked the user to run it, ran the unit tests meanwhile, and wrote the rows from sample output, with no row for a run that stopped early.

🤖 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

The new option has an invalid-input crash and several conflicting usage instructions.

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

Open (3)
What changed in this PR

Adds project-wide heavy-command measurement before feature work begins.

Changes:

  • Adds labeled multi-row measurements with chained budgets.
  • Updates discovery to measure all heavy commands together.
  • Adds parser, sequencing, failure, signal, and process tests.
File Description
SKILL.md Documents project-wide measurement workflow.
bounded_run.py Implements labels and multi-row measurements.
test_bounded_run.py Tests parsing and measurement behavior.

💡 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
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
sourcehawk force-pushed the feat/measure-whole-project branch from b3677f2 to 8fd82bd Compare September 30, 2026 00:58
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on b3677f2 (review 5360221982). No suppressed findings.

  • Reject non-ASCII digits before converting --measure-rows: fixed in abc2709, with a test.
  • Document the required --memory seed for --measure-rows: applied in 8fd82bd.
  • Reuse step 1 row selections: applied in 8fd82bd.

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

Row planning, output handoff, label uniqueness, and exit-code handling have unresolved correctness issues.

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

Open (4)
Resolved since last review (3)

Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Comment thread skills/bounding-heavy-commands/SKILL.md Resolved
Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:12
@sourcehawk
sourcehawk force-pushed the feat/measure-whole-project branch from 8fd82bd to c0c5270 Compare September 30, 2026 01:12
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 8fd82bd (review 5360279500). No suppressed findings.

  • Require unique labels for commands in joined lines: applied in c0c5270.
  • Preserve first nonzero exit code after interruption: fixed in 5fcc183, with a test.
  • Measure all CPU quota rows for self-bound none commands: declined. See the thread: a CPU quota does not change the number of things that the tool runs at once, and the extra rows cost two full runs each.
  • Request complete output when external terminal output is unavailable: applied in c0c5270.

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

Oversized numeric row input can escape argument handling with an uncaught traceback.

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

Open (2)
Resolved since last review (4)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 01:22
@sourcehawk
sourcehawk force-pushed the feat/measure-whole-project branch from c0c5270 to 3937e25 Compare September 30, 2026 01:22
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on c0c5270 (review 5360361217). No suppressed findings.

  • Handle oversized numeric row values without traceback: fixed in ccc0be2, with a test.
  • Correct documented fixed-form row syntax: fixed in 3937e25.

Comment gate: one new inline comment in parse_arguments, "int() refuses a number with more digits than its limit." It stays, because it gives the reason for the except, which the code cannot show. 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

Label validation can produce malformed multi-line row output, and its documented restrictions are incomplete.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low 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: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

🔵 Needs a closer look

A pending stateful command may run before measurement and produce an invalid cached measurement.

Review effort: Balanced
Findings: None

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

In code that hasn't changed since last review

Medium severity Pending measurements can be bypassed by cached generator output

skills/​bounding-heavy-commands/​SKILL.md:127

This single-row exception only prevents later rows in the same call from reusing output. The new instructions at lines 92 and 137 still allow an agent to run this same build/generator while the measurement is pending; its subsequent single measurement can then be a cached no-op and record an undersized budget. Ensure a pending stateful command is measured before any needed run that warms its output, or otherwise restore/force equivalent work before its measurement.

@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round on 0e6a215 (review 5360737970). The review has no inline findings.

  • Previously missed, on SKILL.md:127, "Pending measurements can be bypassed by cached generator output" (no thread): declined, no change. The one-row rule of 4e4f754 exists because rows in one --measure-rows call run back to back, so every row after the first would measure a warm command against a cold one. A single measurement of a build after an earlier build is the normal state of a project, not a fault of the pending line: the agents' later runs are warm too, so the recorded budget fits the runs it is used for. When a cold run does need more, the hard cap stops it with exit 137, and the existing rule (step 5 of §Discovery) measures it again at two times the budget. A rule that orders every run of a stateful command around a pending measurement would add text to tuned skill prose for a case that the cap already corrects.

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 described workflow and covers the new behavior comprehensively.

Review effort: Balanced
Findings: None

@sourcehawk

Copy link
Copy Markdown
Owner Author

Follow-up round, from a finding on #71 (review 5363805257, thread r4142652768) about code of this PR.

  • A SIGTERM, SIGHUP, or SIGQUIT between two rows, or after the list, ended the wrapper with a traceback. Fixed in 5b94bc0: _bounded_rows catches the signal around the whole list, and main() catches _Stopped. New test: test_a_stop_signal_outside_a_row_ends_main_with_its_code.

Comment gate, self-evaluated: the rows-loop comment changed to "A signal while a row runs comes back as its exit code. A signal at any other time in the list raises." A new comment in main() reads "The handlers of --measure-rows can fire after its list ends, before they are put back." Both stay, because they give reasons that the code here 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

🟢 Approval recommended

The implementation, documentation, and comprehensive tests consistently satisfy the stated workflow.

Review effort: Balanced
Findings: None

sourcehawk and others added 14 commits September 30, 2026 11:21
…a project in one run that the user starts

A project with no record got its measurements one command at a time, when an agent first needed each command. An agent asked to fix a bug and run the unit tests measured only the unit tests, at a --cpus that it picked, asked the user nothing, and left the other heavy commands without an entry. Each of those later first measurements holds the whole queue in the middle of someone's work, and the rows of the record come out at whichever --cpus each session picked.

When the record does not exist, discovery now covers every heavy command of the project. The agent writes one command line that measures each command at all, half, and a quarter of the machine's processors, and asks the user to run it when the machine is quiet, or to tell the agent to run it. It then reads the row lines into the record, and writes a row only from a run that did its full work. If the user declines, the agent measures the command that it needs, as before. A command that the project adds later is still measured when an agent first needs it.

The wrapper gets two options for this. --measure-rows N,N,... measures the command at each --cpus of the list, the largest first, and gives each smaller row the suggested budget of the row before it as its --memory, so that only the first row of a command holds the whole queue. --label names the command in a new fixed-form row line that each measurement prints, so that the agent reads the output without guessing.

Closes #56

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…at is not ASCII digits

str.isdigit() accepts characters such as a superscript two, which int() cannot read, so such a value ended the wrapper with a traceback in place of its option error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and measure the rows that step 1 chose

The skill said that the largest row of --measure-rows runs with no --memory, but the wrapper takes a --memory for it, as its usage text shows. The whole-project line also told each command to use all, half, and a quarter of the processors, while step 1 gives a command with self-bound none the row at half only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…when a stop signal ends the rows

The usage text and the skill say that the exit code of --measure-rows is the first exit code of a row that is not 0. When a row failed and a later row was stopped by a signal, the wrapper returned the code of the stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s own label, and ask for output from a terminal

Step 5 puts each row line into the entry of its label, so two commands with one label made their rows ambiguous. And when the user runs the line in a terminal, the agent cannot see its output, so it now asks the user for the row lines and the end of the output of each command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…th too many digits for int()

int() refuses a number with more digits than its limit and raises ValueError, which ended the wrapper with a traceback in place of its option error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…text as the wrapper prints it

The usage text wrote each size field as MIBM, which reads as a literal value. The wrapper prints a number followed by M, as the skill shows.

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

The check used re.match with $, which also matches before a final line break, so a label such as "lint" with a line break passed and split the row line in two. It now uses re.fullmatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a letter or a digit

The wrapper rejects a label that starts with '.', '_' or '-', and the option table did not say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to six digits

The last fix relied on int() refusing a number with too many digits, but Python 3.9 has no such limit, so the new test failed there. Each value now has at most six digits, which the parser checks itself on every version, and the option error names the range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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>
…s own output at one row only

--measure-rows runs a command once for each row, one after the other. A build, a generator, or an install reuses the output of the run before, so its smaller rows did less work and recorded a peak that was too small. Such a command now gets the row at half only, like a command with self-bound none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…for each stop signal between the rows

The last fix covered SIGINT only. SIGTERM, SIGHUP, or SIGQUIT while a later row waited in the queue still ended the wrapper with the default action of the signal, and the failure of an earlier row was lost. --measure-rows now handles the three signals for the whole list and returns the first failed code, or 128 plus the signal. The handlers of the caller come back when the list ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the list of rows

The handlers of --measure-rows raise at any point of the list, but the rows loop caught the signal only while a row waited, and main() caught SIGINT only. A SIGTERM, SIGHUP, or SIGQUIT between two rows, or after the list before the handlers were put back, ended the wrapper with a traceback. The loop now catches it for the whole list and keeps the first failed code, and main() catches it after the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcehawk
sourcehawk force-pushed the feat/measure-whole-project branch from 5b94bc0 to 83c2de0 Compare September 30, 2026 10:22
@sourcehawk
sourcehawk merged commit e887319 into main Sep 30, 2026
10 checks passed
@sourcehawk
sourcehawk deleted the feat/measure-whole-project 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.

Measure every heavy command of a project in one run, before agents need them

2 participants