From 0ac7f5ae6de8e7b94aacc4cc9e8f9c8eb2043ece Mon Sep 17 00:00:00 2001 From: Roo Code Date: Wed, 22 Oct 2025 17:57:14 +0000 Subject: [PATCH] fix: prevent extension from hanging when embedder service is unavailable - Made CodeIndexManager initialization non-blocking during extension activation - Added 5-second timeout to embedder validation to prevent indefinite hanging - Extension now loads successfully even if embedder service is missing Fixes #8777 --- src/extension.ts | 12 ++++++------ src/services/code-index/service-factory.ts | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 5db0996ad657..6ade64418b69 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -100,6 +100,7 @@ export async function activate(context: vscode.ExtensionContext) { const contextProxy = await ContextProxy.getInstance(context) // Initialize code index managers for all workspace folders. + // Make initialization non-blocking to prevent extension activation from hanging const codeIndexManagers: CodeIndexManager[] = [] if (vscode.workspace.workspaceFolders) { @@ -108,16 +109,15 @@ export async function activate(context: vscode.ExtensionContext) { if (manager) { codeIndexManagers.push(manager) + context.subscriptions.push(manager) - try { - await manager.initialize(contextProxy) - } catch (error) { + // Initialize in the background without blocking extension activation + // This prevents the extension from getting stuck if the embedder service is unavailable + manager.initialize(contextProxy).catch((error) => { outputChannel.appendLine( `[CodeIndexManager] Error during background CodeIndexManager configuration/indexing for ${folder.uri.fsPath}: ${error.message || error}`, ) - } - - context.subscriptions.push(manager) + }) } } } diff --git a/src/services/code-index/service-factory.ts b/src/services/code-index/service-factory.ts index 6d69e1f0b6c6..8bbb51483157 100644 --- a/src/services/code-index/service-factory.ts +++ b/src/services/code-index/service-factory.ts @@ -93,7 +93,23 @@ export class CodeIndexServiceFactory { */ public async validateEmbedder(embedder: IEmbedder): Promise<{ valid: boolean; error?: string }> { try { - return await embedder.validateConfiguration() + // Add a timeout to prevent hanging when the embedder service is unavailable + const VALIDATION_TIMEOUT_MS = 5000 // 5 seconds timeout + + const timeoutPromise = new Promise<{ valid: boolean; error: string }>((_, reject) => { + setTimeout(() => { + reject( + new Error( + "Failed to connect to the embedder service. Please check your connection settings and ensure the service is running.", + ), + ) + }, VALIDATION_TIMEOUT_MS) + }) + + const validationPromise = embedder.validateConfiguration() + + // Race between validation and timeout + return await Promise.race([validationPromise, timeoutPromise]) } catch (error) { // Capture telemetry for the error TelemetryService.instance.captureEvent(TelemetryEventName.CODE_INDEX_ERROR, {