From 886ab292cddd903f3d42ef8b8535e5ef9cbcb1e5 Mon Sep 17 00:00:00 2001 From: Lei Gao <97199248+leigaol@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:56:00 -0800 Subject: [PATCH] config(amazonq): adjust timeout for supplemental context #5978 ## Problem The overall supplemental context has a timeout of 50ms, each sub promise has a timeout of 50ms. Problem is these 2 timeout are very tight, leaving no buffer time for node js runtime to do context switch. The poll interval of each sub promise is 10ms, which does not precisely timeout at 50ms. ## Solution Add a 10ms buffer time for supplemental context. Reduce poll duration --- packages/core/src/codewhisperer/util/editorContext.ts | 4 +++- .../util/supplementalContext/crossFileContextUtil.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/src/codewhisperer/util/editorContext.ts b/packages/core/src/codewhisperer/util/editorContext.ts index 1176eaea59e..4b58cb4f848 100644 --- a/packages/core/src/codewhisperer/util/editorContext.ts +++ b/packages/core/src/codewhisperer/util/editorContext.ts @@ -130,9 +130,11 @@ export async function buildGenerateRecommendationRequest(editor: vscode.TextEdit const fileContext = extractContextForCodeWhisperer(editor) const tokenSource = new vscode.CancellationTokenSource() + // the supplement context fetch mechanisms each has a timeout of supplementalContextTimeoutInMs + // adding 10 ms for overall timeout as buffer setTimeout(() => { tokenSource.cancel() - }, supplementalContextTimeoutInMs) + }, supplementalContextTimeoutInMs + 10) const supplementalContexts = await fetchSupplementalContext(editor, tokenSource.token) logSupplementalContext(supplementalContexts) diff --git a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts index 8ef6b9841cd..ee1a82b4cdc 100644 --- a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts +++ b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts @@ -71,13 +71,13 @@ export async function fetchSupplementalContextForSrc( async function () { return await fetchSupplementalContextForSrcV1(editor, cancellationToken) }, - { timeout: supplementalContextTimeoutInMs, interval: 10, truthy: false } + { timeout: supplementalContextTimeoutInMs, interval: 5, truthy: false } ) const promiseV2 = waitUntil( async function () { return await fetchSupplementalContextForSrcV2(editor) }, - { timeout: supplementalContextTimeoutInMs, interval: 10, truthy: false } + { timeout: supplementalContextTimeoutInMs, interval: 5, truthy: false } ) const [resultV1, resultV2] = await Promise.all([promiseV1, promiseV2]) return resultV2 ?? resultV1