Skip to content

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
microsoft:mainfrom
nniiovoo:fix/claude-code-exec-cli-exit
Open

ni (nniiovoo) wants to merge 1 commit into
microsoft:mainfrom
nniiovoo:fix/claude-code-exec-cli-exit

Conversation

@nniiovoo

Copy link
Copy Markdown
Contributor

Fixes #482

_run_claude_code_cli_exec returned the CLI's stdout as the answer unless the exit code was non-zero and stdout was empty. In text mode claude -p prints error results like API Error: 529 ... or Execution error to stdout and exits 1. So with the claude_code_exec target 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 for codex_exec, cursor_exec and copilot_exec, and a non-zero exit isn't retried.

  • Trace: run_claude_code_exec still saves the trace of every attempt to claude_raw.txt and the summary/steps files, including an earlier SDK attempt in auto mode.
  • Message: shows stdout first, so a stderr notice doesn't hide the actual error.

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.

  • A fake CLI that prints 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.
  • In auto mode, a failed SDK attempt followed by a failed CLI call must keep both in claude_raw.txt.
  • A successful run is unchanged.

Full suite on macOS: 2634 passed. The 2 failures in tests/test_sleep_adopt_skill_subset.py also 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_error result exits 1.

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude_code_exec target uses a failed CLI call's "API Error: ..." text as the task's answer

1 participant