Net a resumed arm's cost of the start it resumes

This commit is contained in:
2026-11-17 03:44:53 +01:00
parent e42eb5b288
commit 1bc2ce89e7
2 changed files with 39 additions and 11 deletions
+22 -5
View File
@@ -12,7 +12,7 @@ best? Each case is an archived chunk of this repo, as in advisor_bench.py, whose
has compacted the session with `/compact`, whose stream it saves as <name>.compact.jsonl. The brief arm starts a
session that has the item and handoff-brief-prompt.md, and no transcript.
- `grade` is advisor_bench.py's, over these cases. `summary` counts an arm's cost and seconds from its own runs,
the compaction included, and leaves out the start, which the arms share.
the compaction included, and leaves out the start, which the arms share (`outcome`).
Run each arm of each case once; the table shows a direction, not a significance.
"""
import concurrent.futures
@@ -132,11 +132,28 @@ def run(work, name):
return f"{name}: ran"
def results(stream):
"""The result lines of a claude stream. A resumed run may open with one that holds no work, and a background task's notification adds one."""
found = []
for line in stream.read_text().splitlines():
try:
entry = json.loads(line)
except ValueError:
continue
if isinstance(entry, dict) and entry.get("type") == "result":
found.append(entry)
return found
def outcome(work, name):
"""The cost and seconds of an arm's run: its STRONG stream's, plus its compaction's where it made one."""
streams = [stream for stream in (work / f"{name}.compact.jsonl", work / f"{name}.jsonl") if stream.exists()]
results = [advisor_bench.read_result(stream.read_text().splitlines()) for stream in streams]
return {"cost": sum(result.cost for result in results), "seconds": sum(result.seconds for result in results)}
"""The cost and seconds of an arm's run, its compaction included. A resumed session's cost counts from the session's start, so the start's cost comes off it."""
case, arm, number = advisor_bench.split_name(name)
ran = results(work / f"{name}.jsonl")
if not ran or ran[-1].get("is_error"):
raise ValueError(f"the run ended in an error: {ran[-1].get('result')}" if ran else "the stream has no result line")
compacted = results(work / f"{name}.compact.jsonl") if arm == "compact" else []
before = 0 if arm == "brief" else results(work / f"{case}-start-{number}.jsonl")[-1]["total_cost_usd"]
return {"cost": ran[-1]["total_cost_usd"] - before, "seconds": sum(entry["duration_ms"] for entry in [*compacted, *ran]) / 1000}
def rows_of(work):