fix(cli): stop async failure errors falling back to the whole poll response
Why
When an async command fails in machine mode, the error envelope's error field holds the failure detail, read from the poll response's declared error member (error by default, or the configured errorField). If the poll response did not contain that member, MachineErrorFields fell back to the whole poll response. A job that reached a failure state with no error detail in its body then put the entire poll payload, which can include large result data, into error, so agents parsing the field got an unrelated object instead of the error text.
The same fallback is the only diagnostic for two other async errors: CLI_ASYNC_UNKNOWN_STATE (the poll response reported a state the CLI does not recognise) and CLI_PROTOCOL when the poll response has no state at all. For those, the poll response is what tells the user what the server actually sent, so it must stay.
What changed
asyncRuntimeError.MachineErrorFieldsstill uses the declared member aserrorwhen the poll response object has it.- For
CLI_ASYNC_FAILED, when that member is missing, the poll response no longer replaceserror. The field keeps the error text (the same asmessage), as it does for every machine-mode error without more specific detail. The envelope still carries the reason, message,idandresume. - For every other async error reason (
CLI_ASYNC_UNKNOWN_STATE, missing-stateCLI_PROTOCOL), and for non-object payloads, the poll response is still passed through aserror.
Testing
TestAsyncMachineErrorOnlyIncludesDeclaredErrorMembercovers the default member, a declared member, a missing member, a non-object payload, and the unknown-state and protocol reasons keeping the payload.- Runtime test
TestAsyncMachineErrorDetailruns an async command end to end in agent mode against a local server and checks the stderr envelope:- a failure state with no error member: the poll response is absent and
errorequalsmessage; - an unrecognised state: the poll response is kept in
error; - a poll response with no state:
CLI_PROTOCOL, with the poll response kept inerror.
- a failure state with no error member: the poll response is absent and
- Each case fails against the code it guards (the failure case against
main, the unknown-state case against the first version of this PR, the missing-state case when the protocol error drops its payload, and theerrortext check when the field is cleared). TARGET=review make test-cli,TARGET=primary make test-cli,make check-template-cli,npm run format,go test ./pkg/generate/snapshots/ -run TestSnapCLIandgit diff --checkpass.make lintreports only an existing gofmt issue intemplates/perms.go, which this PR does not touch.
Public-safety check
- This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
- Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (
.claude/skills/public-repo-communication/SKILL.md). - Generated fixtures and review SDK changes are public-safe.
- I reviewed
git diff --check.