Skip to content

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

Closed

Description

@sourcehawk

What happened

An agent ran an end-to-end test command through bounded_run.py with --memory 12288M. That is the budget from the project record. The wrapper took 6 of the 10 slots and then started its wait for free memory. No other bounded command ran, so no budget in the queue could end and free memory. The wait needed 12288 MiB plus 2770 MiB of headroom, but only about 14230 MiB was free. Programs outside the queue (a browser, a container engine, a local cluster, other sessions) used the rest, and swap was more than half full.

The command waited for 2 hours and did not start. The skill says that a long wait means the machine is full and is never a fault, and its Red Flags table tells the agent not to lower --memory. So the agent kept the run in the queue. The user found the stall by hand, read the wrapper source to learn why, and stopped containers to free memory. While the command waited, it also held 6 slots that other bounded commands could not use.

Expected

The wrapper must tell a wait that can end apart from a wait that cannot. When no running bounded command holds memory that it can give back, and the free memory is less than the budget plus the headroom, only programs outside the queue can free that memory. In that state, the wrapper must stop at once with a clear message and a distinct exit code. The message says that the machine cannot give that budget now and gives the largest budget that fits. An alternative is that the queue counts fewer slots when the free memory cannot hold them all. Either way, the skill must tell the agent what to do next: run a smaller measured row, or tell the user what holds the memory.

Where in the plugin

  • Skill: feature-dev-workflow:bounding-heavy-commands
  • Section: ## Rules for the wait
  • Plugin version: 0.9.0

The wrapper is involved too: wait_for_memory in skills/bounding-heavy-commands/scripts/bounded_run.py has no time limit and does not check whether a running bounded command can free memory.

Instruction added by hand

the command should probably fail instead of deadlock a machine that is oversaturated and cannot even consume a single bounded command run, printa message that says the hardware cannot support that request right now, or reduce the available slots if there are not enough hardware capacity to support those 10 slots that may all be free. Then the agent can decide immediately to switch to a lower budget rather than hang forever

The user wrote this after the stall. Before it, nothing told the agent that the wait could not end.

Reproduction

Situation

You follow feature-dev-workflow:bounding-heavy-commands. The project record gives one heavy command with one row, a budget of 12288M. You run it through the wrapper in the background.

Environment facts

  • The wrapper reproduces the stall without a real load. Set a private lock directory and replace the measured memory with fixed values: BOUNDED_RUN_LOCK_DIR=<scratch-dir>/locks BOUNDED_RUN_TOTAL_MIB=28000 BOUNDED_RUN_FREE_MIB=14000 python3 ${CLAUDE_PLUGIN_ROOT}/skills/bounding-heavy-commands/scripts/bounded_run.py --memory 12288M -- true
  • With these values, the wrapper prints holding 6 of 10 slot(s) and then 14000 MiB free, unused running budgets not counted here, 2800 MiB headroom, budget 12288 MiB; waiting. It does not exit. Under timeout 20 it ends with exit code 124.
  • No other bounded command runs. --check --memory 12288M on the real machine gave free-slots=4 ... unused=0M and budget=12288M slots=6 headroom=2770M starts=no, with no held lines.
  • After 2 hours the wrapper still waits. The only new output is a still waiting line every 5 minutes.

Task prompt

Run the end-to-end tests for my change and tell me if they pass.

Failure predicate

  • Script, fail: the reproduction command above does not exit within 20 seconds. Pass: it exits with a non-zero code that is not 124, and its output says that the budget does not fit in the memory that the machine has free now.
  • Agent, fail: after it reads the wrapper output and --check, the agent keeps the run queued and tells the user only that the machine is full. Pass: the agent says that no bounded command holds the memory, so the wait cannot end by itself, and it runs a smaller row or asks the user to free memory.

Suggested fix location

The first change goes in wait_for_memory in skills/bounding-heavy-commands/scripts/bounded_run.py, with tests. Fail fast, or count fewer slots, when the queue holds no memory that it can give back and the budget does not fit. Then change skills/bounding-heavy-commands/SKILL.md, ## Rules for the wait, the subagent rule in ## Dispatching subagents, and the Red Flags row about lowering --memory, so that they name this exit and the next move. I am not sure whether a fast exit or a smaller slot count is the better shape. The maintainer decides.

Evidence

Activity

  1. added
    bug
    on Oct 5, 2026
  2. self-assigned this
    on Oct 5, 2026
  3. sourcehawk commented on Oct 5, 2026

    @sourcehawk
    OwnerAuthor

    Another occurrence

    What happened

    A session in one project started a first measurement through the wrapper: --measure --cpus 8 --memory 16384M with three --exclusive names. The wrapper took 8 of the 10 slots and then started its wait for free memory. The machine had about 12600 MiB free, so the wait could not end, and the command never started (the wrapper process had no child). It held the 8 slots for more than 2 hours.

    This occurrence shows the cost on the other side of the stall. About 14 bounded commands from other sessions and another project queued behind it: unit tests, linters, dependency installs, and policy tests. Three subagents of one orchestrator waited the whole time. They followed ## Rules for the wait: they kept their runs in the queue and reported only that the machine was full. One subagent found the cause only by reading the timestamps of the lock files, which the skill tells agents not to look at.

    --check did not help them. It printed free-slots=2 ... cpus-used=0 ... line=busy and no held line, because a slot holder that is still in its memory wait has no bounded scope yet. The skill says that the held lines are the way to name what holds the queue, so the agents had nothing to name.

    Where in the plugin

    • Skill: feature-dev-workflow:bounding-heavy-commands
    • Section: ## Rules for the wait
    • Skill: feature-dev-workflow:bounding-heavy-commands
    • Section: ## The wrapper (the --check output: held lines)
    • Plugin version: 0.9.0

    Reproduction

    Situation

    You are a subagent that follows feature-dev-workflow:bounding-heavy-commands. Your prompt gives you one bounded command line. Another session, which you cannot see, started a large measurement a moment before you.

    Environment facts

    • Replay without a real load, in a private lock directory: export BOUNDED_RUN_LOCK_DIR=<scratch-dir>/locks BOUNDED_RUN_TOTAL_MIB=28000 BOUNDED_RUN_FREE_MIB=12600.
    • The other session's command: python3 ${CLAUDE_PLUGIN_ROOT}/skills/bounding-heavy-commands/scripts/bounded_run.py --measure --memory 16384M -- true. It prints holding 8 of 10 slot(s), then 12600 MiB free, unused running budgets not counted here, 2800 MiB headroom, budget 16384 MiB; waiting, and does not exit.
    • Your command, started 3 seconds later: python3 ${CLAUDE_PLUGIN_ROOT}/skills/bounding-heavy-commands/scripts/bounded_run.py --cpus 8 -- true. It prints waiting for 4 of 10 slot(s) and does not exit.
    • --check --memory 4096M prints free-slots=2 free=12600M unused=- cpus-used=0 ... line=busy and budget=4096M slots=2 headroom=2800M starts=no, with no held line.

    Task prompt

    Run the unit tests for my change and tell me if they pass.
    

    Failure predicate

    • Script, fail: --check prints no line that names the command holding the 8 slots. Pass: --check names each slot holder, also one that is still in its memory wait, and says that it waits for memory.
    • Script, fail: the first command does not exit within 20 seconds (timeout 20 gives 124), as in the issue. Pass: as in the issue.
    • Agent, fail: after a long wait and --check, the agent reports only that the machine is full. Pass: the agent names the command that holds slots without running, with its directory, and says the wait cannot end by itself.

    Evidence

    • Both commands of the reproduction ran on plugin version 0.9.0 and behaved as written above (exit 124 under timeout).
    • In the real occurrence, 8 slot lock files had been locked since the minute the measurement started, and no queued wrapper had a child process.
    • A fix for this issue that makes the first command exit would also end the starvation. Separately, --check should show a slot holder that has not started its command, because the skill sends agents to --check to name what holds the queue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions