diff --git a/package-lock.json b/package-lock.json index aeff74a10f4..a055a8b0525 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11150,10 +11150,11 @@ "dev": true }, "node_modules/@aws/mynah-ui": { - "version": "4.35.4", - "resolved": "https://registry.npmjs.org/@aws/mynah-ui/-/mynah-ui-4.35.4.tgz", - "integrity": "sha512-LuOexbuMSKYCl/Qa7zj9d4/ueTLK3ltoYHeA0I7gOpPC/vYACxqjVqX6HPhNCE+L5zBKNMN2Z+FUaox+fYhvAQ==", + "version": "4.35.6", + "resolved": "https://registry.npmjs.org/@aws/mynah-ui/-/mynah-ui-4.35.6.tgz", + "integrity": "sha512-uIcskPAnsBySSoXH4cMgJ3IM1AxoMlXuo8s9llRnLa4dF8k0K0tcrvliygqkv4fHeO3TL9jolKg7Fc15ilBaSQ==", "hasInstallScript": true, + "license": "Apache License 2.0", "dependencies": { "escape-html": "^1.0.3", "highlight.js": "^11.11.0", @@ -25721,7 +25722,7 @@ "@aws-sdk/s3-request-presigner": "<3.731.0", "@aws-sdk/smithy-client": "<3.731.0", "@aws-sdk/util-arn-parser": "<3.731.0", - "@aws/mynah-ui": "^4.35.4", + "@aws/mynah-ui": "^4.35.6", "@gerhobbelt/gitignore-parser": "^0.2.0-9", "@iarna/toml": "^2.2.5", "@smithy/fetch-http-handler": "^5.0.1", diff --git a/packages/amazonq/.changes/next-release/Bug Fix-sagemaker-al2-support.json b/packages/amazonq/.changes/next-release/Bug Fix-sagemaker-al2-support.json new file mode 100644 index 00000000000..9f15457f59e --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-sagemaker-al2-support.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Improved Amazon Linux 2 support with better SageMaker environment detection" +} diff --git a/packages/amazonq/src/extension.ts b/packages/amazonq/src/extension.ts index 65caea3b2c8..55c22f0422e 100644 --- a/packages/amazonq/src/extension.ts +++ b/packages/amazonq/src/extension.ts @@ -126,12 +126,15 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is // This contains every lsp agnostic things (auth, security scan, code scan) await activateCodeWhisperer(extContext as ExtContext) - if ( + + // Always activate LSP for SageMaker environments + const shouldActivateLsp = (Experiments.instance.get('amazonqLSP', true) || Auth.instance.isInternalAmazonUser()) && - (!isAmazonLinux2() || hasGlibcPatch()) - ) { + (isSageMaker() || !isAmazonLinux2() || (await hasGlibcPatch())) + + if (shouldActivateLsp) { // start the Amazon Q LSP for internal users first - // for AL2, start LSP if glibc patch is found + // for AL2, start LSP if glibc patch is found or if it's a SageMaker environment await activateAmazonqLsp(context) } if (!Experiments.instance.get('amazonqLSPInline', true)) { diff --git a/packages/amazonq/src/lsp/client.ts b/packages/amazonq/src/lsp/client.ts index c359ac73ded..34b913d59ec 100644 --- a/packages/amazonq/src/lsp/client.ts +++ b/packages/amazonq/src/lsp/client.ts @@ -39,7 +39,7 @@ import { getClientId, extensionVersion, } from 'aws-core-vscode/shared' -import { processUtils } from 'aws-core-vscode/shared' +import { processUtils, isSageMaker } from 'aws-core-vscode/shared' import { activate } from './chat/activation' import { AmazonQResourcePaths } from './lspInstaller' import { ConfigSection, isValidConfigSection, pushConfigUpdate, toAmazonQLSPLogLevel } from './config' @@ -53,11 +53,24 @@ import { InlineChatTutorialAnnotation } from '../app/inline/tutorials/inlineChat const localize = nls.loadMessageBundle() const logger = getLogger('amazonqLsp.lspClient') -export const glibcLinker: string = process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER || '' -export const glibcPath: string = process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH || '' +export async function hasGlibcPatch(): Promise { + // Skip GLIBC patching for SageMaker environments + if (isSageMaker()) { + getLogger('amazonqLsp').info('SageMaker environment detected in hasGlibcPatch, skipping GLIBC patching') + return false // Return false to ensure SageMaker doesn't try to use GLIBC patching + } + + // Check for environment variables (for CDM) + const glibcLinker = process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER || '' + const glibcPath = process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH || '' + + if (glibcLinker.length > 0 && glibcPath.length > 0) { + getLogger('amazonqLsp').info('GLIBC patching environment variables detected') + return true + } -export function hasGlibcPatch(): boolean { - return glibcLinker.length > 0 && glibcPath.length > 0 + // No environment variables, no patching needed + return false } export async function startLanguageServer( @@ -82,9 +95,24 @@ export async function startLanguageServer( const traceServerEnabled = Settings.instance.isSet(`${clientId}.trace.server`) let executable: string[] = [] // apply the GLIBC 2.28 path to node js runtime binary - if (isAmazonLinux2() && hasGlibcPatch()) { - executable = [glibcLinker, '--library-path', glibcPath, resourcePaths.node] - getLogger('amazonqLsp').info(`Patched node runtime with GLIBC to ${executable}`) + if (isSageMaker()) { + // SageMaker doesn't need GLIBC patching + getLogger('amazonqLsp').info('SageMaker environment detected, skipping GLIBC patching') + executable = [resourcePaths.node] + } else if (isAmazonLinux2() && (await hasGlibcPatch())) { + // Use environment variables if available (for CDM) + if (process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER && process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH) { + executable = [ + process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER, + '--library-path', + process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH, + resourcePaths.node, + ] + getLogger('amazonqLsp').info(`Patched node runtime with GLIBC using env vars to ${executable}`) + } else { + // No environment variables, use the node executable directly + executable = [resourcePaths.node] + } } else { executable = [resourcePaths.node] } diff --git a/packages/core/package.json b/packages/core/package.json index d1287b5db07..441c16f86d0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -526,7 +526,7 @@ "@aws-sdk/s3-request-presigner": "<3.731.0", "@aws-sdk/smithy-client": "<3.731.0", "@aws-sdk/util-arn-parser": "<3.731.0", - "@aws/mynah-ui": "^4.35.4", + "@aws/mynah-ui": "^4.35.6", "@gerhobbelt/gitignore-parser": "^0.2.0-9", "@iarna/toml": "^2.2.5", "@smithy/fetch-http-handler": "^5.0.1", diff --git a/packages/core/src/shared/extensionUtilities.ts b/packages/core/src/shared/extensionUtilities.ts index 9675f060951..f69abca3de7 100644 --- a/packages/core/src/shared/extensionUtilities.ts +++ b/packages/core/src/shared/extensionUtilities.ts @@ -176,6 +176,18 @@ export function isCloud9(flavor: 'classic' | 'codecatalyst' | 'any' = 'any'): bo * @returns true if the current system is SageMaker(SMAI or SMUS) */ export function isSageMaker(appName: 'SMAI' | 'SMUS' = 'SMAI'): boolean { + // Check for SageMaker-specific environment variables first + if ( + process.env.SAGEMAKER_APP_TYPE !== undefined || + process.env.SERVICE_NAME === sageMakerUnifiedStudio || + process.env.SAGEMAKER_INTERNAL_IMAGE_URI !== undefined || + process.env.STUDIO_LOGGING_DIR?.includes('/var/log/studio') === true + ) { + getLogger().debug('SageMaker environment detected via environment variables') + return true + } + + // Fall back to app name checks switch (appName) { case 'SMAI': return vscode.env.appName === sageMakerAppname