Disambiguate AI Gateway probe failures by status code#87
Merged
Conversation
Auth-shaped failures (400 Invalid Token / 401 / 403) now point users at re-login instead of the misleading "AI Gateway V2 not available" message; 404 keeps the docs-link guidance for genuinely-unprovisioned workspaces. The HTTP body is also surfaced in the bubbled reason so callers (and the user) see "Invalid Token" without UCODE_DEBUG=1. Co-Authored-By: Claude Opus 4.7 <[email protected]>
AarushiShah-db
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Diagnostic-only improvement for #84.
ensure_ai_gateway_v2previously collapsed every non-200 response into a single misleading error:"Databricks AI Gateway V2 is required but not available on this workspace (HTTP 400 Bad Request). See <docs>". The actual cause (oftenInvalid Tokenfrom a staleDATABRICKS_CONFIG_PROFILEshadowing--host) was only visible withUCODE_DEBUG=1._http_get_json(databricks.py:194): append a 200-char body excerpt to thereasonit returns, so callers and the user-visible error seeInvalid Tokenwithout UCODE_DEBUG.ensure_ai_gateway_v2(databricks.py:826): branch on the reason —400+ body containingInvalid Token, or401/403→"Databricks rejected the access token for <ws> ... Try: databricks auth logout / login --host <ws>"404→"Databricks Unity AI Gateway is not enabled on this workspace ... See <docs>"Does not fix the underlying
DATABRICKS_CONFIG_PROFILE-shadowing---hostbug —ucode configurestill fails in Dhruv's repro, just with an accurate, actionable error pointing at re-login. The env-var pop fix is deferred (since it overlaps with the profile-threading work in #86).Test plan
uv run pytest— 539 pass / 25 skipuv run ruff check .cleantests/test_databricks.pycovering: 400 +Invalid Token, 401, 404, 400 withoutInvalid Token, and_http_get_jsonbody surfacing in the reason