Description
GeminiChat.getHistory() uses structuredClone(history) which deep-copies the entire conversation on every turn. In long sessions (multi-hour, many tool calls), this causes out-of-memory crashes because structuredClone serializes and deserializes the full history into a new allocation each time.
Proposed Fix
Replace structuredClone(history) with [...history] (shallow array copy). The Content objects are shared references — callers already treat history as read-only and must not mutate entries in place. This matches the upstream Gemini CLI pattern for avoiding OOM on long sessions.
Impact
- Eliminates OOM crashes in multi-hour sessions with many tool calls
- Reduces GC pressure significantly (no deep cloning of large objects)
- Zero behavioral change — callers already follow the read-only contract
Description
GeminiChat.getHistory()usesstructuredClone(history)which deep-copies the entire conversation on every turn. In long sessions (multi-hour, many tool calls), this causes out-of-memory crashes becausestructuredCloneserializes and deserializes the full history into a new allocation each time.Proposed Fix
Replace
structuredClone(history)with[...history](shallow array copy). TheContentobjects are shared references — callers already treat history as read-only and must not mutate entries in place. This matches the upstream Gemini CLI pattern for avoiding OOM on long sessions.Impact