Repository navigation
Description
What happened
2026-09-02, dev@2d4c4dde8, built with make build. aforge exec --json's failure
envelope says a run failed and never says why:
$ echo "say hi" | AFORGE_BASE_URL=http://127.0.0.1:1 OPENROUTER_API_KEY=nokey \
./bin/aforge exec --json --turns 1
{"text":"","stop":"error","usage":{"calls":0,"prompt_tokens":0,"completion_tokens":0,"cached_tokens":0,"cost":0},"artifacts":[],"turns":0,"elapsed_ms":121978}
$ echo $?
5
The only copy of the reason went to the error stream:
error: node task-1: after 3 node call attempts: after 3 attempts: execute request: Post "http://127.0.0.1:1/chat/completions": dial tcp 127.0.0.1:1: connect: connection refused
So a script reading exec's standard output — which is the whole point of --json —
can learn that the run failed and never why: a rejected model id, a missing
key, an unreachable endpoint and a wall all produce the identical object. The same is
true of the object written by -o file.
Its sibling already shipped the right shape. aforge do --json's envelope carries an
error field with the sentence, alongside a non-zero exit — headlessOutcome.Error,
set in failedErrand in cmd/aforge/do.go. exec never got it.
Replication
Deterministic (no model).
Nothing but the binary. No API key, no network, no fixture — AFORGE_BASE_URL points
at a port nothing listens on, so the call is refused locally:
make build
echo "say hi" | AFORGE_BASE_URL=http://127.0.0.1:1 OPENROUTER_API_KEY=nokey \
./bin/aforge exec --json --turns 1Today that prints the envelope quoted above: "stop":"error" and no field naming the
cause, exit 5. Budget about two minutes of wall time — the retry ladder waits out its
three attempts before the run gives up.
The same envelope, with the same hole, is what -o out.json writes.
Field (real models).
echo "say hi" | aforge exec --json --model nosuch/model-xyz with a real
OPENROUTER_API_KEY: the API returns 400 nosuch/model-xyz is not a valid model ID,
and the envelope on stdout is again "stop":"error" with nothing saying so. Seconds,
and no money — the call is rejected before any tokens are billed.
Where
cmd/aforge/exec.go: the execEnvelope struct (search json:"stop") has no error
field, and buildExecEnvelope (search func buildExecEnvelope) is called with the
outcome alone, so it never sees runErr. runExec prints runErr to stderr at the
line fmt.Fprintln(os.Stderr, "error:", runErr) and then builds the envelope from
outcome only — three writes of one fact (stdout, -o, stderr) from two sources.
The shape it should have had is headlessOutcome.Error in cmd/aforge/do.go, set in
failedErrand.
The fix
exec --json's failure envelope carries error: why the run did not work, in the
same words a person reads on the error stream, so a caller reading stdout and a caller
reading stderr are never told two different things about one failure.
- The field is
"error"withomitempty, so a run that produced an answer carries no
error key at all rather than an empty one — the emptiness law on a machine contract. - The envelope is built in one place —
buildExecEnvelope(outcome, runErr)— so
stdout,-oand stderr cannot disagree about a failure. - The single-leaf node id every error inside
execis wrapped with (node task-1:)
is machinery here: there is only ever the one node, and naming it pushes the cause
off the front of the line. It is stripped. - The exit code is unchanged: 5, as today.
Acceptance
- e2e: the deterministic replication above — the object on stdout carries a
non-emptyerrornamingconnection refused, alongside"stop":"error"and exit
5; the sentence in the field does not beginnode task-1:. - e2e: the control — a run that answers carries no
errorkey in its envelope
at all (grep -c '"error"'is 0) and exits 0. - Unit:
buildExecEnvelopeis the one place the envelope is built: given a
non-nilrunErrit fillsError, and given nil it leaves it empty and
json.Marshalomits the key. - The manual page that covers this quotes the new wording
(internal/manual/chat/adaptive-runs.md), and the change entry'sinvalidates
names what people believed before.
Drafted with CodeAF · reviewed and owned by the author
Activity
exec: --json says why the run failed (#522)
exec --json says why the run failed (#524)
bench: a real-issue manifest, and the preflight that refuses a false one
bench: derive the real-issue brief, and stop the manifest overstating it
bench: a real-issue manifest, and the preflight that refuses a false one
bench: derive the real-issue brief, and stop the manifest overstating it