mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-06-01 06:32:48 -07:00
fix(core): cap chat history at 1000 items to prevent unbounded memory growth
This commit is contained in:
@@ -83,7 +83,12 @@ export function useHistory({
|
||||
return prevHistory; // Don't add the duplicate
|
||||
}
|
||||
}
|
||||
return [...prevHistory, newItem];
|
||||
const newHistory = [...prevHistory, newItem];
|
||||
// Enforce a hard limit of 1000 items to prevent unbounded memory growth
|
||||
if (newHistory.length > 1000) {
|
||||
return newHistory.slice(newHistory.length - 1000);
|
||||
}
|
||||
return newHistory;
|
||||
});
|
||||
|
||||
// Record UI-specific messages, but don't do it if we're actually loading
|
||||
|
||||
@@ -577,6 +577,12 @@ export class ChatRecordingService {
|
||||
) {
|
||||
const conversation = this.readConversation();
|
||||
updateFn(conversation);
|
||||
// Enforce a hard limit of 1000 items to prevent unbounded memory and file growth
|
||||
if (conversation.messages.length > 1000) {
|
||||
conversation.messages = conversation.messages.slice(
|
||||
conversation.messages.length - 1000,
|
||||
);
|
||||
}
|
||||
this.writeConversation(conversation);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user