mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
fix: 修复内存溢出问题,compact 时清理持久增长数据结构
- compact 时清理 contentReplacementState(seenIds/replacements) - logError() 使用 shortErrorStack 替代完整 err.stack,减少 GC 压力 - permissionDenials 每次 submitMessage 清空,防止无限增长 - SSE 缓冲区添加 1MB 上限,防止畸形数据无限累积 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,17 @@ import { clearSessionMessagesCache } from '../../utils/sessionStorage.js'
|
||||
import { clearBetaTracingState } from '../../utils/telemetry/betaSessionTracing.js'
|
||||
import { resetMicrocompactState } from './microCompact.js'
|
||||
|
||||
/**
|
||||
* Compact-scoped cleanup callbacks registered by REPL or other long-lived
|
||||
* components. Called during runPostCompactCleanup() so instance-scoped state
|
||||
* (e.g. contentReplacementState) is freed alongside module-level caches.
|
||||
*/
|
||||
const compactCleanupCallbacks: Array<() => void> = []
|
||||
|
||||
export function registerCompactCleanup(callback: () => void): void {
|
||||
compactCleanupCallbacks.push(callback)
|
||||
}
|
||||
|
||||
/**
|
||||
* Run cleanup of caches and tracking state after compaction.
|
||||
* Call this after both auto-compact and manual /compact to free memory
|
||||
@@ -88,4 +99,11 @@ export function runPostCompactCleanup(querySource?: QuerySource): void {
|
||||
})
|
||||
}
|
||||
clearSessionMessagesCache()
|
||||
for (const cb of compactCleanupCallbacks) {
|
||||
try {
|
||||
cb()
|
||||
} catch (error) {
|
||||
logError(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user