Answer architecture round 1: 2 🔴, 8 🟡 (0 misread); split task-bench's benched into phases and its table into one column list, parse each stream once, move do-epic's parking out with pure move and news decisions, share the round summaries, rename scoring_due, and file the version question as item 517
CI / tests (pull_request) Successful in 5m2s
CI / tests (pull_request) Successful in 5m2s
This commit is contained in:
+38
-27
@@ -3,18 +3,15 @@ import dataclasses
|
||||
import statistics
|
||||
import typing
|
||||
|
||||
from claude_code.entries import Entry, json_object, tool_calls, ToolCall
|
||||
from failure import Failure
|
||||
from claude_code.entries import json_object, parse_entry, tool_calls, ToolCall
|
||||
from task_bench.runs import HOME, WORK
|
||||
from reading_cost.measure import reads_of
|
||||
from claude_code.tokens import Tokens, tokens_of
|
||||
|
||||
# Where each run's container mounts its copy of the code, and its home folder: the paths in a run's stream start there.
|
||||
WORK = "/work"
|
||||
HOME = "/tmp"
|
||||
# The tools that read or search without a shell. A Bash call counts where `reads_of` finds a file it reads.
|
||||
READING_TOOLS = frozenset({"Glob", "Grep", "Read"})
|
||||
SIDES = ("base", "head")
|
||||
HEADER = ["| Bug | Side | Passed | Input | Cache write | Cache read | Output | Turns | Wall, s | Reads |", "|---|---|---|---|---|---|---|---|---|---|"]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -30,17 +27,42 @@ class Figures:
|
||||
|
||||
|
||||
class Result(typing.NamedTuple):
|
||||
"""One run of a task at a side. figures is None where its claude ended without a result, as when it ran out of time."""
|
||||
"""One run of a task at a side. figures is None where its claude ended without a result, as when it ran out of time. entries
|
||||
holds what its stream tells, for the digest."""
|
||||
|
||||
task: int
|
||||
side: str
|
||||
run: int
|
||||
passed: bool
|
||||
figures: Figures | None
|
||||
entries: typing.Sequence[Entry] = ()
|
||||
|
||||
|
||||
def figures(stream: bytes, bug_file: str) -> Figures | None | Failure:
|
||||
"""The figures of the run whose claude printed stream, with bug_file the bug's file as the run's container names it.
|
||||
class Column(typing.NamedTuple):
|
||||
"""A figure the table shows: its heading, its value in one run, None where the run has none, and whether the head's change
|
||||
in it is a share of the base or a count."""
|
||||
|
||||
heading: str
|
||||
value: typing.Callable[[Figures], float | None]
|
||||
change: typing.Literal["share", "count"]
|
||||
|
||||
|
||||
# Turns and reads are small counts, where a share misleads.
|
||||
COLUMNS = (
|
||||
Column("Input", lambda found: found.tokens.input, "share"),
|
||||
Column("Cache write", lambda found: found.tokens.write_5m + found.tokens.write_1h, "share"),
|
||||
Column("Cache read", lambda found: found.tokens.read, "share"),
|
||||
Column("Output", lambda found: found.tokens.output, "share"),
|
||||
Column("Turns", lambda found: found.turns, "count"),
|
||||
Column("Wall, s", lambda found: found.seconds, "share"),
|
||||
Column("Reads", lambda found: found.reads, "count"),
|
||||
)
|
||||
HEADINGS = ["Bug", "Side", "Passed", *(column.heading for column in COLUMNS)]
|
||||
|
||||
|
||||
def figures(stream: bytes, entries: typing.Sequence[Entry], bug_file: str) -> Figures | None | Failure:
|
||||
"""The figures of the run whose claude printed stream, which parses into entries, with bug_file the bug's file as the run's
|
||||
container names it.
|
||||
|
||||
None where the stream holds no result. A Failure where the API refused the run, as on a token it doesn't take: such a run
|
||||
doesn't measure anything, and every later run would end the same."""
|
||||
@@ -48,11 +70,11 @@ def figures(stream: bytes, bug_file: str) -> Figures | None | Failure:
|
||||
result = next((event for event in reversed(events) if event.get("type") == "result"), None)
|
||||
if result is None:
|
||||
return None
|
||||
# Claude Code retries a failed API call itself, on 429, 529 and 5xx, up to CLAUDE_CODE_MAX_RETRIES times, so its retries didn't clear this one.
|
||||
if result.get("api_error_status") or result.get("terminal_reason") == "api_error":
|
||||
return Failure(f"claude could not use the API: {result.get('result')}")
|
||||
# {"type": "system", "subtype": "init", "model": "claude-haiku-5-5", "claude_code_version": "2.1.330", ...}
|
||||
init = next((event for event in events if event.get("subtype") == "init"), {})
|
||||
entries = [entry for line in stream.splitlines() if (entry := parse_entry(line))]
|
||||
calls = [call for _, call in tool_calls(entries)]
|
||||
return Figures(str(init.get("claude_code_version", "")), str(init.get("model", "")), tokens_of(result.get("usage")), int(result.get("num_turns") or 0), (result.get("duration_ms") or 0) / 1000, reads_before(calls, bug_file))
|
||||
|
||||
@@ -73,27 +95,18 @@ def table(results: list[Result], tasks: dict[int, str]) -> list[str]:
|
||||
sides = {(task, side): [result for result in results if (result.task, result.side) == (task, side)] for task in tasks for side in SIDES}
|
||||
rows = [row(f"{task}: {tasks[task]}", side, sides[task, side]) for task in sorted(tasks) for side in SIDES]
|
||||
base, head = ([result for result in results if result.side == side] for side in SIDES)
|
||||
return [*HEADER, *rows, row("All", "base", base), row("All", "head", head), change([(sides[task, "base"], sides[task, "head"]) for task in sorted(tasks)])]
|
||||
return [cells(HEADINGS), cells(["---"] * len(HEADINGS)).replace(" ", ""), *rows, row("All", "base", base), row("All", "head", head), change([(sides[task, "base"], sides[task, "head"]) for task in sorted(tasks)])]
|
||||
|
||||
|
||||
def medians(results: list[Result]) -> list[float | None]:
|
||||
"""Input, cache write, cache read, output, turns, wall time and reads."""
|
||||
measured = [result.figures for result in results if result.figures]
|
||||
columns: list[list[float]] = [
|
||||
[found.tokens.input for found in measured],
|
||||
[found.tokens.write_5m + found.tokens.write_1h for found in measured],
|
||||
[found.tokens.read for found in measured],
|
||||
[found.tokens.output for found in measured],
|
||||
[found.turns for found in measured],
|
||||
[found.seconds for found in measured],
|
||||
[found.reads for found in measured if found.reads is not None],
|
||||
]
|
||||
return [statistics.median(column) if column else None for column in columns]
|
||||
def median(column: Column, results: list[Result]) -> float | None:
|
||||
"""The column's median over the runs that have a value in it."""
|
||||
values = [value for result in results if result.figures and (value := column.value(result.figures)) is not None]
|
||||
return statistics.median(values) if values else None
|
||||
|
||||
|
||||
def row(task: str, side: str, results: list[Result]) -> str:
|
||||
passed = f"{sum(result.passed for result in results)}/{len(results)}"
|
||||
return cells([task, side, passed, *("-" if median is None else number(median) for median in medians(results))])
|
||||
return cells([task, side, passed, *("-" if (found := median(column, results)) is None else number(found) for column in COLUMNS)])
|
||||
|
||||
|
||||
def change(bugs: list[tuple[list[Result], list[Result]]]) -> str:
|
||||
@@ -102,9 +115,7 @@ def change(bugs: list[tuple[list[Result], list[Result]]]) -> str:
|
||||
as a share of the base median for tokens and wall time, and as a count for turns and reads. This isn't the change from the All
|
||||
base row to the All head row: those medians land in whichever bug's runs sit in the middle of the pooled costs."""
|
||||
passed = sum(result.passed for _, head in bugs for result in head) - sum(result.passed for base, _ in bugs for result in base)
|
||||
pairs = [list(zip(medians(base), medians(head))) for base, head in bugs]
|
||||
# Turns and reads are small counts, where a share misleads.
|
||||
means = [mean_change([pair[column] for pair in pairs], share=column not in (4, 6)) for column in range(7)]
|
||||
means = [mean_change([(median(column, base), median(column, head)) for base, head in bugs], share=column.change == "share") for column in COLUMNS]
|
||||
return cells(["All", "change", number(passed, signed=True), *(found or "-" for found in means)])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user