Skip to content

fix(amazonq): Profile needing to be selected on server restart #7316

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

Merged
merged 6 commits into from
May 15, 2025

Conversation

nkomonen-amazon
Copy link
Contributor

@nkomonen-amazon nkomonen-amazon commented May 15, 2025

See individual commits for isolated changes

Problem

We were seeing the following errors from the Q Language Server on startup:

  • Amazon Q Profile is not selected for IDC connection type
  • Amazon Q service is not signed in

Solution

We needed to do 2 solutions, each is a separate commit (see their message). There were also some minor refactors.

In short:

  • The Auth bearer token MUST be sent to the Q LSP before Profile is sent. We were not doing this and it was causing an error
  • When sending the Auth to the Q LSP, the startUrl MUST be included in the request or else it would fail. We thought we were sending it but based on the logs prefixed with UpdateBearerToken it showedsso did not contain the startUrl

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

Problem:

Profiles and Customizations were pushed to the LSP before Auth was initialized (and its bearer token pushed to the LPS),
this caused errors since it does not make sense to push profile/customization if a bearer token does not exist.

Solution:

Ensure the bearer token is pushed first, then follow up with pushing the profile/customization after.

Signed-off-by: nkomonen-amazon <[email protected]>
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

Problem:

THe old way we got the startUrl did not return a value since the underlying
activeConnection in the Auth class was empty.

The activeConnection we actually want was in AuthUtil.

Solution:

Use the connection we get from AuthUtil as that is the most accurate one.

Signed-off-by: nkomonen-amazon <[email protected]>
@@ -114,11 +115,14 @@ export class AmazonQLspAuth {
.setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
.encrypt(encryptionKey)

const conn = AuthUtil.instance.conn
const startUrl = conn?.type === 'sso' ? conn.startUrl : undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just use AuthUtil.instance.startUrl here? I think previously we were using AuthUtil.instance.auth.startUrl which might have been causing the problem?

Copy link
Contributor Author

@nkomonen-amazon nkomonen-amazon May 15, 2025

Choose a reason for hiding this comment

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

Yeah that was the root, of it. I haven't updated the description but AuthUtil.instance.auth.startUrl is actually using Auth and not the one from AuthUtil. It looks like we never set an activeConnection in Auth so startUrl from there returns nothing.

Idk why this only broke now though

Signed-off-by: nkomonen-amazon <[email protected]>
@Hweinstock
Copy link
Contributor

Idk why this only broke now though

+1

@nkomonen-amazon nkomonen-amazon marked this pull request as ready for review May 15, 2025 02:26
@nkomonen-amazon nkomonen-amazon requested a review from a team as a code owner May 15, 2025 02:26
@Hweinstock
Copy link
Contributor

Ensure the bearer token is pushed first, then follow up with pushing the profile/customization after.

Is there any way we can enforce this with a test? Since this behavior is so critical its likely worth finding a way to ensure this doesn't accidentally get broken in the future. Or is this not worth it since this will be deleted by Flare migration soon?

Use the connection we get from AuthUtil as that is the most accurate one.

If these make it through the Flare Migration, we should invest time to rename this or find a way to make this more obvious, because as a consumer I would have no idea.

await activate(client, encryptionKey, resourcePaths.ui)
}
async function initializeAuth(client: LanguageClient): Promise<AmazonQLspAuth> {
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

technically this listener could trigger before we push the bearer token below in await auth.refreshConnection(true) right? Wouldn't that be problematic?

Copy link
Contributor Author

@nkomonen-amazon nkomonen-amazon May 15, 2025

Choose a reason for hiding this comment

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

From testing I haven't found a code path where this happens. This flow will be simplified in flare and I will revisit

@Hweinstock
Copy link
Contributor

potentially out of scope here, but the error message is deceiving. Failed to launch Amazon Q language server: Amazon Q service is not signed in implies the LS doesn't launch. However, it does launch, just in a bad authentication state.

@velatha
Copy link

velatha commented May 15, 2025

Did we always have this race condition or a regression that got introduced recently?

- Moves the profile/customization code up a level out of the LSP chat activation, since it doesn't make sense there
- Remove the previous onDidChangeProfile handler from the auth setup since it is redundant due to us having it already in onLanguageServerReady()
- Renamed function to onLanguageServerReady() to be more aligned with flare naming

Signed-off-by: nkomonen-amazon <[email protected]>
@Hweinstock
Copy link
Contributor

Hweinstock commented May 15, 2025

Did we always have this race condition or a regression that got introduced recently?

This is still unknown. I tried previous versions of the extension and language server this morning and still saw the same error so I suspect this isn't recent.

@nkomonen-amazon nkomonen-amazon merged commit 6898221 into aws:master May 15, 2025
27 of 31 checks passed
@nkomonen-amazon nkomonen-amazon deleted the profileCustomizationFix branch May 15, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants