Skip to content

Page the model-services probe past an ACL-emptied first page - #464

Merged
david-siqi-liu merged 7 commits into
mainfrom
david/es-2185388-model-service-probe-pagination
Sep 2, 2026
Merged

Page the model-services probe past an ACL-emptied first page#464
david-siqi-liu merged 7 commits into
mainfrom
david/es-2185388-model-service-probe-pagination

Conversation

@david-siqi-liu

@david-siqi-liu david-siqi-liu commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

What did you change, and why?

ucode configure's model-service probe (_probe_ai_gateway_v3) listed /api/2.1/unity-catalog/model-services?page_size=1 and decided accessibility from that single page. Unity Catalog applies page_size before ACL filtering, so an early page can come back empty with only a next_page_token while accessible model services remain behind the cursor.

On the ai-devtools gateway workspace this made configure print:

✔ Unity AI Gateway detected
  Model service: reachable, no accessible model services returned; check USE CATALOG on system, and USE SCHEMA and EXECUTE on system.ai

even though the caller had 42 accessible model services and full grants. The hint sent users to fix Unity Catalog permissions that were already correct.

Fix

Page the model-services probe instead of trusting one page. _probe_ai_gateway_v3 now follows next_page_token (page size 50, bounded by a page cap) and resolves to one of four outcomes, tracked by a new conclusive flag on GatewayProbe:

  • an accessible model service is found on any page: resource_available;
  • the listing is walked to the end (no cursor) with nothing accessible: reachable, confirmed empty;
  • the first call fails: unreachable, with the reason;
  • a later page errors, or the page cap is hit with a cursor still pending: reachable but conclusive=False (the listing was not walked to a verdict, so we do not claim it is empty).

Don't let an unavailable fallback bury a reachable gateway. probe_unity_gateway_capabilities returns the reachable-but-inconclusive probe rather than raising "neither endpoint available": the model-services API answered, so the gateway is enabled even though the walk did not finish.

Missing-OAuth-scope 403s route to re-login, not to a grant hint — and only after the legacy fallback is attempted, since the model-service and legacy-endpoint APIs require different scopes. The classifier matches the OAuth-token wording specifically, so a PAT's permission 403 (which re-login cannot fix) is not misrouted and instead falls through to the grant guidance.

Trim the happy-path output. When an accessible model service is found, configure closes the spinner with ✔ Unity AI Gateway connected and drops the redundant model-service detail line. It prints a single warning line only when no model service was detected but the gateway is still usable (or the result is inconclusive); a hard failure still raises.

Also removed the now-unused empty_hint parameter from _gateway_probe_result.

Related: ES-2185388

How do you know it works?

Verified the built probe against three live workspaces:

  • ai-devtools gateway workspace (the reported case): the probe now resolves to an accessible model service, and configure closes the spinner with a success line:

    GatewayProbe: GatewayProbe(reachable=True, detail='reachable, accessible model service returned', resource_available=True, conclusive=True)
    --- what `ucode configure` prints for the gateway step ---
    ✔ Unity AI Gateway connected
    
  • CSP-enabled workspace with no model services (v3 reachable but genuinely empty; legacy endpoints disabled for CSP): still hard-fails with an actionable error rather than a false success:

    RuntimeError: Databricks Unity AI Gateway is not enabled on this workspace: neither model
    services (reachable, no accessible model services returned; check USE CATALOG on system, and
    USE SCHEMA and EXECUTE on system.ai) nor legacy endpoints (HTTP 404 Not Found:
    {"error_code":"FEATURE_DISABLED","message":"AI Gateway legacy endpoint is not available for
    CSP-enabled workspaces."...}) are available. See https://docs.databricks.com/aws/en/ai-gateway/overview-beta
    
  • A scope-limited token: probes the legacy fallback first, then returns re-login guidance instead of the UC-grant message.

Tests:

  • empty-first-page-plus-cursor finds an accessible service on a later page (the ES-2185388 repro);
  • exhausting the cursor reports confirmed-empty;
  • a later-page error and page-cap exhaustion are reachable-but-inconclusive, not empty;
  • an inconclusive probe does not hard-fail when the legacy endpoint is unavailable;
  • a scope 403 succeeds when the legacy endpoint is reachable, and routes to re-login when it is not;
  • the scope classifier matches the OAuth-token wording but not a PAT permission 403;
  • the happy path prints the success line without the model-service detail, and a warning line is printed only when no model service is detected.

test_databricks.py + test_cli.py pass (538). ruff check and ruff format --check clean.

`ucode configure`'s model-service probe listed with page_size=1 and judged
accessibility from that single page. Unity Catalog applies page_size before
ACL filtering, so an early page can return empty with only a next_page_token
while accessible model services remain behind the cursor. On the ai-devtools
gateway workspace this made configure report "no accessible model services
returned; check USE CATALOG ..." even though 42 model services were accessible.

Follow the cursor (page_size=50, bounded) before reporting empty, and route a
missing-OAuth-scope 403 to the re-login guidance instead of the UC-grant hint,
which does not apply to a token-scope failure.

Related: ES-2185388

Co-authored-by: Isaac <no-reply@databricks.com>
@david-siqi-liu
david-siqi-liu marked this pull request as ready for review September 2, 2026 19:48
david-siqi-liu and others added 3 commits September 2, 2026 20:01
Only report "no accessible model services" after walking the listing to the
end (no pending cursor). A later-page error or hitting the page cap with a
cursor still pending is now reachable-but-inconclusive, not empty.

Stop treating a model-service scope 403 as globally definitive: the model-
service and legacy-endpoint APIs require different OAuth scopes, so attempt the
legacy fallback first. Only when the fallback also fails is a missing-scope 403
surfaced, and then as re-login guidance rather than a UC-grant hint.

Co-authored-by: Isaac <no-reply@databricks.com>
…uth-only

A reachable-but-inconclusive model-service probe (later-page error or page cap)
no longer hard-fails as "gateway not enabled" when the legacy fallback is
unavailable: the API answered, so it is enabled. GatewayProbe carries an
explicit `conclusive` flag to separate "confirmed no accessible resource" from
"reachable, unknown", and the coordinator returns the probe in the inconclusive
case rather than raising.

Scope the missing-scope classifier to the OAuth-token wording so a PAT's
permission 403 is not misrouted to OAuth re-login guidance (which cannot fix a
PAT) and instead falls through to the grant hint.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
When the model-service probe finds an accessible model service, configure now
prints nothing about the gateway and moves on. It emits a single warning line
only when no model service was detected but the gateway is still usable (or the
result is inconclusive); a hard failure still raises. Drops the success header
that would otherwise appear only when something is off.

Co-authored-by: Isaac <no-reply@databricks.com>
Comment thread src/ucode/cli.py Outdated
Per review: when a model service is accessible, print "Unity AI Gateway
connected" as the spinner's success rather than nothing, while still dropping
the redundant model-service detail line. The warning path is unchanged.

Co-authored-by: Isaac <no-reply@databricks.com>
@lilly-luo

Copy link
Copy Markdown
Collaborator
RuntimeError: Databricks Unity AI Gateway is not enabled on this workspace: neither model
services (reachable, no accessible model services returned; check USE CATALOG on system, and
USE SCHEMA and EXECUTE on system.ai) nor legacy endpoints (HTTP 404 Not Found:
{"error_code":"FEATURE_DISABLED","message":"AI Gateway legacy endpoint is not available for
CSP-enabled workspaces."...}) are available. See https://docs.databricks.com/aws/en/ai-gateway/overview-beta

this error message isn't very user friendly. Can we have it say something like this? Just remove the part about legacy endpoints. OK to do in follow up sine this won't affect Isaac

Databricks Unity AI Gateway is not enabled for this workspace.

No accessible AI Gateway model services were found. This may mean that
AI Gateway is not enabled, or that you do not have the required permissions.

If you believe AI Gateway is enabled, verify that you have:
  - USE CATALOG on system
  - USE SCHEMA on system.ai
  - EXECUTE on system.ai

See: https://docs.databricks.com/aws/en/ai-gateway/overview-beta

Comment thread src/ucode/cli.py
@david-siqi-liu

Copy link
Copy Markdown
Collaborator Author
RuntimeError: Databricks Unity AI Gateway is not enabled on this workspace: neither model
services (reachable, no accessible model services returned; check USE CATALOG on system, and
USE SCHEMA and EXECUTE on system.ai) nor legacy endpoints (HTTP 404 Not Found:
{"error_code":"FEATURE_DISABLED","message":"AI Gateway legacy endpoint is not available for
CSP-enabled workspaces."...}) are available. See https://docs.databricks.com/aws/en/ai-gateway/overview-beta

this error message isn't very user friendly. Can we have it say something like this? Just remove the part about legacy endpoints. OK to do in follow up sine this won't affect Isaac

Databricks Unity AI Gateway is not enabled for this workspace.

No accessible AI Gateway model services were found. This may mean that
AI Gateway is not enabled, or that you do not have the required permissions.

If you believe AI Gateway is enabled, verify that you have:
  - USE CATALOG on system
  - USE SCHEMA on system.ai
  - EXECUTE on system.ai

See: https://docs.databricks.com/aws/en/ai-gateway/overview-beta

I don't think we can remove the part about legacy endpoints, as they are still valid use cases. Otherwise, we should only be probing for v3 and just not use v2.

@david-siqi-liu
david-siqi-liu enabled auto-merge (squash) September 2, 2026 21:26
@david-siqi-liu
david-siqi-liu merged commit c585b08 into main Sep 2, 2026
2 checks passed
@david-siqi-liu
david-siqi-liu deleted the david/es-2185388-model-service-probe-pagination branch September 2, 2026 21:32
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