Plan: the general-purpose helper returns a validated result
Closes: #895. Relates to: #884 (the audit), #736, #472, #896. Branches: test/battery-coder-helper, then feat/helper-validated-result. Status: Done (2026-11-27) — the helper returns a checked result; on the coder arm all four gates held (30/30 solved both arms, 30/30 yields, cost ×1.08, no false check)
Context
Ruled by the operator (2026-11-22): a validated result, with a size bound, measured on the battery’s coder task before merging. The contract and the measurement were agreed in conversation (2026-11-27). What the tree says today, by reading:
-
packages/pi-agents/agents/general-purpose.mddeclares nooutput_schemaand lists noyieldtool; its helper answers in prose.Explore.mdandResearch.mddeclare both. -
The machinery is in pi-modes and needs no change.
yield(packages/pi-modes/yield-tool.ts,decideYield) checks the payload against the agent file’s schema inside the helper and tells it every problem at once.MAX_SCHEMA_RETRIESis 3: the first two failing submissions are refused, and the third is accepted markedschemaOverridden. The lead reads "returned a checked result" with the payload (subagent-wiring.ts,yieldText); a contracted helper that ends in prose is reminded once (remindToYield); the delegation gate letsyieldthrough in every mode (NON_CAPABILITY_TOOLSinsubagent-gate.ts). -
On luchs the session files record 161 yields: 160 validated, 1 reported failure, none waived.
-
Only auto, manual and yolo may spawn the helper (
canSpawninpackages/pi-modes/modes.json; plan lists Explore and Research), and all three run Opus 5.5; the helper runs on the session’s model. -
The battery’s
codertask (tools/model-battery/tasks/coder.json) runs pi’s default prompt, not the helper. pi-subagents builds anappendagent’s prompt as the parent’s prompt, a header, and the body inside<agent_instructions>(@gotgenes/pi-subagents,src/session/prompts.ts). The battery’s runner sends an agent’s body with--system-prompt, which replaces pi’s prompt, and has no way to append.
Design
The contract
In general-purpose.md’s frontmatter, with `yield added to tools::
output_schema:
type: object
required: [summary, files, checks, not_done]
additionalProperties: false
properties:
summary: { type: string, minLength: 1, maxLength: 4000 }
files: { type: array, maxItems: 40, items: { type: string, maxLength: 200 } }
checks:
type: array
maxItems: 20
items:
type: object
required: [command, result]
additionalProperties: false
properties:
command: { type: string, minLength: 1, maxLength: 200 }
result: { enum: [passed, failed, not-run] }
detail: { type: string, maxLength: 300 }
not_done: { type: array, maxItems: 10, items: { type: string, maxLength: 300 } }
The worst case is about 27,000 characters as the lead reads it (4,000 + 40 x 200 + 20 x 510 + 10 x 300, plus JSON punctuation). The bound is the schema’s: the helper is refused an oversize payload and shortens it. A helper’s third failing submission is accepted flagged, as for every contracted agent; nothing cuts it. description: gains a last sentence: "Returns a checked result: a summary, the files it touched, the checks it ran, and what is not done."
The body
The first paragraph (who the helper is) and the batching paragraph stay. After the batching paragraph, and in place of the present last paragraph:
Finish by calling the `yield` tool exactly once. `result.data` is an OBJECT
of exactly this shape - the field names and sizes are validated, and prose in
place of the object is rejected:
{"summary": "<what you changed, or the answer when you changed nothing>",
"files": ["<a path you created, changed or deleted>", ...],
"checks": [{"command": "<what you ran>", "result": "passed", "detail": "<optional, one line>"}, ...],
"not_done": ["<what was asked and is not done, and why>", ...]}
`summary` is at most 4,000 characters; `files` at most 40 paths, `checks` at
most 20 and `not_done` at most 10, and any of the three may be an empty
list. A check's `result` is `passed`, `failed` or `not-run`: list a check
with the result you saw in this run, and one you were asked for and did not
run as `not-run`. Never report a result you did not see. Longer material
goes in a file under `.pi/scratch/` that `files` names.
When the work could not be done at all, call `yield` with `result.error` (a
string saying why) instead of `data`. The parent reads what you yield, not
what you say — prose is not delivered. If yield reports schema problems, fix
every one it lists and call it again.
When you are told your turn budget is nearly spent, stop and call `yield`
at once with what you have: `summary` as far as you got, and every part you
did not reach under `not_done`. A partial result the parent can read is
worth more than a run that ends with nothing.
The battery arm
tools/model-battery/tasks/coder-helper.json: the coder task’s fields (path, workspace, cases, userPrompt, sandbox, thinking, scorer, timeoutMs, typicalTokens) unchanged, with "prompt": { "agent": "general-purpose" }, "tools": "agent", "experiment": "coder", and a // saying what it is. It is not in the manifest; it is run by name. Three changes let it run:
-
parseAgentFile(tools/model-battery/lib/task.mjs) also returnsmode("replace"when the frontmatter saysprompt_mode: replace, else"append", pi-subagents' default) andtools(the frontmatter’s list).resolvePromptcarries both; an append prompt’sshaissha256("append\n" + text), a replace prompt’s stayssha256(text). -
"tools": "agent":loadTaskresolves it to the agent file’s list.checkSpecaccepts the string only withprompt.agentandsandbox: true(the file may listbash, and the check cannot read it). -
The runner appends.
tools/model-battery/runners/agent-loop.mjsgains an exportedlanePrompt(prompt):{ appendSystemPrompt: "<agent_instructions>\n" + text + "\n</agent_instructions>" }for an append prompt, else{ systemPrompt: text };laneSpecspreads it.tools/model-battery/lib/headless.mjsgains an exportedheadlessArgs(spec), the argument listrunHeadlessbuilds now, with two additions:--append-system-promptand its text when the spec carriesappendSystemPrompt; and-e builtin:codemodewhen the spec’s tools includecodemodeand its pi arguments include--no-extensions.
The lane’s yield and count are the battery’s own (tools/model-battery/yield-tool.mjs), checked against the agent file’s schema as for explore. codemode is the tool of pi’s built-in extension builtin:codemode: naming it in --tools turns the tool on, but the bare stack’s --no-extensions (BARE_PI_ARGS) disables built-in extensions too, and -e builtin:codemode loads one explicitly (pi’s docs/settings.md, "The built-in extensions are named", and docs/cli.md, --no-extensions, both under node_modules/@earendil-works/pi-coding-agent/). --append-system-prompt takes text or a file and appends it to the system prompt (docs/cli.md, "Prompts and process"). No battery lane has used either, which is what the smoke lane below is for.
The run, and the rule that reads it
The run is the operator’s. One subject, vertex-anthropic/claude-opus-5-5, at the task’s medium; two arms; five runs each over the six cases: 60 lanes, about $10 by the stored coder cell ($0.11 a lane). A scratch script interleaves the arms run by run, as #891 did: it writes main’s general-purpose.md (the helper as shipped) and runs battery run --task coder-helper --model vertex-anthropic/claude-opus-5-5 --runs <r> --store build/battery-895-base, restores the branch’s file and runs the same into build/battery-895-contract, for r = 1 to 5, restoring the file at exit. Before it, a dry run gives the projection, and one smoke lane (one case, the contract arm) shows codemode and yield work under the sandbox; a smoke lane that fails for the harness’s own reasons stops the run.
The decision rule, fixed here. The contract merges when, over the 30 lanes of each arm:
| # | Gate |
|---|---|
a |
Work: lanes solved (hidden suite all green) under the contract are at least the baseline’s count minus 1 |
b |
Delivery: at least 29 of the 30 contract lanes end in an accepted |
c |
Cost: the contract arm’s median cost a lane is at most 1.25 times the baseline’s |
d |
Truth: no contract lane reports a check as |
Gate d is read, lane by lane, from each record’s transcript.jsonl evidence: a claimed command that paraphrases one the lane ran is that command; a claim with no such call, or one whose call failed, breaks the gate. Reported beside the gates: files against the files each lane’s patch.diff changed, turns, and wall time. A prediction goes on #895 before the run. If a gate fails the result goes on #895 and the operator decides; nothing merges.
Scope
-
MR 1 (
Relates to #895), branchtest/battery-coder-helper: the task file,parseAgentFile,resolvePrompt,checkSpec,loadTask,lanePrompt,headlessArgs, their tests, the CHANGELOG line. Merged on its own: #896 measures on the same arm. -
The contract, unmerged, branch
feat/helper-validated-result: the agent file, its tests,helpers.adoc,packages.adoc, the README, the CHANGELOG entry. Validated and consumer-sim run locally; not pushed for merge. -
The dry run, the prediction, the operator’s go, the smoke lane, the run, and the result on #895 by the rule.
-
MR 2 (
Closes #895), only when gates a to d hold.
Tests
| Category | Test | Pins |
|---|---|---|
contract |
|
the body states the contract the schema declares |
contract |
same file: the "packaged contracts … are exactly these (#396)" block’s |
the bounds, and that prose and schema agree on them |
contract |
same file, with |
the pinned TypeBox enforces |
regression |
same file: on one state, two oversize submissions are retries and the third is an accept marked |
the waiver is the only way past the bound, and it is flagged |
contract |
|
the arm takes the helper as its file says; no existing fingerprint moves |
contract |
same file: |
the spec’s shape; a fill never runs the arm unasked |
contract |
|
the helper’s body is appended to pi’s prompt, as pi-subagents appends it; a bare lane that lists |
Mutants, each to fail its test: maxLength dropped from summary; yield dropped from tools:; lanePrompt returning systemPrompt for an append prompt. Coverage bars hold (pi-agents 100 % lines).
Risks
| Risk | Mode | Mitigation |
|---|---|---|
The contract costs the helper its work: turns spent on the report, or a lane ending on a refused yield |
loud |
gates a and c; the baseline arm on the same cases and model |
A helper fills |
silent |
the body forbids it; gate d reads every claim against the transcript before anything merges |
A payload still past the bound on its third submission |
silent |
accepted flagged |
The pinned TypeBox ignores a bound keyword on a plain schema |
fail-open |
the contract test submits each violation through |
The battery lane differs from a real helper: no parent prompt, no reminder, the battery’s own |
silent |
stated with the result; the bare lane is the stricter case for gate b, having no reminder |
|
fail-closed |
the smoke lane first; the run stops on a harness fault |
The swap script leaves main’s agent file in the working tree |
loud |
restored by the script at exit; |
Leads that parse the helper’s prose |
silent |
none in the tree (grep of |
Delivery
-
Canonical page:
docs/modules/ROOT/pages/helpers.adoc, theyieldsection: the general-purpose contract, its four fields and its bounds.docs/modules/ROOT/pages/packages.adocandpackages/pi-agents/README.md: the helper’s line. -
CHANGELOG.adoc== Unreleased: a "Repo only" line for the arm; a Changed entry for the contract. -
This plan committed as
docs/modules/ROOT/pages/plans/helper-validated-result.adoc, listed indocs/modules/ROOT/nav.adoc; Status In progress at start, Done at MR 2’s merge or at the operator’s decision. -
Validate and consumer-sim before each push; MRs merged with squash off; #895 is closed by MR 2 with its merge SHA on the issue. pi-agents takes a minor bump at the next release.