Skip to content

Run leaf-dev suite flake's copies in the background band - #5953

Merged
max-sixty merged 4 commits into
mainfrom
flake-machine-lock
Nov 15, 2026
Merged

max-sixty merged 4 commits into
mainfrom
flake-machine-lock

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

leaf-dev suite flake runs 18 copies of a selection, six at a time, to load the machine. On 14 November one session had six runs going at once, about 36 browser test copies on an 18-core Mac, and load average reached 340. This PR runs each copy in macOS's background band (taskpolicy -b), which gives the copies only the CPU and disk other work leaves, on the efficiency cores. Runs can then overlap freely: a busy machine lengthens a run rather than the run slowing everything else. The copies still load each other, and tests/AGENTS.md already records that this band reproduced ten nightly macOS failures that --cpu-throttle 8 missed.

Worth weighing: the band doesn't share out memory, and other platforms run as before. On a busy machine a run takes 10–15× longer, so a copy can hit one of the suite's 120 s deadlines, which the suite's rule counts as a deadline that is too tight. An earlier version made runs take turns through a machine-wide lock; Max asked why flake runs should take turns when other work runs in parallel, and nothing else justified it.

Max asked why the machine was busy; nobody else has read this. Tests: in dev/tests/process/test_flake.py each copy records its band, and the test fails with the band removed.

This was written by Claude Code on behalf of max-sixty

`leaf-dev flake` sizes its load as the only run on the machine, six copies at a time, but nothing stopped runs from overlapping. One session's four subagents had six runs going at once, about 36 browser test copies on an 18-core Mac at load average 340, and none of those runs measured the load flake is sized for. A run now holds a lock in the temporary directory while its copies run; it still snapshots and collects as soon as it starts.

Tests: dev/tests/process/test_flake.py passes; a probe of two runs started a second apart saw no overlap between their copies, and saw overlap with a separate lock per run.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lock's directory decides which runs take turns, and tempfile.gettempdir() follows each process's TMPDIR. The description already names the gap this leaves: a session whose TMPDIR differs from the others' stacks its copies on theirs, just as it did before this change. The same is true of a second local user, who also can't open a lock file another user created under a shared /tmp. Leaf already has a directory every checkout and session on the machine shares, whatever its TMPDIR: the state home. leaf-dev setup keeps its own machine-wide lock there (state_home() / "development-setup.lock"). Taking the lock there makes the guarantee unconditional, and the change stays the same size. The suggestions below do that. They call state_home() when the lock is taken rather than at import, so the test redirects it with XDG_STATE_HOME instead of patching a constant.

Comment thread dev/leaf_dev/commands/flake.py Resolved
Comment thread dev/leaf_dev/commands/flake.py Resolved
Comment thread dev/leaf_dev/commands/flake.py Resolved
Comment thread dev/leaf_dev/commands/flake.py Resolved
Comment thread dev/tests/process/test_flake.py Resolved
Review on #5953: `tempfile.gettempdir()` follows each process's `TMPDIR`, so a session whose `TMPDIR` differs from the others' would not take turns with them. The state home is shared by every checkout and session on the machine, and `leaf-dev setup` already keeps its machine-wide lock there. The test needs no override: the suite's `isolated_session` fixture gives it its own state home.

Tests: dev/tests/process/test_flake.py passes while another process holds the real lock; the two-run probe sees no overlap with a shared state home and overlap with separate ones.
leaf-agent
leaf-agent previously approved these changes Nov 14, 2026
max-sixty added a commit that referenced this pull request Nov 15, 2026
…galleries' duplicated code (#5965)

`leaf-dev` had 28 commands at one level, so a command's name had to say
its subject, and several didn't: `placements` showed only thread cards,
`pins` only comment pins, and the site's six commands were spread across
the list. This groups the commands by subject and by use, cuts every
caller over, and merges the evidence galleries' duplicated code.

```
leaf-dev
  bench  preview  probe  setup  stills  trace-server
  placement  pins  cards                         (cards was placements)
  journey    run  chart  session  snapshots      (journey, journey-chart, claude-code-session, thread-snapshots)
  logs       response-times  timeline
  suite      flake  bugback  profile             (profile was suite-profile)
  eval       run  report                         (eval, eval-report)
  site       build  verify  distribution  previews  demo  media
  generate   corpus  record-types
```

**The grouping.** A group gathers the commands a developer reaches for
together about one subject. The commands sessions run most, and across
subjects, stay at the top: over the last two weeks `probe` ran in 90 of
146 sessions, and `preview` and `stills` in 37 each. `compare` is now
`preview --base [REF]` (with `--authored`), the flag every other command
that runs two versions takes. `dev/AGENTS.md` states the rule.

**The mechanism.** A package in `leaf_dev/commands/` is a group of the
commands its modules are, found by name as modules always were.
- A module whose name starts with `_` is the group's own helper rather
than a command.
- Help lists the top-level commands and the groups in separate sections,
and each group's line names its commands.
- A command module defines the Click command of its command's name, so a
moved module keeps its function names and names its command in the
decorator.

Every import, module path, file path and invocation follows: CI, the wt
and pre-commit hooks, the Worker's bundle test, the skills and the docs.
Scratch paths follow too, for example `.tmp/cards` and
`.tmp/preview-base`.

**The merged code.** `leaf_dev/gallery.py` writes the pages that show
Leaf's drawing case by case, used by `placement pins`, `placement
cards`, `stills`, `journey snapshots` and `eval report`:
- `media` writes a capture into a page under its content name, which
pins and cards each did.
- `frame` cuts a crop box around a case's regions, the same box on every
arm. stills, snapshots and pins each did this.
- `marked` outlines and tints what a case is about, which stills, pins
and cards each did.
- `shot` builds an lf-shot pair, or a linked image where only one arm
ran, which pins, cards and eval report each did.
- `page` builds the page shell, which pins, cards and eval report each
did.

`browser.QUOTE_RANGE` replaces five JavaScript copies of finding quoted
words in a page.

Testing:
- Every command and group loads, and its `--help` runs.
- These pass: the dev model tier, the product model tests that import
moved modules, `test_evals`, the pins catalogue test, and the
send-placement and margin tests.
- Two dev tests fail on main too:
`test_preview_file_subscription_follows_atomic_replacements` and
`test_a_composed_part_refuses_an_authored_copy`.
- `stills --base` draws the four states whose JavaScript changed as
before.
- Both galleries run end to end.

Left for a follow-up: moving the journey and eval library modules under
their groups, moving `pins` onto `visits`, and the other duplicated
mechanisms a sweep of `leaf-dev` found (bin/leaf runners, arm Python,
media naming).

Open PRs that edit a moved module will need to follow the move: #5953
edits `flake.py`, now `suite/flake.py`, and #5197 edits
`suite_profile.py`, now `suite/profile.py`.

> _This was written by Claude Code on behalf of max-sixty_
…un at a time

The copies are load that exists only to compete for the machine. Making runs take turns
protected other work from stacked runs only, while any other parallel work could load
the machine just as much, and it held back runs that would otherwise share it. In
macOS's background band (`taskpolicy -b`) the copies get only the CPU and disk other
work leaves, on the efficiency cores, so runs can overlap freely and a busy machine
lengthens a run instead of the run slowing everything else. The band doesn't share
out memory.

The copies still compete with each other six at a time, and tests/AGENTS.md already
records that this band reproduced ten nightly macOS failures `--cpu-throttle 8` missed.
A slower copy reports the same result, because the suite's results don't depend on
execution speed. `leaf_dev.suite.run` takes the command to run pytest under; only
flake passes one.

Tests: the flake test now has each copy record its band, and asserts all four ran in the
background on macOS. It fails with the band removed (`'0000' == '1111'`).
@max-sixty max-sixty changed the title Make concurrent leaf-dev flake runs take turns Run leaf-dev suite flake's copies in the background band Nov 15, 2026
@max-sixty
max-sixty merged commit 3c66a3c into main Nov 15, 2026
5 checks passed
@max-sixty
max-sixty deleted the flake-machine-lock branch November 15, 2026 07:55
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.

2 participants