Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions bench/oneroad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,66 @@ Repeatability rules, all of them load-bearing:
green is reported as a failure with its other numbers shown but struck through,
because the fastest way to a green suite is always to delete the test.

## Measuring the script tool

`codeaf-script-flash` and `codeaf-script-crew` are `codeaf-new-flash` and
`codeaf-new-crew` with `CODEAF_TASK_SCRIPT=on` in codeaf's environment and
nothing else changed, so each pair measures the task worker's `script` tool
alone (internal/session/tool_script.go). Run the pairs on the same tasks and
seeds:

```sh
bench/oneroad/wave.sh <task> codeaf-new-crew codeaf-script-crew
# for example: NEW_BIN=$PWD/bin/codeaf bench/oneroad/wave.sh 21 codeaf-new-crew codeaf-script-crew
```

Every codeaf cell's `meta.json` carries, and `collect.py` puts in
`results.csv`:

- `steps`, `script_steps`, `script_calls`: the workers' tool calls, their
script calls and the calls those scripts made, read from plan-run
trajectories and chat-task transcripts alike (`lib/script_use.py`). Read
these first: a script arm whose workers wrote no scripts measured nothing
about the tool, and its differences are noise.
- `worker_usd`, `worker_tokens_in`, `worker_tokens_out`,
`worker_tokens_cache`, `worker_model_calls`: every model call a task worker
made, from the profile's usage ledger (`v3/usage.jsonl`, the rows on the
worker seat or naming a task: a plan run's workers carry only the seat). This is where the tool's effect on spend shows; compare it between
the pair. The plan store's spend rows are not used: they hold only a plan
run's workers, and a chat task's spend is not in them.
- `tokens_in`, `tokens_out`, `tokens_cache`: the conversation's own model
calls (`lib/road.py`), the same names the peer arms' tokens use. They do
not include the workers.

`cost_usd` prefers the conversation's call lines when it has them, so it can
leave the workers' bill out; for this comparison read `worker_usd` beside it.
Then compare outcome, tests after and `wall_s_active`. A run calls live models
on the key in `OPENROUTER_API_KEY` and is billed.

### What the pilots found

Four pilot cells on `batch` (2026-11-18) wrote one script between them, and
it failed: DeepSeek v4 flash read the tool as Node.js, and Sonnet 5.5 did its
reading in `bash` instead, chaining commands in one call. A grid here would
measure that the tool goes unused. `bench/scriptbench` measures the case it
is for, and found the saving there.

### The chat-side arm

`codeaf-chatscript-flash` and `codeaf-chatscript-crew` are the new arms with
`CODEAF_CHAT_SCRIPT=on`: the same tool on the conversation's own belt, the
workers untouched. Run them beside `codeaf-new-*` in the same wave:

```sh
NEW_BIN=... bench/oneroad/wave.sh batch codeaf-new-crew codeaf-chatscript-crew
```

Read `chat_script_steps` and `chat_script_calls` first, for the reason the
worker arm's counts come first. The effect shows in the conversation's own
`tokens_in`, `tokens_out` and `tokens_cache`, beside `worker_*` and `road`:
a chat that can make many calls in one step may do work itself that it would
otherwise have handed to a task, and that is a change of road, not a saving.

## Reading a comparison honestly

- Quote wall clock only beside the verdict. A harness that finishes in half the
Expand Down
141 changes: 123 additions & 18 deletions bench/oneroad/cell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#
# Usage: cell.sh <arm> <task>
# arm codeaf-new-flash | codeaf-new-crew | codeaf-old-flash | pi | opencode
# | codeaf-script-flash | codeaf-script-crew (the new arms with
# CODEAF_TASK_SCRIPT=on, the script tool's measurement)
# | codeaf-chatscript-flash | codeaf-chatscript-crew (the new arms
# with CODEAF_CHAT_SCRIPT=on, the tool on the chat's own belt)
# task 20 | 21 | 22 | 23 | batch
#
# THE PROTOCOL POINT (bench/oneroad/README.md): the codeaf arms are driven
Expand All @@ -24,6 +28,17 @@ SEED="${SEED:-s1}"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ONEROAD="$ROOT"
source "$ONEROAD/lib/corpus.sh"
source "$ONEROAD/lib/loadavg.sh"

# CELL_ENV is the whole environment a harness under test is started with, on
# top of env -i: where programs are, who and where the user is, the locale and
# the temp folder (codeaf names its sockets there). Nothing else from the shell
# that launched the bench — tokens, database URLs, cloud keys — reaches a
# harness, which runs unattended on text from a public repository.
# CELL_ENV_ARGS is for a command run from here; CELL_ENV is the same list
# quoted for the command line tmux hands its own shell.
CELL_ENV_ARGS=("PATH=$PATH" "USER=${USER:-}" "LOGNAME=${LOGNAME:-}" "LANG=${LANG:-en_US.UTF-8}" "SHELL=${SHELL:-/bin/sh}" "TMPDIR=${TMPDIR:-/tmp}")
CELL_ENV="$(printf '%q ' "${CELL_ENV_ARGS[@]}")"

ISSUES="${ISSUES:-20 21 22 23}"
MODEL="${MODEL:-deepseek/deepseek-v4-flash}"
Expand All @@ -43,7 +58,12 @@ CELL_SECONDS="${CELL_SECONDS:-3600}"
SILENCE_SECONDS="${SILENCE_SECONDS:-180}"
POLL="${POLL:-10}"

CELL="$ONEROAD/results/$ARM-$TASK-$SEED"
# THREE OVERRIDES LET ANOTHER BENCHMARK DRIVE THIS CELL (bench/scriptbench):
# RESULTS is where its cells go, PROMPT_FILE is its prompt in place of an
# issue's, and SKIP_SUITE=1 leaves out the test suite for a task whose answer
# is checked by something else. Unset, the one-road cell is unchanged.
RESULTS="${RESULTS:-$ONEROAD/results}"
CELL="$RESULTS/$ARM-$TASK-$SEED"
rm -rf "$CELL"; mkdir -p "$CELL"
WORK="$CELL/work"; mkdir -p "$WORK"
DIR="$WORK/$SLUG"
Expand All @@ -53,7 +73,9 @@ say() { printf '[%s] %s\n' "$(date +%H:%M:%S)" "$*" | tee -a "$CELL/cell.log"; }

# ── the prompt ──────────────────────────────────────────────────────────────
say "$ARM/$TASK: fetching issue text"
if [ "$TASK" = "batch" ]; then
if [ -n "${PROMPT_FILE:-}" ]; then
PROMPT="$(cat "$PROMPT_FILE")" || { say "could not read $PROMPT_FILE"; exit 1; }
elif [ "$TASK" = "batch" ]; then
PROMPT="$(batch_prompt)" || { say "could not read the issues"; exit 1; }
else
PROMPT="$(issue_prompt "$TASK")" || { say "could not read issue #$TASK"; exit 1; }
Expand All @@ -64,20 +86,38 @@ printf '%s' "$PROMPT" > "$CELL/prompt.txt"
say "$ARM/$TASK: cloning at $BASE_COMMIT"
COMMIT="$(fresh_clone "$DIR")" || { say "clone failed"; exit 1; }
echo "$COMMIT" > "$CELL/base-commit"
setup_python "$DIR"
BEFORE="$(run_suite "$DIR" "$CELL/pytest-before.log")"
BEFORE="skipped"
if [ "${SKIP_SUITE:-0}" != "1" ]; then
setup_python "$DIR"
BEFORE="$(run_suite "$DIR" "$CELL/pytest-before.log")"
fi
say "$ARM/$TASK: suite before = $BEFORE (passed/failed)"

# The load this cell started under. Arms share one machine by design (the
# same-wave rule is what keeps provider weather fair), so the contention has to
# be on the record rather than argued about afterwards.
cut -d' ' -f1-3 /proc/loadavg > "$CELL/loadavg-before"
loadavg > "$CELL/loadavg-before"

# ── the codeaf arms: the real TUI, over tmux ────────────────────────────────
run_codeaf() {
local binary="$1" all_flash="$2"
local profile="$CELL/profile" cellhome="$CELL/home"
mkdir -p "$profile" "$cellhome"
local binary="$1" all_flash="$2" switches=""
# THE SCRIPT ARMS DIFFER BY ONE VARIABLE. A third argument of `script` arms the
# task worker's script tool (internal/session/tool_script.go) and changes
# nothing else, so a script arm beside its new arm measures the tool alone.
[ "${3:-}" = "script" ] && switches="CODEAF_TASK_SCRIPT=on"
# AND THE CHAT'S ARM, on the same terms: `chatscript` arms the tool on the
# conversation's own belt and leaves the workers as the new arm has them.
[ "${3:-}" = "chatscript" ] && switches="CODEAF_CHAT_SCRIPT=on"
# THE PROFILE LIVES AT A SHORT PATH WHILE CODEAF RUNS. codeaf names a socket
# inside it, and a socket path has a 103-byte limit on macOS: under results/
# the name is too long, codeaf runs the conversation in its own terminal
# instead, and the cell measures a codeaf nobody runs. $CELL/profile points at
# it while the cell runs, and the folder moves back when it ends.
local profile cellhome="$CELL/home"
profile="$(mktemp -d /tmp/oneroad.XXXXXX)" || return 92
RUN_BIN="$binary"
ln -s "$profile" "$CELL/profile"
mkdir -p "$cellhome"

# The disposable brain. This is the same shape the retired UX harness built:
# HOME moves as well as the profile, so anything that does not yet honour the profile override lands
Expand Down Expand Up @@ -117,10 +157,24 @@ PY
# `pi -p` and `opencode run --auto` take on the other arms.
# --model pins the conversation's own model; the tier rows above (or their
# absence) decide everything the machine calls on its own behalf.
# THE CELL'S CODEAF SEES ONLY WHAT IT NEEDS. It runs --yolo on a public
# issue's words, and a worker that runs `env` reads whatever it was handed,
# so it starts from an empty environment (env -i) plus CELL_ENV, never the
# shell that launched the bench. The provider key is NOT among them: it is in
# the profile's config.json above, and on a command line it would be readable
# by anything that lists processes.
#
# AND NO PROCESS ABOVE IT KEEPS THE SHELL'S ENVIRONMENT EITHER. tmux runs
# its command under the server's shell, whose environment is the one that
# started the server; left alive as codeaf's parent, `ps eww` would read it
# back. So that shell `exec`s straight into env -i, and the steps that must
# follow codeaf run from a launcher under the clean environment.
local launch="$CELL/launch.sh"
printf 'cd %q || exit 1\n%q chat --yolo --model %q\necho codeaf-EXITED\nsleep 60\n' \
"$DIR" "$binary" "$MODEL" > "$launch"
tmux new-session -d -s "$SESSION_NAME" -x 200 -y 50 \
"cd '$DIR' && env HOME='$cellhome' CODEAF_HOME='$profile' CODEAF_PROFILE_DIR='$profile' \
OPENROUTER_API_KEY='$OPENROUTER_API_KEY' TERM=xterm-256color \
'$binary' chat --yolo --model '$MODEL'; echo codeaf-EXITED; sleep 60"
"exec env -i $CELL_ENV HOME='$cellhome' CODEAF_HOME='$profile' CODEAF_PROFILE_DIR='$profile' \
TERM=xterm-256color $switches /bin/sh '$launch'"

# The first frame. A surface that never drew one has nothing to type into, and
# the pane is kept so the reason is legible rather than inferred.
Expand Down Expand Up @@ -181,7 +235,7 @@ PY
echo wall > "$CELL/settle_reason"
return 124
fi
now="$(find "$sessroot" -type f ! -name presence.json -printf '%s %T@ %p\n' 2>/dev/null | sort | md5sum)"
now="$(python3 "$ONEROAD/lib/storeprint.py" "$sessroot" 2>/dev/null | cksum)"
screen="$(tmux capture-pane -t "$SESSION_NAME" -p 2>/dev/null)"
printf '%s\n' "$screen" > "$CELL/tmux-live.txt"
# THE STORE IS THE SIGNAL AND THE SCREEN IS ONLY A VETO ON "working".
Expand All @@ -190,6 +244,21 @@ PY
# had been silent for seven minutes was still being called busy and would
# have run to the wall and been recorded DNF. A liveness check must key on
# something that STOPS when the work stops; the footer's hint does not.
# A CELL STOPPED AT AN APPROVAL IS BLOCKED, NOT IDLE. --yolo still asks
# before the commands internal/approval's floor names (an absolute
# recursive delete among them), nobody here will answer, and the store
# goes quiet while the prompt waits — which the idle rule below would
# record as a cell that finished.
if printf '%s' "$screen" | grep -q 'needs your ok'; then
say "$ARM/$TASK: blocked at an approval prompt at ${elapsed}s"
printf '%s\n' "$screen" | grep -A2 'needs your ok' | head -3 > "$CELL/approval.txt"
tmux capture-pane -t "$SESSION_NAME" -p > "$CELL/tmux-final.txt"
tmux capture-pane -t "$SESSION_NAME" -p -S -4000 > "$CELL/tmux-scrollback.txt"
tmux kill-session -t "$SESSION_NAME" 2>/dev/null
echo BLOCKED > "$CELL/outcome"
echo approval > "$CELL/settle_reason"
return 0
fi
if [ "$now" = "$last" ]; then
quiet=$((quiet + POLL))
else
Expand Down Expand Up @@ -244,7 +313,8 @@ run_peer() {
pi)
# bench/run.sh's recorded invocation, checked against pi 0.84.1: -p is
# still non-interactive print mode and --provider/--model still pin.
(cd "$DIR" && timeout "$CELL_SECONDS" "$PI_BIN" -p \
(cd "$DIR" && env -i "${CELL_ENV_ARGS[@]}" HOME="$HOME" OPENROUTER_API_KEY="$OPENROUTER_API_KEY" \
timeout "$CELL_SECONDS" "$PI_BIN" -p \
--provider openrouter --model "$MODEL" "$PROMPT")
;;
opencode)
Expand All @@ -253,7 +323,8 @@ run_peer() {
# stops at the first permission prompt with nobody there to answer and the
# cell measures a dialog rather than a harness. --auto is this arm's
# equivalent of codeaf's --yolo and pi's -p.
(cd "$DIR" && timeout "$CELL_SECONDS" "$OPENCODE_BIN" run --auto \
(cd "$DIR" && env -i "${CELL_ENV_ARGS[@]}" HOME="$HOME" OPENROUTER_API_KEY="$OPENROUTER_API_KEY" \
timeout "$CELL_SECONDS" "$OPENCODE_BIN" run --auto \
-m "openrouter/$MODEL" "$PROMPT")
;;
esac
Expand All @@ -264,6 +335,10 @@ STARTED=$(date +%s)
case "$ARM" in
codeaf-new-flash) run_codeaf "$NEW_BIN" 1; CODE=$? ;;
codeaf-new-crew) run_codeaf "$NEW_BIN" 0; CODE=$? ;;
codeaf-script-flash) run_codeaf "$NEW_BIN" 1 script; CODE=$? ;;
codeaf-script-crew) run_codeaf "$NEW_BIN" 0 script; CODE=$? ;;
codeaf-chatscript-flash) run_codeaf "$NEW_BIN" 1 chatscript; CODE=$? ;;
codeaf-chatscript-crew) run_codeaf "$NEW_BIN" 0 chatscript; CODE=$? ;;
codeaf-old-flash) run_codeaf "$OLD_BIN" 1; CODE=$? ;;
codeaf-esc-flash) run_codeaf "$ESC_BIN" 1; CODE=$? ;;
codeaf-esc-crew) run_codeaf "$ESC_BIN" 0; CODE=$? ;;
Expand All @@ -284,7 +359,23 @@ case "$ARM" in
*) say "unknown arm $ARM"; exit 2 ;;
esac
WALL=$(( $(date +%s) - STARTED ))
cut -d' ' -f1-3 /proc/loadavg > "$CELL/loadavg-after"
if [ -L "$CELL/profile" ]; then
short="$(readlink "$CELL/profile")"
# THE ENGINE OUTLIVES THE CHAT. codeaf holds the workspace's conversations in
# a daemon that a killed tmux session does not stop; left running, it goes on
# writing into this profile and holds its tasks after the cell has ended.
env -i "${CELL_ENV_ARGS[@]}" HOME="$CELL/home" CODEAF_HOME="$short" CODEAF_PROFILE_DIR="$short" \
"$RUN_BIN" engine --stop --workspace "$DIR" >> "$CELL/cell.log" 2>&1
# codeaf writes its last files on the way out, so the folder moves only once
# nothing holds it open.
for _ in $(seq 30); do
lsof +D "$short" >/dev/null 2>&1 || break
sleep 1
done
sleep 2
rm "$CELL/profile" && mv "$short" "$CELL/profile"
fi
loadavg > "$CELL/loadavg-after"
say "$ARM/$TASK: harness finished, exit $CODE, ${WALL}s"

CHANGED="$(changed_files "$DIR")"
Expand All @@ -306,11 +397,13 @@ LANDED
(cd "$DIR" && git diff) > /dev/null 2>&1
(cd "$DIR" && git status --porcelain | grep -vE '\.venv|__pycache__') > "$CELL/status.txt" 2>/dev/null

AFTER="$(run_suite "$DIR" "$CELL/pytest-after.log")"
AFTER="skipped"
[ "${SKIP_SUITE:-0}" != "1" ] && AFTER="$(run_suite "$DIR" "$CELL/pytest-after.log")"
say "$ARM/$TASK: suite after = $AFTER, $CHANGED changed file(s)"

# ── the road columns, and the parallelism timeline ──────────────────────────
ROAD=""; ARMED=""; PARTS=0; PEAK=""; REFUSED=""; COST=""; COST_SRC=""
TOK_IN=""; TOK_OUT=""; TOK_CACHE=""
ESCALATED=""; ESC_SEEN=""; ROUTE=""; GRIND=""; PRE_LINE=""; MARKS=""
CALLS=""; COST_CALLS=""; ENDPOINTS=""; MARKS_J=""; FORKS=""; COSTROLE=""; CEIL=""; DIVISION=""; DIVWHY=""
case "$ARM" in
Expand Down Expand Up @@ -359,7 +452,8 @@ for name, key in (("ROAD","road"),("ARMED","armed"),("PARTS","parts"),
("COST_CALLS","cost_usd_calls"),("ENDPOINTS","endpoint_mix"),
("MARKS_J","marks"),("FORKS","forks"),("COSTROLE","cost_by_role"),
("CEIL","ceiling_decision"),("DIVISION","division"),("DIVWHY","division_why"),
("COST","cost_usd"),("COST_SRC","cost_source")):
("COST","cost_usd"),("COST_SRC","cost_source"),
("TOK_IN","tokens_in"),("TOK_OUT","tokens_out"),("TOK_CACHE","tokens_cache")):
print("%s=%s" % (name, shlex.quote(str(c.get(key, "")))))')"
fi
else
Expand Down Expand Up @@ -392,6 +486,14 @@ if [ "$OUTCOME" = "DNF" ]; then
SETTLE_NOTE="wall reached with nothing landed"
fi
fi
# HOW MUCH THE WORKERS USED THE SCRIPT TOOL, AND WHAT THEY SPENT, from their
# trajectories and their runs' plan stores. Every codeaf arm records it, so the
# zeros on a new arm are measured, not assumed.
SCRIPT_USE=""
case "$ARM" in
codeaf-*) SCRIPT_USE="$(python3 "$ONEROAD/lib/script_use.py" "$CELL" 2>>"$CELL/cell.log")" ;;
esac
export SCRIPT_USE TOK_IN TOK_OUT TOK_CACHE
SETTLE_REASON="$(cat "$CELL/settle_reason" 2>/dev/null || echo n/a)"
[ -n "${SETTLE_NOTE:-}" ] && SETTLE_REASON="$SETTLE_NOTE"
ARM="$ARM" TASK="$TASK" SEED="$SEED" WALL="$WALL" CODE="$CODE" CHANGED="$CHANGED" \
Expand Down Expand Up @@ -436,6 +538,9 @@ meta = {
"endpoint_mix": env["ENDPOINTS"], "marks": env["MARKS_J"],
"forks": env["FORKS"], "cost_by_role": env["COSTROLE"],
"ceiling_decision": env["CEIL"], "division": env["DIVISION"], "division_why": env["DIVWHY"],
"tokens_in": env.get("TOK_IN", ""), "tokens_out": env.get("TOK_OUT", ""),
"tokens_cache": env.get("TOK_CACHE", ""),
**(json.loads(env.get("SCRIPT_USE") or "{}")),
"loadavg_before": open(os.path.join(env["CELL"], "loadavg-before")).read().strip(),
"loadavg_after": open(os.path.join(env["CELL"], "loadavg-after")).read().strip(),
}
Expand Down Expand Up @@ -464,7 +569,7 @@ PY
# does not depend on the shared file.
case "$ARM" in
pi|opencode)
python3 "$ONEROAD/lib/competitor_cost.py" "$ONEROAD/results" "$(basename "$CELL")" \
python3 "$ONEROAD/lib/competitor_cost.py" "$RESULTS" "$(basename "$CELL")" \
>> "$CELL/cell.log" 2>&1 || say "$ARM/$TASK: competitor cost unreadable (meta.json keeps its blank)"
;;
esac
Expand Down
7 changes: 6 additions & 1 deletion bench/oneroad/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
"changed_files_landed", "stranded_worktree_files", "changed_files_total", "upstream_commits_in_head", "contaminated",
"road", "route", "armed", "parts", "peak_workers", "refused", "chat_tool_calls",
"checkpoint_marks", "escalated", "escalation_seen_on_pane", "pre_turn_line",
"exit", "model", "base_commit", "loadavg_before", "loadavg_after"]
"exit", "model", "base_commit", "loadavg_before", "loadavg_after",
"steps", "script_steps", "script_calls",
"tokens_in", "tokens_out", "tokens_cache",
"worker_usd", "worker_tokens_in", "worker_tokens_out",
"worker_tokens_cache", "worker_model_calls",
"chat_steps", "chat_script_steps", "chat_script_calls"]


def active_wall(cell, row):
Expand Down
6 changes: 3 additions & 3 deletions bench/oneroad/grid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ MAX_WAVES="${MAX_WAVES:-3}"
ARMS="${ARMS:-}"

mkdir -p "$ROOT/results"
echo "grid $$ $(date -Is)" >> "$ROOT/results/PIDS"
echo "grid $$ $(date +%Y-%m-%dT%H:%M:%S%z)" >> "$ROOT/results/PIDS"

for task in $TASKS; do
# Wait for a wave to land before firing the next, so the cap holds without a
# scheduler: `jobs -r` is this shell's own count of waves still in the air.
while [ "$(jobs -r | wc -l)" -ge "$MAX_WAVES" ]; do sleep 20; done
SEED="${SEED:-s1}" bash "$ROOT/wave.sh" "$task" $ARMS > "$ROOT/results/.wave-${WAVE_TAG:-}$task.out" 2>&1 &
echo "wave-${WAVE_TAG:-}$task $! $(date -Is)" >> "$ROOT/results/PIDS"
echo "wave-${WAVE_TAG:-}$task $! $(date +%Y-%m-%dT%H:%M:%S%z)" >> "$ROOT/results/PIDS"
sleep 5
done
wait
python3 "$ROOT/collect.py" >> "$ROOT/results/.collect.out" 2>&1
echo "grid landed $(date -Is)" >> "$ROOT/results/PIDS"
echo "grid landed $(date +%Y-%m-%dT%H:%M:%S%z)" >> "$ROOT/results/PIDS"
9 changes: 9 additions & 0 deletions bench/oneroad/lib/loadavg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# loadavg prints the one-, five- and fifteen-minute load: /proc on Linux,
# sysctl on macOS, where there is no /proc.
loadavg() {
if [ -r /proc/loadavg ]; then
cut -d' ' -f1-3 /proc/loadavg
else
sysctl -n vm.loadavg 2>/dev/null | tr -d '{}' | awk '{print $1, $2, $3}'
fi
}
Loading
Loading