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..28986810e43 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-279c3a22-246e-41ca-9a42-3e446cdb9565.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Inline Suggestions: Occasional `ValidationException` if user context has too many characters." +} diff --git a/packages/core/src/codewhisperer/models/constants.ts b/packages/core/src/codewhisperer/models/constants.ts index 846d9117066..92c51509a2f 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: 20480, } 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..1352f3ae8c8 100644 --- a/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts +++ b/packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts @@ -132,9 +132,16 @@ 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) + totalLength += chunk.nextContent.length + + if (totalLength > crossFileContextConfig.maximumTotalLength) { + break + } + supplementalContexts.push({ filePath: chunk.fileName, content: chunk.nextContent,