Skip to content

Run long commands so that waiting ends with the command (for discussion) - #56

Open
anakanemison wants to merge 1 commit into
mschaller/d3-narrow-the-stopfrom
mschaller/d4-long-commands
Open

anakanemison wants to merge 1 commit into
mschaller/d3-narrow-the-stopfrom
mschaller/d4-long-commands

Conversation

@anakanemison

@anakanemison anakanemison commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

A new "Long commands" paragraph: run a build in the foreground with a long enough timeout where the command tool allows; otherwise in the background, waiting on kill -0 of the saved PID in short slices. Never wait with pgrep -f, which matches its own command line, and run built programs with </dev/null and a timeout.

With an earlier wording ("run in the background and poll"), ten any2bazel-lab runs spent 232 minutes waiting after the work had ended, including a 74-minute self-matching pgrep -f loop. With this wording, in six re-runs of the same projects, that fell from 153 minutes to 6, and QGIS took 121 minutes instead of 206. For discussion: how to wait is partly a property of the agent's tools.

Stacked on #55 (tracking issue: #35). pytest tests/: 186 passed (132 on main). Lab proposal: P12.

🤖 Generated with Claude Code

Agents lose time to commands that block: a built program waiting on stdin,
a Bazel command queued behind another on the same server lock, and above
all waiting on a long build. Large projects make each more expensive, and
done now requires a clean build from a fresh output base.

The procedure's working-directory note gains a "Long commands" paragraph:
- Run a build or test suite in the foreground, with a timeout long enough
  for it, when the command tool allows that long; it returns the moment the
  command ends.
- If it may take longer, start it in the background with its log and PID
  outside the workspace (so the log is not migrated), and wait with a loop
  on `kill -0` of the saved PID, in 15-second slices, which ends as soon as
  the command does.
- Never wait with `pgrep -f <name>`: the waiting command's own command line
  contains the name, so it always finds itself. Don't sleep a fixed time on
  a guess either.
- A second Bazel command in the same workspace waits for the first; run
  built programs with </dev/null and a timeout.
It does not state the command tool's time limit: that is 10 minutes by
default in Claude Code, and settings raise it.

Measured in any2bazel-lab, on an earlier wording of this change ("run builds
and test suites that may take minutes in the background and poll them"):
agents followed it in eight of ten runs and waited badly. One waited 74
minutes on `while pgrep -f "yb_build.sh"`, which matched its own command
line, for a configure that had finished in 16 seconds. Four others spent 8
to 133 minutes in fixed sleeps of up to 700 s on builds that had already
finished. In all, 232 of the ten runs' minutes were commands still waiting
after their work had ended.

With the wording above, in six re-runs of the same projects, no agent
waited on `pgrep -f`, no sleep was longer than 60 s, and no waiting command
outlasted its work by more than 14 seconds. Waiting after work fell from 153
minutes to 6, and the QGIS migration took 121 minutes instead of 206. The
time-limit sentence was revised after those runs.

This is a proposal for discussion: how an agent should wait on long
commands is partly a property of the agent's tools, which the maintainers
may prefer to leave to them.

Lab-Proposal: P12
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant