Skip to content

Commit e14e285

Browse files
authored
fix(amazonq): limit maximum size of supplementalContext being sent (#5877)
## Problem We found there were lots of cases where open tabs context sent from the plugins with total length > 10240 chars long, which will result in `validationException` error while users trigger inline completion service. ## Solution Limit maximum length of supplemental context added in the result set and meanwhile Q team is conducting investigation to root cause it. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 980710d commit e14e285

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
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": "Inline Suggestions: Occasional `ValidationException` if user context has too many characters."
4+
}

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ export const crossFileContextConfig = {
712712
numberOfChunkToFetch: 60,
713713
topK: 3,
714714
numberOfLinesEachChunk: 50,
715+
maximumTotalLength: 20480,
715716
}
716717

717718
export const utgConfig = {

packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,16 @@ export async function fetchSupplementalContextForSrcV1(
132132

133133
// Step 4: Transform best chunks to supplemental contexts
134134
const supplementalContexts: CodeWhispererSupplementalContextItem[] = []
135+
let totalLength = 0
135136
for (const chunk of bestChunks) {
136137
throwIfCancelled(cancellationToken)
137138

139+
totalLength += chunk.nextContent.length
140+
141+
if (totalLength > crossFileContextConfig.maximumTotalLength) {
142+
break
143+
}
144+
138145
supplementalContexts.push({
139146
filePath: chunk.fileName,
140147
content: chunk.nextContent,

0 commit comments

Comments
 (0)