From 5518a1387b6c1629bf3ecf6f5431daa2e406cb88 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Mon, 28 Oct 2024 14:06:23 -0700 Subject: [PATCH 1/5] limit maximum size of supplementalContext being sent --- packages/core/src/codewhisperer/models/constants.ts | 1 + .../util/supplementalContext/crossFileContextUtil.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/packages/core/src/codewhisperer/models/constants.ts b/packages/core/src/codewhisperer/models/constants.ts index 846d9117066..82c252ef2ed 100644 --- a/packages/core/src/codewhisperer/models/constants.ts +++ b/packages/core/src/codewhisperer/models/constants.ts @@ -712,6 +712,7 @@ export const crossFileContextConfig = { numberOfChunkToFetch: 60, topK: 3, numberOfLinesEachChunk: 50, + maximumTotalLength: 10240, } export const utgConfig = { diff --git a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts index 1c4bd4637ba..92afe186a97 100644 --- a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts +++ b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts @@ -132,14 +132,20 @@ export async function fetchSupplementalContextForSrcV1( // Step 4: Transform best chunks to supplemental contexts const supplementalContexts: CodeWhispererSupplementalContextItem[] = [] + let totalLength = 0 for (const chunk of bestChunks) { throwIfCancelled(cancellationToken) + if (totalLength > crossFileContextConfig.maximumTotalLength) { + break + } + supplementalContexts.push({ filePath: chunk.fileName, content: chunk.nextContent, score: chunk.score, }) + totalLength += chunk.nextContent.length } // DO NOT send code chunk with empty content From ef1f17407157956aab3749e5f313554fc89f4f7a Mon Sep 17 00:00:00 2001 From: Will Lo Date: Mon, 28 Oct 2024 14:12:59 -0700 Subject: [PATCH 2/5] update constant --- .../Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json | 4 ++++ packages/core/src/codewhisperer/models/constants.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json diff --git a/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json b/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json new file mode 100644 index 00000000000..f1585599327 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Fix potential validatiokn exception thrown from service if plugins send out supplementalContext with length greather than 10240 characters long" +} diff --git a/packages/core/src/codewhisperer/models/constants.ts b/packages/core/src/codewhisperer/models/constants.ts index 82c252ef2ed..92c51509a2f 100644 --- a/packages/core/src/codewhisperer/models/constants.ts +++ b/packages/core/src/codewhisperer/models/constants.ts @@ -712,7 +712,7 @@ export const crossFileContextConfig = { numberOfChunkToFetch: 60, topK: 3, numberOfLinesEachChunk: 50, - maximumTotalLength: 10240, + maximumTotalLength: 20480, } export const utgConfig = { From 809b40925eb865757ceb0c56ef1c74dbdd49b15d Mon Sep 17 00:00:00 2001 From: Will Lo Date: Mon, 28 Oct 2024 14:27:01 -0700 Subject: [PATCH 3/5] patch --- .../Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json b/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json index f1585599327..6193f68fb18 100644 --- a/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json +++ b/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json @@ -1,4 +1,4 @@ { "type": "Bug Fix", - "description": "Fix potential validatiokn exception thrown from service if plugins send out supplementalContext with length greather than 10240 characters long" + "description": "Fix error thrown if plugins send out supplementalContext with the length greather than 10240 characters" } From cfd0e875087b1fb24d8d4b130eb8b1954501e99c Mon Sep 17 00:00:00 2001 From: Will Lo Date: Mon, 28 Oct 2024 14:41:23 -0700 Subject: [PATCH 4/5] address comments --- .../Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json | 2 +- .../util/supplementalContext/crossFileContextUtil.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json b/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json index 6193f68fb18..28986810e43 100644 --- a/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json +++ b/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json @@ -1,4 +1,4 @@ { "type": "Bug Fix", - "description": "Fix error thrown if plugins send out supplementalContext with the length greather than 10240 characters" + "description": "Inline Suggestions: Occasional `ValidationException` if user context has too many characters." } diff --git a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts index 92afe186a97..886cdd2e7ef 100644 --- a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts +++ b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts @@ -136,16 +136,16 @@ export async function fetchSupplementalContextForSrcV1( for (const chunk of bestChunks) { throwIfCancelled(cancellationToken) - if (totalLength > crossFileContextConfig.maximumTotalLength) { - break - } - supplementalContexts.push({ filePath: chunk.fileName, content: chunk.nextContent, score: chunk.score, }) totalLength += chunk.nextContent.length + + if (totalLength > crossFileContextConfig.maximumTotalLength) { + break + } } // DO NOT send code chunk with empty content From 15ba9f8ad57702a00444b24a1097af24c777e076 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Mon, 28 Oct 2024 14:54:56 -0700 Subject: [PATCH 5/5] patch --- .../util/supplementalContext/crossFileContextUtil.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts index 886cdd2e7ef..1352f3ae8c8 100644 --- a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts +++ b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts @@ -136,16 +136,17 @@ export async function fetchSupplementalContextForSrcV1( for (const chunk of bestChunks) { throwIfCancelled(cancellationToken) - supplementalContexts.push({ - filePath: chunk.fileName, - content: chunk.nextContent, - score: chunk.score, - }) totalLength += chunk.nextContent.length if (totalLength > crossFileContextConfig.maximumTotalLength) { break } + + supplementalContexts.push({ + filePath: chunk.fileName, + content: chunk.nextContent, + score: chunk.score, + }) } // DO NOT send code chunk with empty content