Skip to content

Disambiguate AI Gateway probe failures by status code#87

Merged
rohita5l merged 2 commits into
mainfrom
fix-ai-gateway-v2-error-messages
May 26, 2026
Merged

Disambiguate AI Gateway probe failures by status code#87
rohita5l merged 2 commits into
mainfrom
fix-ai-gateway-v2-error-messages

Conversation

@rohita5l
Copy link
Copy Markdown
Collaborator

Summary

Diagnostic-only improvement for #84. ensure_ai_gateway_v2 previously 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 (often Invalid Token from a stale DATABRICKS_CONFIG_PROFILE shadowing --host) was only visible with
UCODE_DEBUG=1.

  • _http_get_json (databricks.py:194): append a 200-char body excerpt to the reason it returns, so callers and the user-visible error see Invalid Token without UCODE_DEBUG.
  • ensure_ai_gateway_v2 (databricks.py:826): branch on the reason —
    • 400 + body containing Invalid Token, or 401 / 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>"
    • anything else → generic probe-failed message with the body excerpt and docs link.

Does not fix the underlying DATABRICKS_CONFIG_PROFILE-shadowing---host bug — ucode configure still 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 skip
  • uv run ruff check . clean
  • 6 new tests in tests/test_databricks.py covering: 400 + Invalid Token, 401, 404, 400 without Invalid Token, and _http_get_json body surfacing in the reason

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 <noreply@anthropic.com>
@rohita5l rohita5l requested a review from AarushiShah-db May 26, 2026 15:09
@rohita5l rohita5l merged commit 026244f into main May 26, 2026
2 checks passed
@rohita5l rohita5l deleted the fix-ai-gateway-v2-error-messages branch May 26, 2026 16:52
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