Skip to content

fix(providers): keep Claude CLI API errors on the non-streaming path - #1706

Open
pcbeingused33 wants to merge 2 commits into
nextlevelbuilder:devfrom
pcbeingused33:fix/claude-cli-nonstream-api-error
Open

pcbeingused33 wants to merge 2 commits into
nextlevelbuilder:devfrom
pcbeingused33:fix/claude-cli-nonstream-api-error

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Summary

Without streaming, the Claude CLI provider loses API errors. A failed turn that exits non-zero returns claude-cli: exit status 1 (stderr: ) with no cause, and a result flagged is_error with subtype: "success" that exits zero is returned as a normal answer (finish_reason: "stop").

Root cause: the CLI reports API errors in the result event on stdout. ChatStream already checks is_error and recovers the message, but Chat reads only stderr on failure, and parseJSONArray / parseSingleJSONResult check only subtype == "error".

Fix: both parsers also honor is_error, and when stderr is empty Chat adds the message from the failed result event to the returned error, preferring error over result as ChatStream does. A non-empty stderr is reported as before.

Type

  • Bug fix

Target Branch

dev

Checklist

  • go build ./... passes
  • go build -tags sqliteonly ./... passes
  • go vet passes (./internal/providers)
  • Tests pass: go test -race ./internal/providers/... (providers packages only)
  • No hardcoded secrets or credentials

Test Plan

New tests cover an is_error result in object and array form, and run Chat against a fake CLI script that prints a failed result and exits 1. They fail without the change and pass with it. The CLI output in the tests is simulated; no real Claude CLI call was made.

🤖 Generated with Claude Code

@clark-cant clark-cant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary: Extends the Claude CLI error-surfacing fix (stream path, #884) to the non-streaming Chat path: parseJSONArray and parseSingleJSONResult now honor is_error (which can be true with subtype success), and when stderr is empty Chat recovers the API error message from the result event on stdout.

Risk level: Low - 4 files, +89/-3, provider-internal, no API/DB/config surface, CI green (go, web, release-versioning).

Mandatory gates:

  • Duplicate / prior implementation: clear - #884/#885 fixed the stream path (commit 91d79ce); this is the matching non-streaming follow-up; no open PR overlaps.
  • Project standards: docs found (AGENTS.md, CONTRIBUTING.md) - base dev correct, conventional commit, tests included, Go conventions honored.
  • Strategic necessity: clear value - surfaces the real API error (e.g. 529 overloaded) instead of exit status 1 (stderr: ), reducing support toil.

Findings:

  • Critical: none.
  • Important: none.
  • Suggestion:
    1. cliResultError re-scans the output for the failed result event while parseJSONArray/parseSingleJSONResult already apply the same subtype==error || is_error predicate - the rule now lives in three places. Consider having the parsers surface the message (or share a helper) so it lives in one.
    2. Edge: an is_error result with empty result/error that exits 0 still falls through to the raw-text fallback in parseJSONResponse (returns the JSON blob as content with finish_reason stop). The zero-exit case is only fully covered when a message is present; a follow-up guard/test would close it.
    3. AGENTS.md asks for a Surface parity line on fixes; a one-liner (Surface parity: provider-internal, N/A) would keep the checklist honest. Cosmetic.

Verdict: Approve - no critical or important issues; the change mirrors the existing ChatStream handling and is well tested.

Posted by /ck:review-pr at 2026-11-29T01:08:26Z

@clark-cant clark-cant added agent:github-maintain Processed by github-maintain automation maintain:triaged Triaged by maintain workflow pr:reviewed Reviewed by maintainer labels Nov 29, 2026
@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Thanks for catching the zero-exit case. An empty is_error result now returns an explicit error on the non-streaming path, with regression tests for a JSON object, a JSON array, and an array with earlier assistant text. Could a maintainer review and approve this follow-up?

This comment was drafted with Claude Code.

@clark-cant clark-cant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary: Re-review of the follow-up commit 15d595b9 ("report empty Claude CLI result errors"). It closes the zero-exit gap flagged in the prior review: an is_error result event with an empty result/error now yields an explicit error on the non-streaming path, and parseJSONArray no longer falls back to assistant text once the result event has failed.

Risk level: Low - this commit touches 2 files (+55/-14), provider-internal, no API/DB/config surface, CI green (go, web, release-versioning).

Mandatory gates:

  • Duplicate / prior implementation: clear - follow-up to #884/#885 (stream path, commit 91d79ce); no overlapping open PR.
  • Project standards: docs found (AGENTS.md, CONTRIBUTING.md) - base dev correct, conventional commit, tests included, Go conventions honored.
  • Strategic necessity: clear - surfaces the real API error instead of exit status 1 / the raw JSON blob, reducing support toil.

Findings:

  • Critical: none.
  • Important: none.
  • Suggestion:
    1. parseJSONArray now discards accumulated assistant text whenever the result event is is_error (the finishReason != "error" guard), so a mid-stream API error that arrives after a partial answer returns result error (no message) and drops that partial text. Consider returning the partial text with FinishReason=error, or including it in the error, so callers do not silently lose content.
    2. The subtype == "error" || is_error predicate now lives in four places (parseJSONArray, parseSingleJSONResult, cliResultError, ChatStream) - a shared helper would keep the rule in one spot. (Carried over from the prior review.)
    3. AGENTS.md asks for a Surface parity line on fixes; a one-liner (Surface parity: provider-internal, N/A) would keep the checklist honest. Cosmetic.

Verdict: Approve - the follow-up correctly closes the zero-exit empty-message gap with regression tests for object, array, and array-with-assistant shapes; no critical or important issues.

Posted by /ck:review-pr at 2026-11-29T10:09:22Z

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

Labels

agent:github-maintain Processed by github-maintain automation maintain:triaged Triaged by maintain workflow pr:reviewed Reviewed by maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants