Skip to content

fix(client): report non-JSON cluster auth errors as RuntimeError - #6310

Merged
qinxuye merged 2 commits into
xorbitsai:mainfrom
David-Wu1119:fix/client-cluster-auth-error-detail
Dec 4, 2026
Merged

qinxuye merged 2 commits into
xorbitsai:mainfrom
David-Wu1119:fix/client-cluster-auth-error-detail

Conversation

@David-Wu1119

@David-Wu1119 David-Wu1119 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Bug

Client(base_url) checks GET /v1/cluster/auth in __init__. For a status other than 200 or 404, Client._check_cluster_authenticated builds its error from response.json()['detail']:

  • a plain-text or HTML error body, such as a reverse proxy's 502 page or a plain-text 403 from an IP allow-list in front of the server, makes Client() fail with requests.exceptions.JSONDecodeError;
  • a JSON error body without detail makes it fail with KeyError: 'detail'.

The intended RuntimeError("Failed to get cluster information, detail: ...") is never raised, so the user sees a JSON parsing error instead of the HTTP status. AsyncClient._check_cluster_authenticated and the other sync client calls already use _get_error_string(response), which falls back to the HTTP status line.

Fix

Use the server's JSON detail when there is one, and otherwise only "<status> <reason>". A JSON error with detail gives the same message as before. The status-line fallback is formatted directly rather than through _get_error_string, because that helper's own fallback is str(HTTPError), which includes the request URL and any credentials embedded in it.

Tests

  • New xinference/client/tests/test_sync_cluster_auth_error.py stubs requests.Session.get and builds Client against a 502 HTML page, a plain-text 403, a JSON 500 without detail, and a JSON 403 with detail. The client is built against http://user:secret@xinference.test. On main the first three fail (JSONDecodeError / KeyError) and the last passes; with this change all 4 raise RuntimeError with the status line or the server's detail, and the credentials appear in none of them.
  • test_sync_cluster_auth_error.py, test_sync_image_edit_cleanup.py, test_sync_stream_cleanup.py, test_common.py, test_async_error_detail.py and test_async_client_cleanup.py in xinference/client/tests: 124 passed.
  • pre-commit run --from-ref=origin/main --to-ref=HEAD passes.
  • Not run: no Xinference server was started; the HTTP response is stubbed. No docs describe this error, so none were changed.

Found by Gemini (through Google Antigravity) while comparing xinference's sync and async Python clients; Claude Code checked it, wrote the fix and the tests.

🤖 Generated with Claude Code

Client.__init__ checks /v1/cluster/auth and, for a status other than
200 or 404, built its RuntimeError from response.json()['detail']. A
plain-text or HTML error (a reverse proxy's 502, an IP allow-list 403)
made Client() fail with requests' JSONDecodeError, and a JSON error
without "detail" with KeyError, instead of "Failed to get cluster
information". Use _get_error_string, as the other client calls and
AsyncClient._check_cluster_authenticated do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 22:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 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-12-03T22:31:16.439534Z 4456866 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.

@qinxuye qinxuye 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.

The focused client suite passed all 124 tests on 44568668. I found one remaining issue in error formatting.

The fallback added in the previous commit used _get_error_string, whose
own fallback is str(HTTPError); that text includes the response URL, so
Basic Auth credentials embedded in the endpoint ended up in the
RuntimeError. Keep the server's JSON detail and otherwise report only
the status code and reason. The test now uses an endpoint with
credentials and checks that they are absent from the message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@qinxuye qinxuye 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.

LGTM

@qinxuye
qinxuye merged commit 125d94a into xorbitsai:main Dec 4, 2026
32 of 34 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.

3 participants