-
Notifications
You must be signed in to change notification settings - Fork 288
Fail fast on azd ai agent init when not logged in #7614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -127,6 +127,27 @@ func checkAiModelServiceAvailable(ctx context.Context, azdClient *azdext.AzdClie | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ensureLoggedIn verifies that the user is authenticated before any file-modifying | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // operations take place. It calls ListSubscriptions as a lightweight auth probe; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // only gRPC Unauthenticated errors are treated as failures. Other errors (e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // network issues) are ignored so they don't block init for unrelated reasons. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func ensureLoggedIn(ctx context.Context, azdClient *azdext.AzdClient) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _, err := azdClient.Account().ListSubscriptions(ctx, &azdext.ListSubscriptionsRequest{}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if st, ok := status.FromError(err); ok && st.Code() == codes.Unauthenticated { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return exterrors.Auth( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exterrors.CodeNotLoggedIn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "not logged in", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "run `azd auth login` to authenticate before running init", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+140
to
+146
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hardcoded At minimum, forwarding
Suggested change
Longer term, exporting |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+132
to
+147
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // only gRPC Unauthenticated errors are treated as failures. Other errors (e.g. | |
| // network issues) are ignored so they don't block init for unrelated reasons. | |
| func ensureLoggedIn(ctx context.Context, azdClient *azdext.AzdClient) error { | |
| _, err := azdClient.Account().ListSubscriptions(ctx, &azdext.ListSubscriptionsRequest{}) | |
| if err == nil { | |
| return nil | |
| } | |
| if st, ok := status.FromError(err); ok && st.Code() == codes.Unauthenticated { | |
| return exterrors.Auth( | |
| exterrors.CodeNotLoggedIn, | |
| "not logged in", | |
| "run `azd auth login` to authenticate before running init", | |
| ) | |
| } | |
| // gRPC Unauthenticated errors are treated as login failures, cancellation and | |
| // deadline errors are propagated, and other errors (e.g. network issues) are | |
| // ignored so they don't block init for unrelated reasons. | |
| func ensureLoggedIn(ctx context.Context, azdClient *azdext.AzdClient) error { | |
| _, err := azdClient.Account().ListSubscriptions(ctx, &azdext.ListSubscriptionsRequest{}) | |
| if err == nil { | |
| return nil | |
| } | |
| if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { | |
| return err | |
| } | |
| if st, ok := status.FromError(err); ok { | |
| if st.Code() == codes.Canceled || st.Code() == codes.DeadlineExceeded { | |
| return err | |
| } | |
| if st.Code() == codes.Unauthenticated { | |
| return exterrors.Auth( | |
| exterrors.CodeNotLoggedIn, | |
| "not logged in", | |
| "run `azd auth login` to authenticate before running init", | |
| ) | |
| } | |
| } |
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new fail-fast auth behavior via ensureLoggedIn is important user-facing flow control, but there’s no unit test asserting it. Consider adding a test that starts a minimal in-process gRPC server with AccountService.ListSubscriptions returning codes.Unauthenticated and verifies init errors out before doing any work; also cover the non-Unauthenticated path (should not block).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to arrange this after WaitForDebugger so debugging still works when logged out
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function
ensureLoggedin should not depend on trying to run one API that requires logged in.If there is not a unique API to check for auth, consider using the workflow api like in
azure-dev/cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers.go
Line 592 in 8472f78
You you can call
azd auth statushere