Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/azd/extensions/azure.coding-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ This can happen if your azd login token has expired. You can fix this by logging
azd auth login
```

You might also get this error if you have not run `azd init` first. To fix this, run `azd init` and go through the setup wizard. After this is completed, you should be able to run `azd coding-agent config`.

Comment on lines +83 to +84
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richardpark-msft , can we make the extension to return this as part of the error? or even make the extension to invoke azd init ?

Looking for a way to shift left this from happening to preventing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From talking with @bob-okeefe, it sounded like the steps he went through were:

  1. azd login
  2. Run the coding-agent extension
  3. Error back from AZD cred (internally) that says the refresh token is expired

So then he azd init'd and it worked.

Does azd init do something differently from azd login?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting.
It might make a difference if you were asked to pick a subscription - or if the azd init invoked the azd auth login

Do we have more details about the number 3? I what was trying to use the credential?

Any ideas @weikanglim ? -

But then, @richardpark-msft , there's not expectation from the extension around running azd init first? If not, we should not add this note and instead make this an issue/bug to investigate (try to repro).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was always asked to pick a subscription when I ran azd coding-agent config. I would choose my subscription and my repo. However when I got to the MI step and said to create a new MI it always failed. I was only able to resolve this after running azd init.

See attached.
image

When using debug I got this:
image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I only figured out that I had to run azd init because when I was using Copilot to troubleshoot this it suggested running azd env set AZURE_SUBSCRIPTION_ID . When I did this I got this error:

ERROR: no project exists; to create a new project, run azd init

After the azure.yml file was created I was able to run azd coding-agent config successfully

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently those errors are coming from when I call into the 'azd' PromptClient/PromptServiceClient:

I was wondering, at first, if perhaps I was messing up some subscription or passing in a bad credential, but this is within 'azd' itself.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then, @richardpark-msft , there's not expectation from the extension around running azd init first? If not, we should not add this note and instead make this an issue/bug to investigate (try to repro).

There isn't - I remember us talking about this. I don't use any azd logic to detect or use any project, so it should be safe.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you happen to have subscriptions across multiple tenants? I wonder if doing azd auth login --tenant <tenant-id> would've helped in this case. It's odd you still got an expired token error right after running azd auth login.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you ended up running azd env set AZURE_SUBSCRIPTION_ID xxxxxx ?
If yes, that's how it was fixed.
You had to run azd init ... but only to be able to run azd env set ... - to have an azd env where to set the sub-id.

A similar approach is to set AZURE_SUBSCRIPTION_ID as system env var (not at azd's env) and that would also work.

The issue is that azd is trying to use a token for the wrong tenant. When you set the sub-id, azd resolves the right tenant where that sub belongs to.

Even thought the extension is asking for a subscription, azd is not using the response to use that sub/tenant for the following events - instead it is using the credential provider which resolves to use a different token.
We need to make the extension to use the subId selected to re-set the credential provider - I'll see if that can be done (time to chat to the AI ...) - I'll be back to you...

Copy link
Copy Markdown
Member

@vhvb1989 vhvb1989 Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the hypothesis — the extension uses Subscription.TenantId (resource tenant) instead of Subscription.UserTenantId (user access tenant) when creating the AzureDeveloperCLICredential. For multi-tenant/guest users these differ, causing "refresh token expired" errors.

Filed #7077 with fix at #7078.

### Must have admin rights to Repository

Configuring a GitHub repository for the coding agent **requires** admin rights. Without these rights, you won't be able to update the Copilot environment to use managed identity credentials, or update the MCP configuration for the repository.
Expand Down
Loading