Skip to content

Conversation

@opieter-aws
Copy link
Contributor

@opieter-aws opieter-aws commented May 6, 2025

Problem

Agentic chat introduced code changes that break auth on LSP

Solution

Fixes for the auth flow:

  • Move instantiation of AuthUtil into startLanguageServer sinc ethe function uses several AuthUtil calls, which fail if it is not instantiated yet
  • Remove the dependency of LSP on glibc patch, since auth doesn't work if LSP is not started
  • Add URL opening capability to the new ShowDocumentRequest handler, and remove the old handler from client.ts.
  • Fix bug where session isn't restored upon start of extension when SSO is expired.

  • 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.

@github-actions
Copy link

github-actions bot commented May 6, 2025

  • 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.

Comment on lines -133 to -140
if (
(Experiments.instance.get('amazonqLSP', true) || AuthUtil.instance.isInternalAmazonUser()) &&
(!isAmazonInternalOs() || (await hasGlibcPatch()))
) {
// start the Amazon Q LSP for internal users first
// for AL2, start LSP if glibc patch is found
await activateAmazonqLsp(context)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This setup doesn't work with auth on LSP, since the LSP needs to start for auth to work

Comment on lines -71 to -72
context.subscriptions.push(amazonq.focusAmazonQPanel.register(), amazonq.focusAmazonQPanelKeybinding.register())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now part of

amazonq.focusAmazonQPanel.register(),

const installResult = await new AmazonQLspInstaller().resolve()
return await lspSetupStage('launch', () => startLanguageServer(ctx, installResult.resourcePaths))
})
AuthUtil.create(new auth2.LanguageClientAuth(client, clientId, encryptionKey))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move instantiation of the AuthUtil singleton into startLanguageServer. The function uses several AuthUtil calls, which fail if it is not instantiated yet

Comment on lines 431 to 438
if (uri.scheme.startsWith('http')) {
try {
await openUrl(vscode.Uri.parse(params.uri))
return params
} catch (err: any) {
getLogger().error(`Failed to open http from LSP: error: %s`, err)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This functionality was added to enable LSP to open documents in agentic chat. We were relying on the same request type to open the auth URL we receive from LSP in the login flow

Comment on lines +91 to +93
if (!this.isConnected()) {
await this.refreshState()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ensures that a session is restored successfully upon start of the extension with expired SSO. If SSO is expired upon start of extension, the LSP throws an error. Since there is no state change in that case (notConnected > notConnected), we can't rely on the state change handler to trigger a login flow

@opieter-aws opieter-aws changed the title Feature/amazonq lsp auth @opieter-aws fix(amazonq): Bug fixes for LSP auth on agentic mode May 6, 2025
@opieter-aws opieter-aws changed the title @opieter-aws fix(amazonq): Bug fixes for LSP auth on agentic mode fix(amazonq): Bug fixes for LSP auth on agentic mode May 6, 2025
@opieter-aws opieter-aws closed this May 6, 2025
@opieter-aws opieter-aws reopened this May 6, 2025
@github-actions
Copy link

github-actions bot commented May 6, 2025

  • 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.

@opieter-aws opieter-aws marked this pull request as ready for review May 6, 2025 13:52
@opieter-aws opieter-aws requested review from a team as code owners May 6, 2025 13:52
notifications: true,
showSaveFileDialog: true,
},
q: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this can be dropped

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The merge with mainline made it duplicate, see line 140

@opieter-aws opieter-aws requested a review from jpinkney-aws May 6, 2025 14:39
@opieter-aws opieter-aws merged commit 8787af3 into aws:feature/amazonqLSP-auth May 6, 2025
12 of 22 checks passed
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.

2 participants