From 9f70322c78b287b856dc39933bf9ac251d2319a8 Mon Sep 17 00:00:00 2001 From: Qianhao Zhang Date: Wed, 11 Nov 2026 22:26:29 +0000 Subject: [PATCH 1/3] auth login: cap the optional workspace lookup at 5s and explain the fallback On a unified host, `databricks auth login` lists account workspaces to populate a picker. When that call returned 503 the SDK retried for its default ~5 minutes with no output before falling back to the manual workspace ID prompt. The lookup is best-effort, so bound its retry and HTTP budget to 5 seconds, print a progress line, and show why it fell back along with the non-interactive `--host "?w="` form. Co-authored-by: Isaac --- cmd/auth/export_test.go | 7 +++++++ cmd/auth/login.go | 11 +++++++++++ cmd/auth/login_workspace_test.go | 19 +++++++++++++++++++ .../01-initial.golden | 1 + 4 files changed, 38 insertions(+) diff --git a/cmd/auth/export_test.go b/cmd/auth/export_test.go index ad363a491ac..e5476625f4a 100644 --- a/cmd/auth/export_test.go +++ b/cmd/auth/export_test.go @@ -4,3 +4,10 @@ var ( NewWorkspaceSearcher = newWorkspaceSearcher PromptForWorkspaceSelection = promptForWorkspaceSelection ) + +// SetWorkspaceListTimeoutSeconds overrides the workspace lookup budget and returns a restore func. +func SetWorkspaceListTimeoutSeconds(seconds int) func() { + previous := workspaceListTimeoutSeconds + workspaceListTimeoutSeconds = seconds + return func() { workspaceListTimeoutSeconds = previous } +} diff --git a/cmd/auth/login.go b/cmd/auth/login.go index 067d9e6f7be..dc67113db24 100644 --- a/cmd/auth/login.go +++ b/cmd/auth/login.go @@ -1054,6 +1054,10 @@ func u2mResourcesFromProfile(p *profile.Profile) []string { return splitScopes(p.Resources) } +// workspaceListTimeoutSeconds bounds the optional workspace lookup during login. +// It is a variable only so tests can shorten it. +var workspaceListTimeoutSeconds = 5 + // promptForWorkspaceSelection lists workspaces for a SPOG account and lets the // user pick one. Returns the selected workspace ID or empty string if skipped. // This is best-effort: errors are returned to the caller for logging, not shown @@ -1068,14 +1072,21 @@ func promptForWorkspaceSelection(ctx context.Context, authArguments *auth.AuthAr Host: authArguments.Host, AccountID: authArguments.AccountID, Credentials: config.NewTokenSourceStrategy("login-token", authconv.AuthTokenSource(tokenSource)), + + // The workspace list is only a convenience with a manual fallback, so + // don't spend the SDK's default 5 minute retry budget on a 503 here. + HTTPTimeoutSeconds: workspaceListTimeoutSeconds, + RetryTimeoutSeconds: workspaceListTimeoutSeconds, }) if err != nil { return "", err } + cmdio.LogString(ctx, "Looking up workspaces for your account...") workspaces, err := a.Workspaces.List(ctx) if err != nil { log.Debugf(ctx, "Failed to load workspaces (this can happen if the user has no account-level access): %v", err) + cmdio.LogString(ctx, "Could not list workspaces for this account. To skip this step, pass a host with the workspace ID, e.g. --host \"?w=\".") return promptForWorkspaceID(ctx) } diff --git a/cmd/auth/login_workspace_test.go b/cmd/auth/login_workspace_test.go index b3b83ce1d19..b5ec553fcac 100644 --- a/cmd/auth/login_workspace_test.go +++ b/cmd/auth/login_workspace_test.go @@ -235,6 +235,25 @@ func TestPromptForWorkspaceSelectionListError(t *testing.T) { } } +func TestPromptForWorkspaceSelectionGivesUpQuicklyOnUnavailable(t *testing.T) { + t.Cleanup(authcmd.SetWorkspaceListTimeoutSeconds(1)) + args, requests := newWorkspaceListServer(t, http.StatusServiceUnavailable, nil) + start := time.Now() + tm := termtest.Run(t, func(ctx context.Context) (string, error) { + return authcmd.PromptForWorkspaceSelection(ctx, args, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: workspaceTestToken})) + }) + tm.WaitFor(workspaceIDPrompt) + // The SDK's default retry budget is 5 minutes; the lookup must fall back well before that. + assert.Less(t, time.Since(start), 30*time.Second) + tm.Type("123456" + termtest.KeyEnter) + id, err := tm.Result() + require.NoError(t, err) + assert.Equal(t, "123456", id) + assert.Positive(t, requests.Load()) + assert.Contains(t, tm.Raw(), "Looking up workspaces") + assert.Contains(t, tm.Raw(), "?w=") +} + // newWorkspaceListServer exercises the SDK's actual list decoding without a live account. func newWorkspaceListServer(t *testing.T, status int, workspaces []provisioning.Workspace) (*auth.AuthArguments, *atomic.Int32) { t.Helper() diff --git a/cmd/auth/testdata/TestPromptForWorkspaceSelectionNoResults/01-initial.golden b/cmd/auth/testdata/TestPromptForWorkspaceSelectionNoResults/01-initial.golden index 66cd29acfdb..30481eb4fb5 100644 --- a/cmd/auth/testdata/TestPromptForWorkspaceSelectionNoResults/01-initial.golden +++ b/cmd/auth/testdata/TestPromptForWorkspaceSelectionNoResults/01-initial.golden @@ -1,3 +1,4 @@ +Looking up workspaces for your account... Search: █ ? Select a workspace (search by name or ID): ▸ Alpha (111) From d148f1008f03e0e6507f1ef499b8438333a5be27 Mon Sep 17 00:00:00 2001 From: Qianhao Zhang Date: Wed, 11 Nov 2026 23:48:34 +0000 Subject: [PATCH 2/3] Add changelog fragment for auth login workspace lookup timeout Co-authored-by: Isaac --- .nextchanges/cli/auth-login-workspace-lookup-timeout.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/cli/auth-login-workspace-lookup-timeout.md diff --git a/.nextchanges/cli/auth-login-workspace-lookup-timeout.md b/.nextchanges/cli/auth-login-workspace-lookup-timeout.md new file mode 100644 index 00000000000..44816c1163b --- /dev/null +++ b/.nextchanges/cli/auth-login-workspace-lookup-timeout.md @@ -0,0 +1 @@ +* `databricks auth login` now gives up on the optional workspace lookup after about 5 seconds instead of retrying for about 5 minutes, and explains the fallback to the manual workspace ID prompt ([#7522](https://github.com/databricks/cli/pull/7522)). ([#7522](https://github.com/databricks/cli/pull/7522)) From e55d5d9ff41130cb64898a2291fec8332a10d4d1 Mon Sep 17 00:00:00 2001 From: Qianhao Zhang Date: Wed, 11 Nov 2026 23:49:01 +0000 Subject: [PATCH 3/3] Fix changelog fragment link placement Co-authored-by: Isaac --- .nextchanges/cli/auth-login-workspace-lookup-timeout.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/auth-login-workspace-lookup-timeout.md b/.nextchanges/cli/auth-login-workspace-lookup-timeout.md index 44816c1163b..5ed6d0c31ae 100644 --- a/.nextchanges/cli/auth-login-workspace-lookup-timeout.md +++ b/.nextchanges/cli/auth-login-workspace-lookup-timeout.md @@ -1 +1 @@ -* `databricks auth login` now gives up on the optional workspace lookup after about 5 seconds instead of retrying for about 5 minutes, and explains the fallback to the manual workspace ID prompt ([#7522](https://github.com/databricks/cli/pull/7522)). ([#7522](https://github.com/databricks/cli/pull/7522)) +* `databricks auth login` now gives up on the optional workspace lookup after about 5 seconds instead of retrying for about 5 minutes, and explains the fallback to the manual workspace ID prompt. ([#7522](https://github.com/databricks/cli/pull/7522))