Skip to content

fix(skills/bounding-heavy-commands): stop endless waits for free memory - #85

Merged
sourcehawk merged 15 commits into
mainfrom
fix/memory-wait-never-ends
Oct 5, 2026
Merged

sourcehawk merged 15 commits into
mainfrom
fix/memory-wait-never-ends

Conversation

@sourcehawk

@sourcehawk sourcehawk commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Description

Fixes #84

A bounded command whose budget did not fit in free memory waited with no end when no other bounded command ran, because only programs outside the queue could free that memory. It held its slots while it waited. Now the wrapper sees that no bounded command runs, prints one fixed no-memory line with the largest budget that fits, releases its slots, and exits 75. The skill tells the agent to run a smaller recorded row, or to tell the user. A first measurement with no --memory on a busy machine without the hard cap now stops at once instead of waiting, and goes to the user.

Changes

  • bounded_run.py: a wrapper holds run-<unit>.lock while its command runs. The memory wait counts the running commands (run files that another process holds, plus bounded scopes under the hard cap), and stops when none runs and the budget does not fit.
  • The stop prints bounded-run: no-memory budget=<n>M free=<n>M headroom=<n>M fits=<n>M and exits 75. A --measure-rows run ends at the first row that stops this way; a command that exits 75 by itself is an ordinary non-zero exit.
  • --check prints fits=<n>M as the last field of its first line, so an agent can choose a row before it runs.
  • SKILL.md: the wrapper section names exit 75; a new ### After exit code 75 section gives the next move (largest recorded row within fits, or report budget, free, and fits to the user); the subagent rule and the Red Flags table say the same.

Challenges

Only commands that have started count as running, not commands that hold slots. Two waiters that each hold slots would otherwise count each other and wait forever. A command started by an older version of the wrapper holds no run file. Under the hard cap its scope still counts, but without the cap it is not counted, so the new wrapper can stop where a wait would have ended, until every session runs this version.

Testing

The script tests pass: 361 tests, run through the wrapper at --memory 512M. New tests cover the run-file count (held, leftover, slot files ignored), largest_fit_mib at its edges, the stop and the waits around it (including a command that ends between the reads, a lock directory that cannot be listed, and cgroup scopes that cannot be listed), the exit code and fixed line, the rows behavior for both kinds of 75, the cap-path scope count, and fits in the check. A subprocess test replays the reproduction from #84: --memory 12288M on a simulated 28000 MiB machine with 14000 MiB free exits 75 in about a second with fits=11008M, and all 10 slots are free after. On this machine, with real bounded commands of other projects running under the hard cap, the same call keeps waiting as it should.

The skill text went through RED and GREEN with isolated subagents, three runs for each of two scenarios: a recorded command that exits 75, and a first measurement that exits 75. Before the edit, all six runs read exit 75 as a full queue, and two ran the same budget again. After it, all six named the cause; the recorded-command runs picked the largest row within fits, and the measurement runs ran nothing and reported the values to the user.

🤖 Generated with Claude Code

sourcehawk and others added 10 commits October 5, 2026 11:05
… command runs (#84)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… fits now (#84)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unded command runs (#84)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he wrapper exits 75 (#84)

Exit code 75 means that no other bounded command ran, so programs
outside the queue hold the memory and the same budget fails again.
The skill now gives the next move: the largest recorded row within
fits, or a report to the user for a measurement or when no row fits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… can free the budget (#84)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts in the check (#84)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a precise fits (#84)

The steps after exit 75 sat between the wait rules and their bullets,
so the bullets read as part of them. They now have their own section,
which needs the no-memory line, since a command can exit 75 by itself.
fits counts memory only; starts also counts the slots and the line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…apper's own no-memory stop (#84)

- bounded_once re-raises NoMemory after the log line, so only the wrapper's own stop ends the rows. A command that exits 75 by itself is a normal non-zero exit.
- The usage text gives the 75 paragraph its own block and says that fits counts only memory.
- A test covers the older-wrapper scope count in read_running under the hard cap.
- The --check test asserts " line=busy fits=".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t section (#84)

The new section after exit 75 made "see the next section" point at it.
Name the section instead. The Red Flags row now says that the same
budget fails again only while programs outside the queue hold the
memory, as the section does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… every place (#84)

The check section and largest_fit_mib still said that fits would start
now, but it counts memory only. Also rewrap the stop-signal paragraph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 10:20
@sourcehawk sourcehawk self-assigned this Oct 5, 2026

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

A memory-sampling race and inconsistent exit-status handling remain unresolved.

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

Open (4)
What changed in this PR

Addresses #84 by stopping memory waits when no running bounded command is detected, rather than holding queue slots indefinitely.

Changes:

  • Track running commands and report memory refusals with exit 75.
  • Add fits to queue checks and stop measurements on memory refusal.
  • Add recovery guidance and regression coverage.
File Description
skills/​bounding-heavy-commands/​SKILL.md Defines memory-refusal recovery and reporting.
skills/​bounding-heavy-commands/​scripts/​tests/​test_bounded_run.py Covers tracking, memory refusals, row handling, and queue cleanup.
skills/​bounding-heavy-commands/​scripts/​bounded_run.py Implements running-command tracking, fast exits, and budget-fit reporting.

💡 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
sourcehawk and others added 2 commits October 5, 2026 11:32
…o-memory stop (#84)

The last bounded command can end between the read of the free memory
and the count of running commands, since it ends without the memory
lock. The wait now reads the memory again after a count of 0, and
starts when the budget fits. A row that stops for memory after a
failed row now exits 75, as its line says. The usage text says that a
command can exit 75 by itself, and the lock test accepts the count from
before the run file exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e everywhere (#84)

The Red Flags row read exit 75 alone as a memory stop, but a command can
exit 75 by itself. The --measure-rows entry now says that a memory stop
ends the list with 75.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 10:32
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round 1. Review base: 5b12fd9. All four findings were valid and are fixed in d41434e and 5ca7705; each thread has its reply. The review had no suppressed comments.

Comment changes in this round:

Declaration Lines (base → now) Sentence Verdict Source Judge
module docstring, bounded_run.py:2 (text that users read) 86 → 90 "Exit code 75 with the line below means that the budget did not fit in the free memory while no other bounded command ran, so nothing in the queue could free it, and the command did not start." KEEP bounded_once logs the line and raises NoMemory; bounded returns 75 evaluator
"A command can also exit 75 by itself, without the line." KEEP run_command / exit_code_of pass the command's code through evaluator
"A row that stops with the no-memory line ends the list with exit code 75." KEEP _bounded_rows returns EXIT_NO_MEMORY on NoMemory evaluator
inline, bounded_run.py:740 in wait_for_memory 0 → 1 "A command ends without the memory lock, so the last one can free its memory after the reads above." keep a concurrency fact the code cannot show author
inline, test_bounded_run.py:3035 0 → 1 "The command can list the lock directory before the wrapper makes its run file." keep why the test accepts two counts author

The suite passes: 359 tests through the bounded wrapper.

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 mixed-version behavior is an explicit compatibility tradeoff, and remaining feedback concerns non-blocking documentation clarifications.

Review effort: Balanced
Findings: None

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

In code that hasn't changed since last review

Low severity Avoid attributing no-memory conditions to outside programs

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

During a mixed-version rollout without the hard cap, an older wrapper has no run file and can remain active when this wrapper reports no-memory. The PR acknowledges that limitation, but this paragraph and step 2 tell agents that outside programs hold the memory. Qualify the diagnosis as no detected running command and report the observed budget, free, and fits without asserting who holds the memory. Apply the same qualification to the summary at line 51, the Red Flags row at line 223, and the Python module's exit-code documentation.

… who holds the memory (#84)

Without the hard cap, a command of an older wrapper holds no run file,
so a no-memory stop does not prove that programs outside the queue hold
the memory. The text now says that the wrapper found no bounded command
running, and the agent reports budget, free and fits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 10:41
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round 2. Review base: 5b12fd9. The review posted no inline comments and listed one previously missed finding, which has no thread.

  • Avoid attributing no-memory conditions to outside programs (SKILL.md:173, also lines 51 and 223 and the module docstring): applied in 7dbf8a1. Without the hard cap, an older wrapper's command holds no run file, so a stop does not prove who holds the memory. The four places now say that the wrapper found no bounded command running, and step 2 tells the agent to report that the budget does not fit while no bounded command runs, with budget, free, and fits.

Comment changes: the module docstring block of bounded_run.py changed (90 → 90 lines, no growth); its one sentence now states what the script observed. No flag from the comment gate.

The suite passes: 359 tests through the bounded wrapper.

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

Running-command detection can incorrectly report no active workload after a directory read failure or wrapper termination.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Handle directory listing errors without assuming no running commands

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

A failed directory listing is not evidence that no command is running. Without the hard cap, an I/O error here makes read_running() return zero, so a low-memory request incorrectly exits 75 even when another command still holds its run lock. Report a WrapperError, consistent with other lock-directory failures, or propagate an unknown count through the callback instead of returning zero.

…not be listed (#84)

A failed listing of the lock directory gave a count of 0 running
commands, so an I/O error could end in a false no-memory stop. It now
gives no count, and the wrapper waits as it did before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 10:51
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round 3. Review base: 5b12fd9.

  • Preserve child liveness tracking after wrapper termination (thread): declined, with the reason in the thread. A hard-killed wrapper also loses its slot locks, so its orphaned child already runs outside the queue. Making the child count would need it to inherit a lock, which the suite forbids on purpose.
  • Handle directory listing errors without assuming no running commands (previously missed, no thread): applied in 8d5601e. running_commands returns None when the lock directory cannot be listed, read_running passes that on unless a bounded scope runs, and the wait treats None as "not known: wait". New test: test_a_directory_that_cannot_be_read_gives_no_count.

Comment changes, judged by a fresh evaluator:

Declaration Lines (base → now) Sentence Verdict Source
module docstring, bounded_run.py:2 (text that users read) 86 → 90 "Exit code 75 with the line below means that the budget did not fit in the free memory while the script found no other bounded command running, so nothing in the queue could free it, and the command did not start." KEEP wait_for_memory, bounded_once, bounded
running_commands, bounded_run.py:489 4 → 5 "Returns None when the directory cannot be read." KEEP except OSError: return None; the caller waits on None

The suite passes: 360 tests through the bounded wrapper.

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

Failed scope enumeration can incorrectly trigger exit 75 while an older bounded command is still running.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

…ot be listed (#84)

A failed listing of the scopes counted as no bounded command running,
but a command of an older wrapper shows only as a scope. The count is
now unknown in that case unless a run file shows a running command, so
the wrapper waits and does not stop with 75.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 5, 2026 12:33
@sourcehawk

Copy link
Copy Markdown
Owner Author

Review round 4. Review base: 8d5601e.

  • Preserve unknown scope state when cgroup listing fails (thread): applied in ce14f07. A failed scope listing now gives an unknown count unless a run file shows a running command, so the wrapper waits and does not stop with 75. New test: test_a_scope_listing_that_fails_gives_no_count_when_no_run_file_shows_a_command.

Comment changes: two added blocks, no growth flag. The doc comment of bounded_scope_count states its None result, which the caller handles. The inline comment in read_running gives the reason that only a run file proves a count when the scopes cannot be listed.

The suite passes: 361 tests through the bounded wrapper.

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 acknowledged inability to detect older wrappers without a hard cap needs human acceptance of the resulting fail-fast behavior.

Review effort: Balanced
Findings: None

Resolved since last review (1)

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.

bounding-heavy-commands: a bounded command waits forever for memory that no bounded command holds

2 participants