Skip to content

fix(core): structuredClone OOM in long sessions #2562

Description

@netbrah

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions