Repository navigation
fix(model): treat a non-zero Claude Code CLI exit as a failed target call - #483
Open
ni (nniiovoo) wants to merge 1 commit into
Open
ni (nniiovoo) wants to merge 1 commit into
ni (nniiovoo) wants to merge 1 commit into
Conversation
…call In text mode `claude -p` prints error results such as "API Error: 529 ..." or "Execution error" to stdout and exits 1. The claude_code_exec target returned that text as the answer unless stdout was also empty, so it was scored and passed to reflection. A non-zero exit now raises, as codex_exec, cursor_exec and copilot_exec already do, and the trace of every attempt is still saved. The message shows stdout first so a stderr notice cannot hide the error. Fixes microsoft#482 Signed-off-by: NNIIOVO <haimingni44@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #482
_run_claude_code_cli_execreturned the CLI's stdout as the answer unless the exit code was non-zero and stdout was empty. In text modeclaude -pprints error results likeAPI Error: 529 ...orExecution errorto stdout and exits 1. So with theclaude_code_exectarget in CLI mode, that text became the task's final answer and was scored and reflected on.Now any non-zero exit raises
RuntimeError("Claude Code CLI failed with exit code N: ..."). The rollout records a failed item, the same way it already does forcodex_exec,cursor_execandcopilot_exec, and a non-zero exit isn't retried.run_claude_code_execstill saves the trace of every attempt toclaude_raw.txtand the summary/steps files, including an earlier SDK attempt inautomode.One trade-off: if Claude Code can't save its session transcript (disk full or over quota), it exits 1 even when it has printed an answer. That item is now recorded as failed too, and the output is still in
claude_raw.txt.Tests: new
tests/test_claude_code_exec_cli_exit.py.API Error: 529 ...and exits 1 must make the call raise after one CLI call, and the trace must be kept. This test fails on main, where the error text is returned.automode, a failed SDK attempt followed by a failed CLI call must keep both inclaude_raw.txt.Full suite on macOS: 2634 passed. The 2 failures in
tests/test_sleep_adopt_skill_subset.pyalso fail on main.I checked the exit behaviour against the installed Claude Code 2.1.326: in text mode the error result is printed to stdout, and an
is_errorresult exits 1.