Repository navigation
Description
What happened
aforge do --json promises one object on stdout that a script can be written
against, and docs/HEADLESS.md tells that script to "read the exit code, not the
deliverable" — three separate times. The object does not carry the exit code.
A caller that pipes stdout somewhere and reads the JSON has no field that tells it
whether the run succeeded, failed, or came back partial. It has to catch $?
separately, which is exactly the thing a single-object contract exists to avoid,
and which is unavailable to anything reading a stored out.json after the fact.
Verified
The schema. headlessOutcome, cmd/aforge/do.go:107-180. Every serialized
field, in order:
deliverable, artifacts, spend, spend_work, spend_overhead, nodes,
seconds, settled, blocked_on, learned, model, plan_model,
model_source, plan_model_source, subharness, error.
Sixteen fields, no exit_code.
Where the status actually lives. cmd/aforge/do.go:178:
status exitStatusUnexported, no struct tag — so json.Marshal skips it. The struct's own doc
comment two dozen lines above says "The verdict is the exit code", and the
verdict is the one thing the object omits.
Where the process exit status is decided. exitStatus is defined at
cmd/aforge/do.go:80 with exitFailed = 1 (:85) and exitPartial = 2 (:94).
It is assigned at five sites — do.go:336, :929, :939, :1026, :2009,
:2029 — and converted into the process's exit by errandStatus,
cmd/aforge/do.go:2478-2483, whose returned error is what the command exits on.
Where the JSON is printed. reportErrand, cmd/aforge/do.go:2425-2431:
if request.asJSON {
encoded, err := json.MarshalIndent(outcome, "", " ")
...
fmt.Fprintln(request.stdout, string(encoded))
return errandStatus(outcome)
}The status is in scope, on the very value being marshalled, one line before it is
turned into the exit code — and it is not in the bytes.
The stream never prints it either. The non-JSON footer is
cmd/aforge/do.go:2449-2451 and carries three things:
fmt.Fprintf(request.stdout, "%s · %s · $%.4f\n",
time.Duration(outcome.Seconds*float64(time.Second)).Round(time.Second),
plural(outcome.Nodes, "node"), outcome.Spend)i.e. 4m12s · 6 nodes · $0.0731. No verdict word, no code.
The documentation says the same thing, and is stale beyond this
docs/HEADLESS.md:205-218 prints a sample JSON object and :222-234 tabulates
every field. Neither has exit_code — and the sample is also missing
spend_work, spend_overhead, subharness and error, which the struct has
carried for some time. docs/HEADLESS.md:188-201 documents the settled/exit-code
matrix in prose only.
The manual page is internal/manual/chat/adaptive-runs.md, section "Running one
task without the screen — aforge do, headless, from a script: what flags it takes,
what it prints, and what its exit code means" (:88). It states the footer line
and the three exit codes at :126-128, and never says the JSON carries them —
correctly, because it does not. Under THE MANUAL LAW that page changes in the same
commit as the field.
Replication
# every field the object can carry, from the source of truth
sed -n '107,180p' cmd/aforge/do.go | grep -o 'json:"[^"]*"'
# ...and the one that has no tag
sed -n '176,180p' cmd/aforge/do.go
# what a caller actually gets
aforge do --json 'say hello' > out.json; echo "exit=$?"
jq 'has("exit_code")' out.json # falseShape of a fix
Add ExitCode int \json:"exit_code"`(always present, neveromitempty— an absent key is indistinguishable from an older binary, which is the reasoning the struct already applies toplan_modelandsubharness), set from outcome.statuswhere the object is marshalled, and updatedocs/HEADLESS.md's sample and table (including the four fields already missing from it) plus internal/manual/chat/adaptive-runs.md` in the same change.
From the aforge do worker trial (three 45-minute runs against #510 on dev
b95f8c29f): report at bench/worker-trial/REPORT.md on branch
trial/aforge-as-worker (local branch, not yet pushed to origin). Related: #510.
Queued for after the WIP freeze; do not start without the coordinator.
Drafted with CodeAF · reviewed and owned by the author
Activity
santoshkumarradha commentedon Sep 10, 2026
Consolidated into #815 — a run's ending is a receipt: the verdict, the waste, the words and the marks. This issue's evidence, replication and acceptance are reproduced there in full under its own heading, alongside the four others that share the reporting seam in
cmd/aforge/do.go; the lane that takes #815 takes this. Nothing is lost — this issue stays readable and #815 links back to it.Closed as part of the 2026-09-10 triage sweep, which folded five separately-filed complaints about what a headless run hands back into one piece of work. Verified at dev@95a0d0a9b that this one is still live.