Skip to content

Commit 8a1e95a

Browse files
committed
fix: limit file size for during memory bank analysis
1 parent 6a9fe88 commit 8a1e95a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/context/memorybank/memoryBankController.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,18 +433,26 @@ export class MemoryBankController {
433433
throw new Error('No source files found in workspace')
434434
}
435435

436+
// Filter out very large files to prevent conversation overflow
437+
const MAX_FILE_SIZE_FOR_MEMORY_BANK = 20000 // 20KB limit
438+
const reasonableSizedFiles = discoveredFiles.filter(file => file.size <= MAX_FILE_SIZE_FOR_MEMORY_BANK)
439+
440+
this.features.logging.debug(
441+
`Memory Bank analysis: filtered ${discoveredFiles.length - reasonableSizedFiles.length} files over ${MAX_FILE_SIZE_FOR_MEMORY_BANK} characters`
442+
)
443+
436444
// Limit files to prevent memory exhaustion on large projects
437445
const MAX_FILES_FOR_ANALYSIS = 200
438446
let filesToAnalyze: Array<{ path: string; size: number }>
439447

440-
if (discoveredFiles.length > MAX_FILES_FOR_ANALYSIS) {
441-
const shuffled = [...discoveredFiles].sort(() => Math.random() - 0.5)
448+
if (reasonableSizedFiles.length > MAX_FILES_FOR_ANALYSIS) {
449+
const shuffled = [...reasonableSizedFiles].sort(() => Math.random() - 0.5)
442450
filesToAnalyze = shuffled.slice(0, MAX_FILES_FOR_ANALYSIS)
443451
this.features.logging.info(
444-
`Memory Bank analysis: randomly selected ${filesToAnalyze.length} files (from ${discoveredFiles.length} discovered)`
452+
`Memory Bank analysis: randomly selected ${filesToAnalyze.length} files (from ${reasonableSizedFiles.length} reasonable-sized files) to prevent memory issues`
445453
)
446454
} else {
447-
filesToAnalyze = discoveredFiles
455+
filesToAnalyze = reasonableSizedFiles
448456
}
449457

450458
// Step 2: Calculate lexical dissimilarity using TF-IDF

0 commit comments

Comments
 (0)