Plan: plan-review cases at production scale, with two known-bad arms that prove they bite
Closes: #999. Relates to: #996, #911, #886, #878, #86. Branches: test/battery-plan-deep, test/battery-plan-deep-cases, test/battery-plan-deep-records. Status: Done (2026-12-01) — 120 records across all three arms ($94.00 actual); full D9 scorecard reported on #999 and #996
Erratum (2026-12-01): after the 20-call D9 pilot (claude-fable-5-2 23/24 recall, gemini-4-carbon 22/24, both fp=1 on ruff/config-option), fixed four real defects in control ruff/config-option and executed D9’s single hardening round across the five cases both subjects caught 3/3 (pi/config-unknown-keys, pi/memory-pool-key, pi/phone-shell-escape, pi/ssh-host-down, ruff/server-republish-scope), shifting corpus reach from 4/4/8/8 to 1/2/3/18 (surface/supplied/held-back/unnamed) and reducing the inherently plan-only class "two sections that contradict each other more than 60 lines apart" from 2 instances to 1 (the other seven D8.3 classes remain at ≥ 2 instances each).
Context
#996 fixed two regressions found in production’s own records, not by the battery: round two anchored on round one’s review (Carbon’s catches on plans round one called CLEAN fell from 10 of 13 to 1 of 17), and the 12-call read budget starved reviewers (42 % of 194 plan reviews hit it). The operator’s ruling (2026-12-01): the test plans must be complex enough to test these limits. Approach agreed in conversation the same day: real pinned repositories, and the old round-two arm replaced by two known-bad arms on the new cases. What the tree says, by reading:
-
Every plan case (
tools/model-battery/cases/planning,planning-hard,planning-round-two) is 44 to 77 lines over acontext/tree of at most 16 files and 10.7 KB: the whole tree is smaller than the 80 KB cap on one read result. -
The review driver (
tools/model-battery/drivers/review.mjs,subjectFor) hands a plan case everykey.contextfile. Production instead resolves the plan’sreviewPathswithresolvePlanContext(packages/pi-workflow/review-context.ts): at most 12 files, 80 KB each, 200 KB in all, the rest listed as NOT SUPPLIED. No battery case has ever produced that list. -
planning-hardandplanning-round-twohold different cases, so no pipeline setting was ever measured against another on the same plans; all sixearlier-review.txtfiles sayVERDICT: FLAGS. -
Production no longer sends an earlier review (#996), yet
packages/pi-workflow/plan-review.tsstill carriesEarlierReview,EARLIER_REVIEW_FRAMING,renderEarlierand the second parameter ofplanReviewSystemPrompt, used only by the battery’s"round": 2task. -
The explore task already pins real repositories (
tools/model-battery/lib/corpora.mjs): this repository as a detached worktree of a commit (checkoutFor), and ruff 0.16.6 as a shallow clone under~/.cache/gadhs-battery/repos/ruff(11,108 files, 1,983 of them Rust). CI clones with full history (GIT_DEPTH: "0"), so a pin of this repository is checkable there; a ruff check skips visibly when the clone is absent (tools/model-battery/test/explore.test.mjs). -
The battery’s review call has no wall-time bound (
callModel,tools/model-battery/lib/catalog.mjs); production ends a review atreviewTimeoutMs, 600 s.
Design
D1. Two pinned corpora, nothing large committed
tools/model-battery/cases/planning-deep/ holds one directory per corpus, each with a pin.json in the form cases/explore/*/pin.json has:
-
pi/pin.json:{ "name": "pi", "commit": "24843db472254cd340c976bc5ec70e93b37d36bc" }(v0.190.0), norepo. -
ruff/pin.json: thename,repo(url, tag0.16.6) andcommitofcases/explore/ruff/pin.json, so both tasks share one clone.
A case is a directory under its corpus (pi/<case>/), named <corpus>/<case>, holding plan.adoc, key.json and round-one-clean.txt. The reviewer’s tree is the corpus checkout: checkoutFor(corpus).
D2. The driver sends a deep case as production sends a plan
New tools/model-battery/lib/plan-corpus.mjs:
-
planCorpusCases(casesDir, { provision, cache }): for each corpus ofloadCorpora(casesDir), each subdirectory holding akey.jsonis a case{ name, dir, key, sha: treeDigest(dir), pin: pin.commit, corpus },corpuscarryingcachewhen one is given. When the corpus’s git directory is present (this repository always; a foreign clone when it exists, or after cloning whenprovisionis true) it callscheckPlanCorpus; when a foreign clone is absent andprovisionis false, the cases are listed unchecked. -
checkPlanCorpus(cases, gitDir): for every case, everyreviewPathspath (its:START-ENDsuffix removed) and everyproofandclaimspath exists at the pin; everyhasliteral occurs ingit show <pin>:<path>and nolacksliteral does. It throws naming the case and the entry. It is synchronous (git plumbing throughexecFileSync), becausecases()is read synchronously bytools/model-battery/cli.mjsandtools/model-battery/lib/run.mjs, and stays so. -
suppliedFor(kase, cwd), async:resolvePlanContext(localWorkspace(cwd), key.reviewPaths, cwd, contextLimits(DEFAULT_WORKFLOW_CONFIG)), imported from pi-workflow; a non-emptyproblemsthrows. -
reachProblems(kase, context), pure: each defect’s reach derived from that answer (D3), and every one that differs from the key’s, named. -
declaredTree(kase, gitDir): a temporary directory holding only the case’s declared files (git archive <pin> — <paths>).resolvePlanContextreads there the same files it would read in the full checkout, so the corpus test derives reach forpiwithout a worktree.
In corpora.mjs, checkoutFor(corpus, cache = REPO_CACHE) gains the optional cache, passes it to corpusGitDir, and keys its memo on the corpus’s name, its pinned commit and the cache (checkoutKey(corpus, cache), exported). Today the key is the name alone: cases/explore/pi/pin.json pins pi at 003d8cb and D1 pins it at 24843db, and runners/agent-loop.mjs calls the same function, so one process running both tasks would hand the second the first one’s worktree. In drivers/review.mjs:
-
cases(casesDir, spec, options):isCorpora(casesDir)givesplanCorpusCases(casesDir, options);loadTask(tools/model-battery/lib/task.mjs) passes{ provision }.battery rescore(tools/model-battery/cli.mjs) loads its tasks withprovision: false. -
subjectFor, for a case with acorpus: the tree ischeckoutFor(kase.corpus, kase.corpus.cache);filesandnotSuppliedcome fromsuppliedForand go tobuildPlanReviewPromptasplan-pause.tspasses them (notSuppliedonly when non-empty); a non-emptyreachProblemsover the same answer throws before the case’s call; the snapshot iscreateSnapshot(localWorkspace(cwd), cwd, "disk", budget);disposedoes nothing. -
The budget is
snapshotBudget(DEFAULT_WORKFLOW_CONFIG, "plan"), itsmaxCallsandmaxBytesreplaced by the task’ssnapshotBudgetwhen the spec has one. -
The lane’s recorded
snapshotgainsmaxCallsandmaxBytes. -
MODULE_URLSgainspackages/pi-workflow/review-context.ts.
checkSpec accepts "snapshotBudget": { "maxCalls": n, "maxBytes": n } (two positive integers) and "earlier": { "reviewer": "…", "file": "…" } (two non-empty strings), each on a review task only. round and the key-level earlier go (D5).
D3. A case’s key
As cases/planning-hard/hard-requeue/key.json, with these differences:
-
reviewPathsreplacescontext: every file the plan names, in the order the plan first names it; an entry may bepath:START-END. -
A defect carries
reachand, unless its reach issurface,proof: a list of{ "path", "has" }or{ "path", "lacks" }. Itstierissurfacefor reachsurfaceandcross-fileotherwise, so the existing columns still read it. -
Reach is what the reviewer must do to see the defect, derived from production’s own answer at the pin. A proof is settled by the supplied text when a supplied file of that path contains its
hasliteral, or is the whole file for alacks.surface: no proof, the plan contradicts itself.supplied: every proof is settled by the supplied text.unnamed: some proof’s path is not inreviewPathsand does not occur inplan.adoc.held-back: anything else. -
A decoy carries
justification(a path at the pin) and aproof. -
A control (no defects) carries
claims: at least ten{ "path", "has" }, one for each seam its plan describes.
D4. The ten cases
Each plan proposes work that is not done at its pin. "Home" files exist at the pin and are where the case’s plan says its change lands; this plan edits none of them. S, Su, H, U are the planted defects by reach (surface, supplied, held-back, unnamed).
| Case | The plan proposes | Home files | S | Su | H | U | Decoys |
|---|---|---|---|---|---|---|---|
|
one memory pool for a project however it was cloned |
|
0 |
1 |
1 |
1 |
1 |
|
|
|
1 |
0 |
1 |
1 |
1 |
|
the pre-push hook checks the commits pushed, not the working tree |
|
0 |
1 |
1 |
1 |
0 |
|
the modes overlay refuses an unknown top-level key by name |
|
1 |
0 |
1 |
1 |
1 |
|
several approved plans recorded per commit |
|
0 |
1 |
1 |
1 |
1 |
|
the paired phone’s |
|
1 |
0 |
1 |
1 |
1 |
|
a text filter and paging for the |
|
control |
||||
|
the lint cache’s 30-day retention ( |
|
1 |
0 |
1 |
1 |
1 |
|
after a configuration file changes, the server republishes diagnostics only for documents under the reloaded roots |
|
0 |
1 |
1 |
1 |
0 |
|
a new top-level option, read through options, configuration and settings |
|
control |
Totals: 24 scored defects (4 surface, 4 supplied, 8 held-back, 8 unnamed), 6 decoys, 2 controls.
D5. Three arms on the same cases
Task file (tools/model-battery/tasks/) |
What differs | Subjects, 3 runs each | Role |
|---|---|---|---|
|
nothing: production’s caps and 48 calls, 800 KB |
Fable 5.2, Carbon |
the shipped pipeline |
|
|
Fable 5.2, Carbon |
known bad: the budget before #996 |
|
|
Carbon |
known bad: round two as 0.173.0 to 0.189.0 sent it |
All three: "path": "single-call", "driver": "review", "cases": "cases/planning-deep", "scorer": "anchors", "experiment": "planning", "typicalTokens": 350000, and a // saying what the arm is. Subjects are bare refs (vertex-anthropic/claude-fable-5-2, vertex-gemini/gemini-4-carbon), so levelFor sends production’s plan levels. battery.json gains one permutation entry per task; RESCORABLE gains the three names.
Under earlier, every case must hold the named file, non-empty, or cases() refuses it by name; the system prompt is production’s with the frozen framing inserted, and the user prompt ends with the frozen rendering of the file (D6). promptText(spec) appends snapshotBudget=<calls>/<bytes> for a task with one, and for a task with earlier the framed system prompt and renderEarlier.toString().
planning-round-two is retired: its task file, its six case directories, its manifest entry and its RESCORABLE entry are deleted. Its records stay under tools/model-battery/store/planning-round-two, as verify’s did (#898). `planning and planning-hard are not changed.
D6. The earlier-review path leaves pi-workflow
packages/pi-workflow/plan-review.ts loses EarlierReview, PlanReviewInput.earlier, EARLIER_REVIEW_FRAMING, renderEarlier and the second parameter of planReviewSystemPrompt; buildPlanReviewPrompt and runPlanReview no longer mention them. The cold prompts do not change (pinned by digest in packages/pi-workflow/test/review-snapshot-loop.test.ts).
New tools/model-battery/lib/earlier-review.mjs holds what production sent from 0.173.0 to 0.189.0, word for word from plan-review.ts at v0.189.0: EARLIER_REVIEW_FRAMING, renderEarlier({ reviewer, text }), and withEarlierFraming(systemPrompt), which inserts the framing before the one occurrence of Answer each of P1-P4 and throws when there is not exactly one. Checked on 2026-12-01 against main: that insertion into planReviewSystemPrompt(budget) gives planReviewSystemPrompt(budget, true) character for character. MR 1’s test commit comes first and records, in its test, the sha256 of the framing as production’s round-two prompt holds it (the text that prompt has and the cold one lacks), while pi-workflow can still build it; the refactor commit then removes the parameter.
D7. Scoring by reach, the read budget, and the wall
tools/model-battery/scorers/anchors.mjs:
-
REACHESandreachCounts(key, caught), aspositionCounts:scoreReviewanderroredScoreaddbyReachfor a key whose defects carryreach. -
aggregatepoolsbyReach, and for records whosesnapshotcarriesmaxCallsaddshitCallCap(the share withsnapshot.calls > snapshot.maxCalls: a call was refused),callsMedian, andoverTimeout(the share whosewallMsexceedsDEFAULT_WORKFLOW_CONFIG.reviewTimeoutMs: production would have ended that review unreviewed).
tools/model-battery/render.mjs gains reachTable, placed after a role’s experiments table: one row per summary permutation of the role’s arms whose cell has byReach, with caught over planted per reach, hitCallCap, callsMedian and overTimeout. With no such cell it returns the empty string, so the page does not change until the arms are measured.
D8. Authoring rules
-
Form. Each
plan.adocis written as this repository’s own plans are (header line, Context, a Design of numbered decisions, Scope, a Tests table, a Risks table with a Mode column, Delivery), in 180 to 280 lines, passesplanShapeProblems(packages/pi-workflow/plan-shape.ts), and cites an issue number above #1200, so no real issue is cited. -
Size. It names 18 to 35 files that exist at the pin, all in
reviewPaths; production’s caps at the pin hold at least six of them back. -
Planted. Each defect is one of these classes, named in its
source, each class used at least twice: a caller or test the plan says does not exist; a signature, return or visibility misdescribed; two sections that contradict each other more than 60 lines apart; a step that needs what a later step builds; a behaviour the plan says is unchanged that its own change alters; a count the tree contradicts; a mechanism said to cover a case it does not; a cited test that asserts something else. A planted claim is written once, as the author’s plain statement. A decoy looks wrong and is right, for a reason in a file at the pin. -
Nothing else. A case plants what its key lists; every other seam the plan describes is as the tree has it. A control’s seams are its
claims, so the check reads them. -
Round one’s review.
round-one-clean.txtis in production’s answer form:VERDICT: CLEAN, P1 to P4 each PASS with a sentence, then theBeyond the declared context the reviewer read …line naming three to five files, none of them a proof path of that case. -
No preview. No plan with planted defects is shown to a model before the run. A helper may read a control’s plan against its pin and report contradictions, which are fixed before the case lands.
-
cases/planning-deep/README.adocsays the plans misdescribe their trees on purpose.
D9. The run, and the rule that reads it
The run is the operator’s. First a pilot: node tools/task.mjs battery fill --task planning-deep --runs 1, 20 calls, after its --dry-run. It gives the measured cost per call, and stops the work when either subject catches 23 or more of the 24 defects: the cases are then hardened (below) before anything else is spent. Then the full fill of the three tasks, 150 calls less the pilot’s 20, projected from the pilot’s cost; by typicalTokens and the catalog’s rates it is about $620, over the battery’s $300 gate, so the operator names --budget. One --retry-errors --jobs 1 pass follows.
The rule, fixed here. Per subject, pooled over its three runs: R is recall over all defects; D is recall over held-back and unnamed defects; S is the highest per-run value minus the lowest, the larger of the two arms compared.
| # | The suite bites when |
|---|---|
a |
D on |
b |
Carbon’s R on |
c |
R on |
-
All hold: the result goes on the issue and the page; whether
planning-deepbecomes the planning role’s task, and any change to a budget or toreviewTimeoutMs(fromoverTimeout), are the operator’s decisions and their own issues. -
a or c fails: one hardening round is in scope. Every case that all runs of both subjects caught whole on
planning-deepis rewritten with its evidence in unnamed files, the arms are run again on those cases with the operator’s go, and the rule is read once more. A second failure is reported as the result. -
b fails: anchoring did not reproduce on hand-written CLEAN reviews. That is a finding about #996’s cause, reported on #996 and on the issue, and not a reason to rewrite cases.
Scoring protocol. A prediction goes on the issue before the pilot. After each run every miss and every false flag is read. An anchor changes only to credit a FAIL block that plainly names the defect in other words, or to stop a decoy matching a block about a real defect; every change is applied to every subject by battery rescore and listed on the issue. A control that turns out to hold a real defect is reported with the result and stays as measured.
Scope
-
MR 1 (
Relates tothe issue), branchtest/battery-plan-deep, two commits, thetestone first.refactor(pi-workflow): D6’s removal, with its CHANGELOG line.test:plan-corpus.mjs,earlier-review.mjs,checkoutFor’s parameter and memo key, the driver, `checkSpec,loadTask,rescore’s `provision: false, the scorer,reachTable, the retirement ofplanning-round-two, the tests below that need no deep case,battery render,page-head.adoc, and one sentence inbattery.json’s `defaultsNote: reviewer and planning rows dated before 2026-12-01 were measured under the 12-call, 200 KB read budget (#996). -
MR 2 (
Relates tothe issue), branchtest/battery-plan-deep-cases: the two pins, the ten cases, the README, the three task files, the manifest entries,RESCORABLE, the corpus tests,battery render. -
The pilot and the run, each with the operator’s go; the prediction first.
-
MR 3 (
Closesthe issue), branchtest/battery-plan-deep-records: the records,battery summariseandbattery render, any key change the protocol made, the result by the rule.
Not in scope: moving the planning role to the deep task; any production budget or timeout; planning and planning-hard; a signal in production when a review hits its budget (#1000).
Tests
vitest, in tools/model-battery/test/. New plan-deep.test.mjs replaces plan-round-two.test.mjs (its planning-hard checks move across unchanged). "Temp corpus" is a small git repository built in a temporary cache directory and pinned as a foreign corpus, as explore.test.mjs builds one for corpusGitDir.
| Category | Test | Pins |
|---|---|---|
contract |
temp corpus, 14 declared files: |
a deep case is sent as production sends a plan |
contract |
the three arms on one temp case: the system prompt says 48 calls and 800 KB, 12 calls and 200 KB, and 48 and 800 with the frozen framing before |
each arm differs from the shipped pipeline in one thing |
contract |
|
no other task’s fingerprint carries an arm’s text |
contract |
|
the spec’s shape |
contract |
|
the old prompt is rebuilt exactly or refused, fail-closed |
contract |
the manifest lists the three tasks with 3 runs and the subjects of D5 |
the permutations |
regression |
temp corpus: a |
a stale or mislabelled case is not measured |
regression |
|
a task is not handed another task’s tree |
regression |
|
|
regression |
|
the pinned tree does not hold the keys |
regression |
corpus: every deep plan passes |
the corpus is what D4 and D8 say |
regression |
for every defect and decoy, a FAIL block whose text is its |
anchors match their own words; round one’s review misses what is planted |
regression |
|
the three new numbers |
regression |
|
the page moves only when measured |
regression |
|
the lists that name every task |
Mutants, each to fail its test: subjectFor handing every declared file; the spec’s budget ignored; the framing appended instead of inserted; checkPlanCorpus skipping lacks; the memo keyed on the name alone.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
A planted defect the tree does not support, or a control that is not clean |
silent |
every proof and claim is checked at the pin by test and again when the cases are listed; D8.4; the protocol reads every false flag |
Reach mislabelled, so recall by reach misleads |
fail-closed |
derived from |
Two tasks pin one corpus name at different commits and share a checkout |
silent |
the memo is keyed on name, commit and cache (regression test) |
The keys reach the reviewer through the tree |
silent |
the pin predates the cases (regression test) |
The ruff clone is absent in CI, so its keys are unchecked there |
loud |
the test skips visibly; listing the cases checks them on the box that runs |
A cold case run anchored, or the reverse |
fail-closed |
the task names the earlier file and the loader refuses a case without it |
An anchor misses a finding worded another way |
silent |
the |
Hand-written CLEAN reviews differ from real ones |
silent |
production’s answer form is pinned by test; stated as a limit in the result |
The cases are written by a model of a reviewed family |
silent |
defect classes come from production’s own catches; outcome b and c are read per subject |
The suite does not bite |
loud |
the rule’s second and third outcomes; one hardening round, then reported |
A review outlives production’s 600 s bound and is scored as if it had happened |
silent |
|
Cost above the projection |
fail-closed |
the pilot measures first; the battery refuses over its budget before any call |
|
loud |
rendered in MR 1 first; a diff outside planning’s experiments and the notes is reported and left out |
Delivery
-
Canonical page:
docs/modules/ROOT/pages/model-battery.adoc, generated bybattery render; its sourcetools/model-battery/page-head.adocnames the three arms in the Experiments bullet in place ofplanning-round-two, and reach in the Scores bullet. -
CHANGELOG.adoc== Unreleased: a Changed line for D6 (@gadhs/pi-workflow), and a "Repo only" line with each MR. -
This plan committed as
docs/modules/ROOT/pages/plans/battery-plan-deep.adoc, listed indocs/modules/ROOT/nav.adoc; Status In progress at start, Done at MR 3’s merge. -
Validate before each push; MRs merged through the train with squash off; the issue is closed by MR 3, with its merge SHA and the result noted on it.