You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9a1e083
Browse filesBrowse the repository at this point in the historyBrowse files
Tell AI agents to pass the device code login on to the user (#7235)
Stacked on #7220.
## Changes
When an AI agent is detected (`useragent.AgentProvider()`), device code
login prints a note after the user code that tells the agent to give the
URL and the code to the user, not to open the URL or approve the login
itself, and to ask the user for the confirmation code. In the
interactive login, the note also tells the agent to enter the code at
the `Confirmation code` prompt. Agent detection does not change the
flow.
The note uses the new `agent.AgentNote`, which `AgentNotice` now uses
too, with its text unchanged. The new `testutil.SetAgent` keeps the
agent running the tests out of them.
## Why
The login must be approved by the user, but an agent that runs it gets
the URL and the code and could try to approve it itself, or not pass it
on. Split out of #7220 to keep that PR smaller.
## Tests
The `device-code/non-interactive/nominal` acceptance test runs both
steps with `AGENT` set. `TestPromptForConfirmationCode_Agent` checks the
interactive note, and `libs/agent` tests cover `AgentNote` and
`AgentNotice`.
This pull request and its description were written by Isaac.
---------
Co-authored-by: Isaac <no-reply@databricks.com>
Error: token exchange: Invalid confirmation code (error code: invalid_request). Check the confirmation code and approve the login if you haven't, then rerun this command. Run the same command without --user-code and --confirmation-code to start a new login if it still fails
Error: token exchange: Invalid confirmation code (error code: invalid_request). Check the confirmation code and approve the login if you haven't, then rerun this command. Run the same command without --user-code and --confirmation-code to start a new login if it still fails
67
+
68
+
Note for AI agents (test-agent): ask the user to check the confirmation code
69
+
and to approve the login if they haven't. Do not approve it yourself
returnnil, fmt.Errorf("%w. Check the confirmation code and approve the login if you haven't, then rerun this command. %s if it still fails", err, startNewLoginHint)
257
+
err=fmt.Errorf("%w. Check the confirmation code and approve the login if you haven't, then rerun this command. %s if it still fails", err, startNewLoginHint)
258
+
// The agent runs this step, so the error above is addressed to it.
259
+
// Only the user may approve the login.
260
+
ifnote:=agent.AgentNote("ask the user to check the confirmation code\n"+
261
+
"and to approve the login if they haven't. Do not approve it yourself"); note!="" {
262
+
err=fmt.Errorf("%w\n\n%s", err, note)
263
+
}
264
+
returnnil, err
251
265
caseerrors.Is(err, u2m.ErrDeviceCodeRateLimited):
252
266
returnnil, fmt.Errorf("%w. Rerun this command later. %s if it still fails", err, startNewLoginHint)
253
267
caseerrors.Is(err, u2m.ErrInvalidDeviceCode):
@@ -291,7 +305,9 @@ func sameCode(a, b string) bool {
291
305
// and asks again.
292
306
funcpromptForConfirmationCode(ctx context.Context, da u2m.DeviceAuthorization, lastErrerror, attemptsLeftint) (string, error) {
0 commit comments