Skip to content

Commit a7e37a3

Browse files
committed
fix(amazonq): sagemaker instance detection fix and correcting glibc path
1 parent ebadabc commit a7e37a3

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Improved Amazon Linux 2 support with better SageMaker environment detection"
4+
}

packages/amazonq/src/extension.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
126126

127127
// This contains every lsp agnostic things (auth, security scan, code scan)
128128
await activateCodeWhisperer(extContext as ExtContext)
129-
if (
129+
130+
// Always activate LSP for SageMaker environments
131+
const shouldActivateLsp =
130132
(Experiments.instance.get('amazonqLSP', true) || Auth.instance.isInternalAmazonUser()) &&
131-
(!isAmazonLinux2() || hasGlibcPatch())
132-
) {
133+
(isSageMaker() || !isAmazonLinux2() || (await hasGlibcPatch()))
134+
135+
if (shouldActivateLsp) {
133136
// start the Amazon Q LSP for internal users first
134-
// for AL2, start LSP if glibc patch is found
137+
// for AL2, start LSP if glibc patch is found or if it's a SageMaker environment
135138
await activateAmazonqLsp(context)
136139
}
137140
if (!Experiments.instance.get('amazonqLSPInline', true)) {

packages/amazonq/src/lsp/client.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ import {
3636
undefinedIfEmpty,
3737
getOptOutPreference,
3838
isAmazonLinux2,
39+
fs,
3940
getClientId,
4041
extensionVersion,
4142
} from 'aws-core-vscode/shared'
42-
import { processUtils } from 'aws-core-vscode/shared'
43+
import { processUtils, isSageMaker } from 'aws-core-vscode/shared'
4344
import { activate } from './chat/activation'
4445
import { AmazonQResourcePaths } from './lspInstaller'
4546
import { ConfigSection, isValidConfigSection, pushConfigUpdate, toAmazonQLSPLogLevel } from './config'
@@ -53,11 +54,24 @@ import { InlineChatTutorialAnnotation } from '../app/inline/tutorials/inlineChat
5354
const localize = nls.loadMessageBundle()
5455
const logger = getLogger('amazonqLsp.lspClient')
5556

56-
export const glibcLinker: string = process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER || ''
57-
export const glibcPath: string = process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH || ''
57+
export async function hasGlibcPatch(): Promise<boolean> {
58+
// Skip GLIBC patching for SageMaker environments
59+
if (isSageMaker()) {
60+
getLogger('amazonqLsp').info('SageMaker environment detected in hasGlibcPatch, skipping GLIBC patching')
61+
return false // Return false to ensure SageMaker doesn't try to use GLIBC patching
62+
}
63+
64+
// Check for environment variables first (for CDM)
65+
const glibcLinker = process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER || ''
66+
const glibcPath = process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH || ''
5867

59-
export function hasGlibcPatch(): boolean {
60-
return glibcLinker.length > 0 && glibcPath.length > 0
68+
if (glibcLinker.length > 0 && glibcPath.length > 0) {
69+
getLogger('amazonqLsp').info('GLIBC patching environment variables detected')
70+
return true
71+
}
72+
73+
// Fall back to file check for other environments
74+
return await fs.exists('/opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2')
6175
}
6276

6377
export async function startLanguageServer(
@@ -82,9 +96,31 @@ export async function startLanguageServer(
8296
const traceServerEnabled = Settings.instance.isSet(`${clientId}.trace.server`)
8397
let executable: string[] = []
8498
// apply the GLIBC 2.28 path to node js runtime binary
85-
if (isAmazonLinux2() && hasGlibcPatch()) {
86-
executable = [glibcLinker, '--library-path', glibcPath, resourcePaths.node]
87-
getLogger('amazonqLsp').info(`Patched node runtime with GLIBC to ${executable}`)
99+
if (isSageMaker()) {
100+
// SageMaker doesn't need GLIBC patching
101+
getLogger('amazonqLsp').info('SageMaker environment detected, skipping GLIBC patching')
102+
executable = [resourcePaths.node]
103+
} else if (isAmazonLinux2() && (await hasGlibcPatch())) {
104+
// Use environment variables if available (for CDM)
105+
if (process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER && process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH) {
106+
executable = [
107+
process.env.VSCODE_SERVER_CUSTOM_GLIBC_LINKER,
108+
'--library-path',
109+
process.env.VSCODE_SERVER_CUSTOM_GLIBC_PATH,
110+
resourcePaths.node,
111+
]
112+
getLogger('amazonqLsp').info(`Patched node runtime with GLIBC using env vars to ${executable}`)
113+
}
114+
// Fall back to hardcoded path
115+
else {
116+
executable = [
117+
'/opt/vsc-sysroot/lib64/ld-linux-x86-64.so.2',
118+
'--library-path',
119+
'/opt/vsc-sysroot/lib64',
120+
resourcePaths.node,
121+
]
122+
getLogger('amazonqLsp').info(`Patched node runtime with GLIBC using hardcoded path to ${executable}`)
123+
}
88124
} else {
89125
executable = [resourcePaths.node]
90126
}

packages/core/src/shared/extensionUtilities.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ export function isCloud9(flavor: 'classic' | 'codecatalyst' | 'any' = 'any'): bo
176176
* @returns true if the current system is SageMaker(SMAI or SMUS)
177177
*/
178178
export function isSageMaker(appName: 'SMAI' | 'SMUS' = 'SMAI'): boolean {
179+
// Check for SageMaker-specific environment variables first
180+
if (
181+
process.env.SAGEMAKER_APP_TYPE !== undefined ||
182+
process.env.SERVICE_NAME === sageMakerUnifiedStudio ||
183+
process.env.SAGEMAKER_INTERNAL_IMAGE_URI !== undefined ||
184+
process.env.STUDIO_LOGGING_DIR?.includes('/var/log/studio') === true
185+
) {
186+
getLogger().debug('SageMaker environment detected via environment variables')
187+
return true
188+
}
189+
190+
// Fall back to app name checks
179191
switch (appName) {
180192
case 'SMAI':
181193
return vscode.env.appName === sageMakerAppname

0 commit comments

Comments
 (0)