Skip to content

fix(claude-code): stop treating successful answers as provider failures - #392

Merged
zpzjzj merged 4 commits into
alibaba:mainfrom
karanb192:fix/claude-success-provider-error
Nov 12, 2026
Merged

zpzjzj merged 4 commits into
alibaba:mainfrom
karanb192:fix/claude-success-provider-error

Conversation

@karanb192

@karanb192 karanb192 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Claude Code adapter scans stdout and the session's final message for phrases such as "rate limit", "too many requests" and "authentication error" on every result, including exit 0. With claude -p, stdout is the agent's answer, so a correct answer that mentions those words is reported as a provider failure:

  • Done. I added a rate limit of 100 requests per second to the API gateway and documented the 429 Too Many Requests response. becomes claude-code provider rate limit: ...
  • Fixed the authentication error handling in login.go becomes claude-code authentication failed: ...

The exit code is forced to 1, the case becomes ERROR, and the judge never runs. Any Skill about rate limiting, retries or login handling can hit this. The agent judge calls the same Run, so a judge that grades such a Skill is affected too.

Answer text is now scanned only when the run exits non-zero or the text is an error report. The same answers pass through, on Run and on resumed turns.

Related issues

None. Found while reading the adapter; small fix, so I went straight to a PR.

Changes

  • internal/agent/claude_code.go:
    • stderr is always scanned, as before.
    • stdout and the final message are scanned as before when the exit code is non-zero.
    • At exit 0 they are scanned only when the text is an error report:
      • its first or last line starts with API Error:;
      • it parses as a Claude Code JSON result event, alone or in an event array, with is_error: true;
      • it starts with the gateway notice 模型提供方限流.
    • If the session file ends with an API error entry (isApiErrorMessage, already parsed into an error-role transcript message), that text is scanned as well.
  • providerRateLimitText and providerAuthFailureText keep their matching rules.

Test plan

Checked on 56ded7d, based on 7814813, using Go 1.26.10 and the pinned lint tools.

  • Reproduce on unchanged main: the new Run and RunTurn tests fail for both example answers.
  • TestClaudeProviderSignals_AnswerText covers each path: prose at exit 0 and at exit 1, stderr, an API Error: first or last line, the gateway notice, a JSON result event with and without is_error, a session that ends with an API error, and a session that recovered from one. It also pins four answers that must pass: an error code named in prose, prose that starts with "API errors", the gateway notice quoted inside a sentence, and a JSON answer that only has an is_error field.
  • TestClaudeProviderSignals_SessionAPIError parses a synthetic session file with an isApiErrorMessage entry and checks that the error is found even though stdout has no API Error: line.
  • The existing provider-signal tests pass unchanged.
  • make verify
  • make test

Notes for reviewers

  • The test inputs are synthetic. I could not capture a live rate-limit or auth failure from the Claude CLI without a provider that returns one. The rules follow what the repo already treats as an error: the shapes pinned in the existing tests, and the API Error check in e2e/agent_test.go.
  • Two behaviors narrow on purpose at exit 0:
    1. An answer that only mentions one of the phrases, with no API Error: line and no API error entry in the session file, is no longer a failure.
    2. authentication_failed, "api_error_status":403 and the gateway notice no longer match in the middle of an answer. They still match in a JSON result event flagged is_error, at the start of the text (the notice), on stderr, and at a non-zero exit.
  • One boundary stays: a plain-text answer that is itself a Claude result event with is_error: true, for example a generated fixture, is still read as the CLI's own status. I kept that shape because TestProviderAuthFailureSignal expects it at exit 0 and buildClaudePrintJSONSessionResult is kept for the JSON output mode.
  • If your gateway returns a failure as plain text with exit 0 in some other wording, tell me the wording and I will add it.

Run and RunTurn scanned stdout and the session's final message for
phrases such as "rate limit" and "authentication error" on every
result, so an exit-0 answer that mentioned them was reported as a
provider failure and never judged. Scan answer text only when the run
exits non-zero or the text is an error report.
Match the exact "API Error:" line, parse the JSON result instead of
searching it for field names, and accept the gateway notice only in
place of an answer. Add a session-file test for a recorded API error.
A JSON answer that only has an is_error field is the agent's output, not
the CLI's status.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T14:54:57.900506Z 497c235 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

goconst counts a fourth "result" literal in the package.

@zpzjzj zpzjzj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zpzjzj
zpzjzj merged commit 4a220a7 into alibaba:main Nov 12, 2026
14 checks passed
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.

2 participants