Skip to content

CLI backend: auth errors surface as misleading pydantic parse failure #64

@max-tet

Description

@max-tet

Bug

When the CLI backend encounters an authentication error, the failure manifests as a confusing pydantic validation error instead of a clear auth failure message.

Root Cause

CliBackend.invoke() in claude.py does not treat is_error=True with exit code 0 as a fatal error. The Claude CLI exits with code 0 but sets is_error: true in the JSON output, with result containing the error text:

"Failed to authenticate. API Error: 401 {\"type\":\"error\",\"error\":{\"type\":\"authentication_error\",\"message\":\"Invalid authentication credentials\"},...}"

This result string is returned as output_text. The caller passes it to parse_response(), which extracts the embedded API error JSON object via _extract_json(), then fails pydantic validation — producing a log like:

Failed to parse preliminary plan response: LLM response failed validation for PreliminaryPlanResponse: 3 validation errors
...
Data: {'type': 'error', 'error': {'type': 'authentication_error', 'message': 'Invalid authentication credentials'}, ...}

Expected Behavior

An auth error should surface as a clear log message like "Claude CLI authentication failed" and the issue should be marked failed (or the tick skipped), not produce a pydantic parse failure.

Fix

In CliBackend.invoke(), after parsing the JSON output, check for is_error=True and inspect the result text for known fatal error patterns (authentication errors, "not logged in", etc.). Raise an appropriate exception or log clearly and propagate the failure before reaching parse_response().

Additionally, is_claude_available() should return False on auth errors (currently it only catches "not logged in" text, missing the "Failed to authenticate" pattern).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions