Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .workflow/tasks/WB-57.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"key": "WB-57",
"title": "Show real errors workbench caught, and a 30-60 s demo",
"type": "chore",
"status": "open",
"status": "done",
"desc": "Build later: only once the WB-52 bench records at least one catch plain missed. Examples must come from bench records or real tickets, never staged.\n\nACCEPTANCE:\n- docs page with each example: the ticket, what plain did, what workbench flagged, link to the run record\n- a 30-60 s recording of wb start, wb next, wb approve on one fixture ticket, linked from the README",
"created": "2026-09-26T17:51:51Z",
"updated": "2026-09-26T17:51:51Z",
"updated": "2026-09-27T03:12:57Z",
"comments": [],
"linked": [
{
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ arm, so a direction rather than a verdict):
| bug in user data | fixed, no test (2/2) | fixed, with a test, planned (critical zone) | 6.7x tokens, 5.8x wall |

Small work now costs about twice a plain session; work in a critical zone still
costs the full plan.
costs the full plan. [What workbench caught](docs/caught.md) walks through each
case, and a 33-second recording of `wb start`, `wb next`, `wb finish` and
`wb approve` on one of these tickets is in [docs/demo.cast](docs/demo.cast)
(`asciinema play docs/demo.cast`; recorded by `bench/demo.py` from real output).

### The light path

Expand Down Expand Up @@ -475,7 +478,8 @@ Exit codes: 2 usage, 3 config, 4 auth, 5 provider, 6 not found, 7 audit failed,
- [CHANGELOG.md](CHANGELOG.md) — what changed, and the deprecation policy
- [status.md](docs/status.md) — the pipeline, the command history, rigour tiers, settled gates
- [flow.md](docs/flow.md) — source and validation branches, cherry-pick carrying, branch naming
- [bench.md](docs/bench.md) — the benchmark: metrics, the two arms, running it, reading the report
- [bench.md](docs/bench.md) — the benchmark: metrics, the arms, running it, reading the report
- [caught.md](docs/caught.md) — what workbench caught in the benchmark, case by case, with the run records

These are for maintainers. Agents do not read them: the behaviour they describe
is enforced in code, and loading them into a session would pay twice for the
Expand Down
120 changes: 120 additions & 0 deletions bench/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""Record the README's demo: wb start, wb next, wb finish and wb approve on BN-6.

python bench/demo.py [--out docs/demo.cast]

Every line of output in the recording is what the command printed, run for real
against a fresh copy of the benchmark fixture; nothing is typed into the file by
hand. The one edit is the fix itself, made by a command shown on screen, since a
recording of an editor would show nothing wb does. The pace -- typing speed and
the pause after each output -- is set here, so the clip lasts 30-60 s whatever
the machine; the real duration of each command is not what the clip is about.

Writes an asciicast v2 file: `asciinema play docs/demo.cast`, or any asciicast
player.
"""

from __future__ import annotations

import argparse
import json
import os
import subprocess
import sys
from pathlib import Path

import run as bench_run

ROOT = bench_run.ROOT
TICKET = "BN-6"
MESSAGE = "fix: allow ordering exactly the units on hand"
FIX = "shop/stock.py"
TEST = "tests/test_stock.py"
TEST_ADDED = (
"\n\nclass LastUnitTest(unittest.TestCase):\n"
" def test_the_last_units_on_hand_can_be_ordered(self):\n"
" self.assertTrue(available({\"tea\": 2}, \"tea\", 2))\n"
)
TYPE_S = 0.06
# Time to read an output: a base, plus a little per line.
PAUSE_S = 3.5
PAUSE_PER_LINE_S = 0.45
WIDTH, HEIGHT = 100, 30


def steps(wb: str) -> list[tuple[str, list[str] | None]]:
"""(what is shown at the prompt, the argv that runs it; None for a shell step done in Python)."""
return [
(f"wb start {TICKET}", [sys.executable, wb, "start", TICKET]),
("wb next", [sys.executable, wb, "next"]),
(f"sed -i 's/> quantity/>= quantity/' {FIX} # the fix, and a test for it", None),
(f'wb finish {TICKET} -m "{MESSAGE}" --commit', [sys.executable, wb, "finish", TICKET, "-m", MESSAGE, "--commit"]),
("wb approve", [sys.executable, wb, "approve"]),
]


def record(out: Path) -> Path:
ticket = next(t for t in bench_run.load_tickets([TICKET]))
with bench_run.workdir("wb-demo-") as work:
env = bench_run.session_env(work)
env["WB_NO_HOOKS"] = "1"
plugin = bench_run.copy_plugin(work / "plugin")
repo = work / "repo"
bench_run.prepare(repo, ticket, "workbench", env, plugin)
wb = str(plugin / "lib" / "wb.py")

events: list[list] = []
clock = 0.5
for shown, argv in steps(wb):
clock = _type(events, clock, f"$ {shown}")
if argv is None:
_fix(repo)
output = ""
else:
done = subprocess.run(argv, cwd=repo, env=env, stdin=subprocess.DEVNULL, capture_output=True,
text=True, encoding="utf-8", errors="replace", timeout=300)
output = (done.stdout + done.stderr).replace(str(work), "~").replace(str(work).replace("\\", "/"), "~")
events.append([round(clock, 3), "o", "\r\n" + output.replace("\n", "\r\n")])
clock += (PAUSE_S + PAUSE_PER_LINE_S * output.count("\n")) if output else 1.2

out.parent.mkdir(parents=True, exist_ok=True)
header = {"version": 2, "width": WIDTH, "height": HEIGHT, "title": f"workbench: {TICKET} on the light path",
"env": {"SHELL": "/bin/sh", "TERM": "xterm-256color"}}
lines = [json.dumps(header)] + [json.dumps(event, ensure_ascii=False) for event in events]
out.write_text("\n".join(lines) + "\n", encoding="utf-8")
return out


def _type(events: list[list], clock: float, text: str) -> float:
for character in text:
events.append([round(clock, 3), "o", character])
clock += TYPE_S
return clock + 0.4


def _fix(repo: Path) -> None:
path = repo / FIX
# newline="\n": the fixture's line endings, as an editor keeps them. A CRLF
# rewrite on Windows would read as every line changed.
fixed = path.read_text(encoding="utf-8").replace("> quantity", ">= quantity")
path.write_text(fixed, encoding="utf-8", newline="\n")
test = repo / TEST
test.write_text(test.read_text(encoding="utf-8").rstrip("\n") + TEST_ADDED, encoding="utf-8", newline="\n")


def duration(cast: Path) -> float:
last = cast.read_text(encoding="utf-8").strip().splitlines()[-1]
return float(json.loads(last)[0])


def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="Record the README demo (asciicast v2).")
parser.add_argument("--out", default=str(ROOT / "docs" / "demo.cast"))
args = parser.parse_args(argv)
os.environ.setdefault("PYTHONIOENCODING", "utf-8")
path = record(Path(args.out))
print(f"wrote {path} ({duration(path):.0f} s)")
return 0


if __name__ == "__main__":
sys.exit(main())
100 changes: 100 additions & 0 deletions docs/caught.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# What workbench caught

Every example here comes from a benchmark record, never from a staged session:
the ticket, what a plain session did with it, what the workbench session did,
and the run records that show both. The numbers come from the first clean run,
[2026-09-27, commit 9abd3c9](../bench/results/2026-09-27-9abd3c9/report.md): the
same model (Sonnet), the same prompt, two runs per arm. Two runs is a direction,
not a verdict. How the benchmark works is in [bench.md](bench.md).

A catch is said the way it happened. Where a guardrail refused something, it
says so. Where the flow only asked for something and the session did the rest,
it says that instead.

## BN-6: the ticket names a function that was renamed

**The ticket.** "`in_stock` refuses the last unit on hand: with 2 on hand, an
order for 2 is refused." The live check is `shop/stock.available`. A deprecated
`in_stock` with the same bug still sits in `shop/legacy.py`, kept for an old
export script that checkout never calls.

**Plain, 2 of 2 runs.** It searched for `in_stock`, found the one in
`shop/legacy.py`, fixed it and committed. It wrote no test. The live check is
still broken, and the hidden tests fail. It took 5-6 turns and about 16 s.
Records: [BN-6-plain-1](../bench/results/2026-09-27-9abd3c9/BN-6-plain-1.json),
[BN-6-plain-2](../bench/results/2026-09-27-9abd3c9/BN-6-plain-2.json).

**Workbench, 2 of 2 runs.** `wb start` put the ticket on the light path, which
asks for the change *and a test that covers it*. The session opened
`shop/legacy.py` too, then went looking for the test to extend. `tests/test_stock.py`
tests `stock.available`, not `in_stock`, so the session concluded that the copy
in `legacy.py` is dead and the live code is `stock.py`. In its own words: "The
ticket's `in_stock` name matches `shop/legacy.py`, but that module is explicitly
deprecated and unused by checkout. The live code path is `shop/stock.py`'s
`available()`." It fixed that function and added a test for the last unit.
`wb finish` proved the test fails on the base and passes with the fix. The hidden
tests pass. It took 16 turns and about 47 s.
Records: [BN-6-workbench-1](../bench/results/2026-09-27-9abd3c9/BN-6-workbench-1.json),
[BN-6-workbench-2](../bench/results/2026-09-27-9abd3c9/BN-6-workbench-2.json).

**What caught it.** No guardrail refused anything. What steered the session was
the light path's requirement to cover the change with a test. The requirement
does not always work: in an earlier run whose numbers are not citable
([31a7699](../bench/results/2026-09-27-31a7699/report.md)), one of two workbench
sessions fixed `legacy.py` and wrote a test for it, and `wb finish` passed
that. A test proves the code does what the test says, not that it is the right
code.

## BN-3, BN-4, BN-7: a fix with no test

**The tickets.** A one-file chore (`format_money` prints refunds wrong), a bug
in user data (`display_name` keeps stray whitespace), and a one-character bug
(loyalty points are a tenth of what they should be). There is no test file for
the loyalty module at all.

**Plain, 6 of 6 runs.** It fixed each bug correctly (the hidden tests pass) and
wrote no test for any of them. The next change to any of these functions has
nothing to stop it undoing the fix.

**Workbench, 6 of 6 runs.** Every run added or extended a test. On BN-3 and BN-7
(the light path), `wb finish` refuses a logic change with no test change, and
on a bug it runs each changed test on the base the branch left, where the test
must fail. In these runs the session wrote the test before it was asked, so
the refusal never had to fire. What held the line was the instruction, backed
by a check that would have refused.

Records: `BN-3-*`, `BN-4-*` and `BN-7-*` in
[9abd3c9](../bench/results/2026-09-27-9abd3c9/). The report's caught-errors
section counts `tests_missing` for each arm.

## BN-4: a fix that lands in user data

**The ticket.** `display_name` keeps stray whitespace. The function is in
`shop/users.py`, which the repo profile puts in the **user-data** critical zone.

**Plain, 2 of 2 runs.** Fixed, no test, committed. 7-8 turns.

**Workbench, 2 of 2 runs.** This is the one guardrail that fired. The session
fixed the bug on the light path, then `wb finish` refused:
`BN-4 outgrew the light path: touches user-data. It now takes the standard route`.
The session then planned the change, audited the plan, verified it and
committed, with a test. The result matched plain's plus a test, and it cost
6.7x the tokens. Both runs also discarded the working fix before planning,
which WB-58 records as waste.
Records: [BN-4-workbench-1](../bench/results/2026-09-27-9abd3c9/BN-4-workbench-1.json),
[BN-4-workbench-2](../bench/results/2026-09-27-9abd3c9/BN-4-workbench-2.json).

**What caught it.** The zone check did what it is for: a change to user data is
held to the highest bar in the repo. Whether that bar paid for itself on a
whitespace fix is a fair question, and this record is the evidence either way.

## What has not been caught

- **A spill into a shared neighbour (BN-5).** Every plain session so far fixed
it in place and left the shared `regions.zone_for` alone. This ticket has
never separated the arms.
- **An invented reference.** `invalid_refs` has been 0 in every run of both
arms.

Both stay in the fixture. A ticket that does not separate the arms is a result
too.
Loading
Loading