Skip to content

fix(amazonq): add cancel support to loading developer profiles #940

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 2 commits into from
Apr 14, 2025

Conversation

awschristou
Copy link
Contributor

Problem

There can be some latency while loading developer profiles, caused by either a poor internet connection, a sluggish backend, or both. Clients need a way to cancel the request for loading profiles.

Solution

Wire in support for the Cancellation Token.

This change is being done in tandem with VS Toolkit change https://github.com/aws/aws-toolkit-visual-studio-staging/pull/2443

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@awschristou awschristou requested a review from a team as a code owner April 10, 2025 00:21
@@ -80,7 +80,7 @@ export const QConfigurationServerToken =
case Q_CONFIGURATION_SECTION:
;[customizations, developerProfiles] = await Promise.all([
serverConfigurationProvider.listAvailableCustomizations(),
serverConfigurationProvider.listAvailableProfiles(),
serverConfigurationProvider.listAvailableProfiles(token),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should cancel whole onGetConfigurationFromServer request and return RequestCanceled LSP Error from here to signal that client cancellation was handled by server correctly.

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#errorCodes

	 * The client has canceled a request and a server has detected
	 * the cancel.
	 */
	export const RequestCancelled: [integer](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#integer) = -32800;

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, we could for all switch cases here pass the token to a method e.g. handleTokenCancellation, which will throw a RequestCancelled error in case the request was cancelled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure -- I'm going to refrain from adding it to the Q_CUSTOMIZATIONS_CONFIGURATION_SECTION case statement, because customizations code currently does not support tokens.

@@ -73,6 +84,10 @@ async function fetchProfilesFromRegion(
do {
logging.debug(`Fetching profiles from region: ${region} (iteration: ${numberOfPages})`)

if (token.isCancellationRequested) {
return allRegionalProfiles
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think we could just return an empty list here, request might be cancelled after some profiles are already aggregated due to pagination and higher up we we will return an empty list after cancellation anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO this is a concern for the caller, whether the caller is within flare or from a client. In both places, the caller can decide what to do given that they have access to the token cancellation state.

@awschristou awschristou merged commit d07f79a into main Apr 14, 2025
6 checks passed
@awschristou awschristou deleted the awschristou/load-profile-cancel-support branch April 14, 2025 15:25
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.

3 participants