Answer principles round 2: 0 🔴, 2 🟡 (0 misread); workflow-bench hands its effects in as arguments, and no Python file of the repo patches a global
CI / tests (pull_request) Successful in 3m46s
CI / tests (pull_request) Successful in 3m46s
This commit is contained in:
@@ -18,12 +18,15 @@ Run each arm of each case once; the table shows a direction, not a significance.
|
||||
"""
|
||||
import collections
|
||||
import concurrent.futures
|
||||
import dataclasses
|
||||
import functools
|
||||
import json
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
import advisor_bench
|
||||
@@ -54,6 +57,18 @@ START_BUDGET = 0.36
|
||||
CLAUDE_FLAGS = ["--setting-sources", "project", "--permission-mode", "bypassPermissions", "--output-format", "stream-json", "--verbose"]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Handoff:
|
||||
"""What this bench's steps act on, which the script's entry point hands them."""
|
||||
bench: advisor_bench.Bench
|
||||
# Dollars WEAK may spend before the handoff.
|
||||
budget: float
|
||||
# Where Claude Code keeps each session's transcript.
|
||||
projects: pathlib.Path
|
||||
# Makes the ID of the session `start` opens, as uuid.uuid4 does.
|
||||
new_session: typing.Callable
|
||||
|
||||
|
||||
def stopped_at_budget(lines):
|
||||
"""Whether a claude stream's first result line, the worker's own, says the run stopped at --max-budget-usd."""
|
||||
for line in lines:
|
||||
@@ -66,34 +81,35 @@ def stopped_at_budget(lines):
|
||||
return False
|
||||
|
||||
|
||||
def run_prompt(case):
|
||||
def run_prompt(bench, case):
|
||||
"""advisor_bench's prompt for the case's item, as the item's text stood at the start commit."""
|
||||
base = CASES[case][0]
|
||||
text = advisor_bench.item_text(advisor_bench.git(advisor_bench.REPO, "show", f"{base}:todo.md"), case)
|
||||
base = bench.cases[case][0]
|
||||
text = advisor_bench.item_text(advisor_bench.git(bench.repo, "show", f"{base}:todo.md"), case)
|
||||
return (BENCH / "advisor-run-prompt.md").read_text().format(base=base, item=case, text=text)
|
||||
|
||||
|
||||
def claude(prompt, flags, clone, stream):
|
||||
def claude(process, prompt, flags, clone, stream):
|
||||
with stream.open("w") as out:
|
||||
subprocess.run(["claude", "-p", prompt, *flags, *CLAUDE_FLAGS], cwd=clone, stdin=subprocess.DEVNULL, stdout=out, stderr=subprocess.STDOUT)
|
||||
process(["claude", "-p", prompt, *flags, *CLAUDE_FLAGS], cwd=clone, stdin=subprocess.DEVNULL, stdout=out, stderr=subprocess.STDOUT)
|
||||
|
||||
|
||||
def start(work, name):
|
||||
def start(handoff, work, name):
|
||||
"""WEAK's capped run of <case>-<n>, and the tree and session it leaves the arms; the files are in the module docstring."""
|
||||
case, number = name.split("-")
|
||||
base = CASES[case][0]
|
||||
bench = handoff.bench
|
||||
base = bench.cases[case][0]
|
||||
clone, saved = work / name, work / f"{case}-start-{number}"
|
||||
if clone.exists():
|
||||
raise ValueError(f"{name} already started: remove {clone}")
|
||||
advisor_bench.fresh_clone(base, clone)
|
||||
session = str(uuid.uuid4())
|
||||
advisor_bench.fresh_clone(bench.repo, base, clone)
|
||||
session = str(handoff.new_session())
|
||||
stream = saved.with_suffix(".jsonl")
|
||||
claude(run_prompt(case), [*WEAK.flags(), "--session-id", session, "--max-budget-usd", str(START_BUDGET)], clone, stream)
|
||||
claude(bench.process, run_prompt(bench, case), [*WEAK.flags(), "--session-id", session, "--max-budget-usd", str(handoff.budget)], clone, stream)
|
||||
if not stopped_at_budget(stream.read_text().splitlines()):
|
||||
raise ValueError("the weak worker finished within its budget, or its run failed, so there is no handoff to bench")
|
||||
transcripts = list(CLAUDE_PROJECTS.glob(f"*/{session}.jsonl"))
|
||||
transcripts = list(handoff.projects.glob(f"*/{session}.jsonl"))
|
||||
if len(transcripts) != 1:
|
||||
raise ValueError(f"expected one transcript of session {session} under {CLAUDE_PROJECTS}, found {len(transcripts)}")
|
||||
raise ValueError(f"expected one transcript of session {session} under {handoff.projects}, found {len(transcripts)}")
|
||||
shutil.copy(transcripts[0], saved.with_suffix(".session.jsonl"))
|
||||
saved.with_suffix(".session").write_text(str(transcripts[0]))
|
||||
# The worker may have committed against the bench rules, so the arms get its whole change since base, uncommitted.
|
||||
@@ -104,9 +120,10 @@ def start(work, name):
|
||||
return f"{name}: started"
|
||||
|
||||
|
||||
def run(work, name):
|
||||
def run(handoff, work, name):
|
||||
"""STRONG's run of one arm, <case>-<arm>-<n>, from the tree and session `start` left."""
|
||||
case, arm, number = advisor_bench.split_name(name)
|
||||
bench = handoff.bench
|
||||
if arm not in ARMS:
|
||||
raise ValueError(f"the arm {arm!r} is none of {ARMS}")
|
||||
clone, saved = work / f"{case}-{number}", work / f"{case}-start-{number}"
|
||||
@@ -122,15 +139,15 @@ def run(work, name):
|
||||
shutil.copy(saved.with_suffix(".session.jsonl"), transcript)
|
||||
resumed = ["--resume", transcript.stem]
|
||||
if arm == "compact":
|
||||
claude("/compact", [*WEAK.flags(), *resumed], clone, work / f"{name}.compact.jsonl")
|
||||
claude(bench.process, "/compact", [*WEAK.flags(), *resumed], clone, work / f"{name}.compact.jsonl")
|
||||
finished(work / f"{name}.compact.jsonl")
|
||||
if arm == "brief":
|
||||
claude(run_prompt(case) + "\n" + (BENCH / "handoff-brief-prompt.md").read_text(), [*STRONG.flags(), "--no-session-persistence"], clone, stream)
|
||||
claude(bench.process, run_prompt(bench, case) + "\n" + (BENCH / "handoff-brief-prompt.md").read_text(), [*STRONG.flags(), "--no-session-persistence"], clone, stream)
|
||||
else:
|
||||
prompt = (BENCH / "handoff-resume-prompt.md").read_text().format(rung=f"{STRONG.model} at {STRONG.effort} effort")
|
||||
claude(prompt, [*STRONG.flags(), *resumed], clone, stream)
|
||||
claude(bench.process, prompt, [*STRONG.flags(), *resumed], clone, stream)
|
||||
outcome(work, name)
|
||||
advisor_bench.save_change(work, name, clone, CASES[case])
|
||||
advisor_bench.save_change(bench, work, name, clone, bench.cases[case])
|
||||
return f"{name}: ran"
|
||||
|
||||
|
||||
@@ -185,16 +202,21 @@ def summary(rows):
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def main(argv):
|
||||
def steps_of(handoff):
|
||||
"""The steps main runs by name, each on handoff; the grade is advisor_bench's, over handoff's cases."""
|
||||
return {"start": functools.partial(start, handoff), "run": functools.partial(run, handoff), "grade": functools.partial(advisor_bench.grade, handoff.bench)}
|
||||
|
||||
|
||||
def main(argv, steps, say):
|
||||
"""Runs the step argv names on each run it names, and hands say each result line; or hands say the summary."""
|
||||
work, step, names = pathlib.Path(argv[0]), argv[1], argv[2:]
|
||||
if step == "summary":
|
||||
print(summary(rows_of(work)))
|
||||
say(summary(rows_of(work)))
|
||||
return
|
||||
steps = {"start": start, "run": run, "grade": lambda work, name: advisor_bench.grade(work, name, CASES)}
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
|
||||
for result in pool.map(lambda name: advisor_bench.attempted(steps[step], work, name), names):
|
||||
print(result, flush=True)
|
||||
say(result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
main(sys.argv[1:], steps_of(Handoff(advisor_bench.Bench(advisor_bench.REPO, CASES, subprocess.run), START_BUDGET, CLAUDE_PROJECTS, uuid.uuid4)), functools.partial(print, flush=True))
|
||||
|
||||
Reference in New Issue
Block a user