Skip to content

Commit 8e66f05

Browse files
Update the doc
1 parent 556ea93 commit 8e66f05

4 files changed

Lines changed: 110 additions & 10 deletions

File tree

‎CHANGES.md‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Login timeout fix moved to a separate branch
2+
3+
Commit "Add experimental device code login" originally moved
4+
`context.WithTimeout(ctx, loginTimeout)` above `u2m.NewPersistentAuth` in
5+
`cmd/auth/login.go`. That move also fixes an existing bug unrelated to device
6+
code login, so it now lives on its own branch.
7+
8+
## The bug
9+
10+
`PersistentAuth` stores the context it is constructed with, and `Challenge()`
11+
takes no context. On `main` the timeout context is created after
12+
`NewPersistentAuth`, so the browser login never sees the deadline and waits
13+
for the OAuth redirect indefinitely: `auth login --timeout` has no effect on
14+
the browser step. This was introduced in `e619b01cf` (#2076), which changed
15+
`persistentAuth.Challenge(ctx)` to `persistentAuth.Challenge()`. The discovery
16+
login (#4702) already creates the timeout context first.
17+
18+
## Where it went
19+
20+
Branch `login-timeout`, commit `0fe7e106c` ("Apply auth login --timeout to the
21+
browser login"), based on `origin/main` (`f5801e2e3`):
22+
23+
- `cmd/auth/login.go`: create the timeout context before `NewPersistentAuth`.
24+
- `acceptance/cmd/auth/login/timeout`: browser login with
25+
`BROWSER=echo_browser.py` (never completes the redirect) and `--timeout 1s`
26+
fails with `authorize: context deadline exceeded`. Without the fix the test
27+
hangs until the Go test timeout.
28+
29+
Draft PR: https://github.com/databricks/cli/pull/7103. The changelog fragment
30+
`.nextchanges/cli/auth-login-timeout.md` is in commit `cfe4a88bb`.
31+
32+
## What changed on this branch
33+
34+
The timeout move is removed from the first commit, `0c5cafec9` ("Add
35+
experimental device code login"), so `device-code` is independent of
36+
`login-timeout` for now and matches `main` for this hunk.
37+
38+
Until `device-code` is rebased on `login-timeout`, `--timeout` does not reach
39+
the device code flow either. The acceptance tests that depend on it are
40+
removed, from the commits that added them, for now:
41+
42+
- `acceptance/cmd/auth/login/use-device-code-timeout`, from "Fix device
43+
authorization login timeout": a 5s-delayed device authorization request must
44+
be cancelled by `--timeout 1s`. That commit was later dropped (see below),
45+
so this test is gone with it.
46+
- The "Login times out while waiting for the confirmation code" case in
47+
`acceptance/cmd/auth/login/use-device-code/script`, from `34ed39b8a` ("Add
48+
tests for device code login")
49+
(`sleep 3 | ... --use-device-code --timeout 1s`, expecting
50+
`reading confirmation code: context deadline exceeded`). Without the fix it
51+
ends with `reading confirmation code: EOF` once stdin closes. Its
52+
`output.txt` was regenerated, which also shifts the `device-code-N` numbers
53+
in the recorded requests by one.
54+
55+
The unit test `TestPromptForConfirmationCode_Timeout` stays: it passes the
56+
deadline to `promptForConfirmationCode` directly and does not depend on
57+
`login.go`.
58+
59+
## Dropped commits
60+
61+
Two follow-up commits were dropped from `device-code`. The old head with both
62+
is the local branch `backup/device-code-before-drop`.
63+
64+
- "Fix device authorization login timeout": sent the device authorization
65+
request with the login context, so `--timeout` cancels it. Not needed: the
66+
HTTP client of `PersistentAuth` already times the request out after 30s
67+
(`libs/auth/u2m/persistent_auth.go`), so it only mattered for `--timeout`
68+
values under 30s. It also moved the form submission shared with the token
69+
exchange into a helper (`postDeviceCodeForm`).
70+
- "Reject extra auth login arguments before profile resolution": added
71+
`Args: cobra.MaximumNArgs(1)` to `auth login`. That changes behavior for all
72+
`auth login` users: on `main`, `auth login HOST PROFILE` silently uses HOST
73+
and ignores PROFILE. It is a candidate for its own PR with a changelog
74+
entry. Without it, the `existingProfile != nil` guard in the device-code
75+
preflight check (folded into `0c5cafec9`) is what prevents the crash with two
76+
positional arguments, so keep the guard until the argument check lands.
77+
78+
## TODO: add the device code timeout test back
79+
80+
After rebasing `device-code` on `login-timeout`, re-add the "Login times out
81+
while waiting for the confirmation code" case to
82+
`acceptance/cmd/auth/login/use-device-code/script` (copy it from
83+
`backup/device-code-timeout-tests`, after the "no confirmation code" case) and
84+
run `./task test-update` for `cmd/auth/login`. Do not check out the whole
85+
directory from the backup: its script also has the two-argument case, which
86+
depends on the dropped argument check. `use-device-code-timeout` needs the
87+
dropped "Fix device authorization login timeout" commit, so it is not coming
88+
back. `docs/device-code-login.md` already documents the
89+
`context deadline exceeded` error, which is only accurate once the
90+
`login-timeout` fix is in.

‎cmd/auth/login.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,9 @@ func setHostAndAccountId(ctx context.Context, existingProfile *profile.Profile,
614614
return nil
615615
}
616616

617-
// isAccountOrUnifiedHost reports whether the target host requires an account ID
618-
// for OAuth URL construction. True for classic account hosts (accounts.*) and
619-
// for unified hosts detected via account-scoped DiscoveryURL.
617+
// isAccountOrUnifiedHost reports whether host is a classic account host
618+
// (accounts.* or accounts-dod.*) or a unified host with an account-scoped
619+
// discoveryURL.
620620
func isAccountOrUnifiedHost(host, discoveryURL string) bool {
621621
canonicalHost := (&config.Config{Host: host}).CanonicalHostName()
622622
if auth.IsClassicAccountHost(canonicalHost) {

‎cmd/auth/login_test.go‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,12 @@ func TestIsAccountOrUnifiedHost(t *testing.T) {
431431
discoveryURL string
432432
want bool
433433
}{
434-
{name: "classic accounts host", host: "https://accounts.cloud.databricks.com", want: true},
435-
{name: "accounts-dod host", host: "https://accounts-dod.databricks.com", want: true},
436-
{name: "accounts host with path", host: "https://accounts.cloud.databricks.com/some/path", want: true},
437-
{name: "plain workspace host", host: "https://workspace.cloud.databricks.com"},
438-
{name: "account-scoped DiscoveryURL", host: "https://spog.cloud.databricks.com", discoveryURL: "https://spog.cloud.databricks.com/oidc/accounts/acct-123/.well-known/oauth-authorization-server", want: true},
439-
{name: "workspace-scoped DiscoveryURL", host: "https://workspace.cloud.databricks.com", discoveryURL: "https://workspace.cloud.databricks.com/oidc/.well-known/oauth-authorization-server"},
440-
{name: "workspace host no signals", host: "https://workspace.cloud.databricks.com"},
434+
{name: "classic account host", host: "https://accounts.cloud.databricks.com", want: true},
435+
{name: "classic account host on accounts-dod", host: "https://accounts-dod.databricks.com", want: true},
436+
{name: "classic account host with path", host: "https://accounts.cloud.databricks.com/some/path", want: true},
437+
{name: "unified host with account-scoped discoveryURL", host: "https://spog.cloud.databricks.com", discoveryURL: "https://spog.cloud.databricks.com/oidc/accounts/acct-123/.well-known/oauth-authorization-server", want: true},
438+
{name: "workspace host", host: "https://workspace.cloud.databricks.com"},
439+
{name: "workspace host with workspace-scoped discoveryURL", host: "https://workspace.cloud.databricks.com", discoveryURL: "https://workspace.cloud.databricks.com/oidc/.well-known/oauth-authorization-server"},
441440
}
442441
for _, tc := range cases {
443442
t.Run(tc.name, func(t *testing.T) {

‎pyrefly.toml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
project-includes = [
2+
"**/*.py"
3+
]
4+
5+
project-excludes = []
6+
7+
search-path = []
8+
9+
disable-search-path-heuristics = true
10+
ignore-missing-imports = ["*"]
11+
ignore-errors-in-generated-code = true

0 commit comments

Comments
 (0)