[Crash]: FATAL ERROR: Ineffective mark-compacts near heap limit - JavaScript heap out of memory after long-running session (~182.4M tokens, 20h uptime)
I maintainer di solito rispondono entro 1 giorno
@GooseKIller ci sta già lavorando.
Dal 19/11/2026.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
Direzione di ricerca
Start by reading packages/cli/src/ui/hooks/useMemoryMonitor.ts and the history retention paths named in the report: packages/core/src/core/agentChatHistory.ts, packages/cli/src/ui/hooks/useHistoryManager.ts, and MainContent.tsx. Compare the reported RSS warning threshold with V8 heap usage and the session persistence flow. The report proposes dynamic warnings, bounded history, and emergency snapshots; done means the chosen behavior is bounded and users receive a warning or recoverable checkpoint before heap exhaustion.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What happened?
During an extended interactive Gemini CLI session running for 72,130,808 ms (~20.03 hours) with 182.4 million cumulative tokens processed, the process crashed with a fatal V8 out-of-memory error:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Aborted (core dumped)
At the time of the crash:
- The status bar indicated:
- Memory (RSS):
3.32 GB - LLM Context Utilization:
32% used(the wire context window was healthy and well within model bounds due to context pruning/summarization) - Quota Utilization:
28% used - Cumulative Tokens:
182.4m tokens - Status:
⠹ Thinking... (esc to cancel, 2m 47s)
- Memory (RSS):
- The V8 garbage collector attempted consecutive scavenge and mark-compact cycles near the 4,099.7 MB heap limit. The mark-compact collection reclaimed only ~23.6 MB (
4062.0 -> 4038.4 MB), demonstrating that >99% of heap objects were retained live references that could not be freed. - Because the built-in
MEMORY_WARNING_THRESHOLDinpackages/cli/src/ui/hooks/useMemoryMonitor.tsis hardcoded to a static 7 GB (7 * 1024 * 1024 * 1024), the warning was never triggered and no alert/heap snapshot was captured before the fatal crash. - The process aborted abruptly with a core dump, resulting in loss of active session state.
What did you expect to happen?
- Bounded Heap Retention: Memory usage in long-running interactive sessions should remain bounded or grow sub-linearly. Historical turns and cold tool outputs should be evicted from the active in-memory heap or paged out to disk session logs (
~/.gemini/history/). - Adaptive Memory Warning:
useMemoryMonitorshould monitor memory usage relative to the active V8 heap limit (v8.getHeapStatistics().heap_size_limit), warning users at ~75–80% of the active heap limit (e.g. ~3.2 GB on a 4 GB heap) rather than relying on a static 7 GB threshold that can never be reached on default 4 GB heap environments. - Emergency Checkpoint / Heap Snapshot: When approaching critical heap limits (>85%), the CLI should automatically flush a session checkpoint to disk and capture a diagnostic heap snapshot via
v8.getHeapSnapshot()before an unrecoverable process abort occurs.
Client information
Client Information
- Gemini CLI version:
0.68.0 - Node.js version:
v24.18.0(/home/<user>/.nvm/versions/node/v24.18.0/bin/node) - Operating system: Linux x86_64 (
workstation-linux-x64) - Model:
gemini-3.8-flash - Active Modes: YOLO mode enabled (
Ctrl+Y), No sandbox - Session Duration:
72,130,808 ms(~20 hours 2 minutes) - Cumulative Tokens:
182.4m tokens - Heap Limit at Crash:
4,099.7 MB(~4.09 GB default 64-bit V8 space) - RSS at Crash:
3.32 GB
Login information
Logged in via Google Account / OAuth credentials.
Anything else we need to know?
1. Terminal Output and Status Line Prior to Crash
YOLO Ctrl+Y 2 GEMINI.md files · 1 MCP server · 66 skills
* Type your message or @path/to/file
workspace (/directory) branch sandbox /model quota context memory session machine /auth diff tokens
~/workspace-app fix/history-canvas-ftp-1772-rows no sandbox gemini-3.8-flash 28% used 32% used 3.32 GB 853b90b0 workstation-linux-x64 <user>@<org>.com +1696 -731 182.4m tokens 3 errors (F12 for details)
⠹ Thinking... (esc to cancel, 2m 47s) ? for shortcuts
2. V8 GC Logs and Native Stack Trace
<--- Last few GCs --->
[1900208:0x4415c000] 72130243 ms: Scavenge (interleaved) 4056.2 (4081.0) -> 4054.9 (4099.5) MB, pooled: 0 MB, 33.36 / 0.00 ms (average mu = 0.318, current mu = 0.322) allocation failure;
[1900208:0x4415c000] 72130808 ms: Mark-Compact (reduce) 4062.0 (4099.7) -> 4038.4 (4060.4) MB, pooled: 0 MB, 21.48 / 0.00 ms (+ 492.2 ms in 98 steps since start of marking, biggest step 5.4 ms, walltime since start of marking 557 ms) (average mu = 0.284,
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
1: 0x74eae8 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
2: 0xc42680 [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
3: 0xc4276f [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
4: 0xee5fc5 [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
5: 0xee5ff2 [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
6: 0xee62ea [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
7: 0xef6fea [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
8: 0xefb390 [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
9: 0x198d931 [/home/<user>/.nvm/versions/node/v24.18.0/bin/node]
Aborted (core dumped)
3. Root Cause Analysis & Codebase Investigation
Investigation of the codebase reveals three intersecting factors:
A. Unbounded In-Memory Retention in AgentChatHistory and useHistory
While AgentHistoryProvider (packages/core/src/context/agentHistoryProvider.ts) successfully summarizes and truncates context payloads sent over the wire to the Gemini API (which is why context usage was only 32%), the underlying in-memory data structures retain all historical turns indefinitely:
AgentChatHistory(packages/core/src/core/agentChatHistory.ts:23-43):
this.historyis an unbounded array ofHistoryTurn. Every user prompt, model reply, and massive tool output (such as large file reads, terminal diffs, and data rows) is appended tothis.historyand never evicted.useHistory(packages/cli/src/ui/hooks/useHistoryManager.ts:44):
The UI hook stores all turns in React state (useState<HistoryItem[]>), causing the Ink renderer (MainContent.tsx:453-462) to retain an ever-expanding tree of component objects.
B. Inoperative Memory Warning Threshold on Default 4 GB Heaps
In packages/cli/src/ui/hooks/useMemoryMonitor.ts:
export const MEMORY_WARNING_THRESHOLD = 7 * 1024 * 1024 * 1024; // 7GB in bytes
export const MEMORY_CHECK_INTERVAL = 60 * 1000; // one minute
...
const usage = process.memoryUsage().rss;
if (usage > MEMORY_WARNING_THRESHOLD) {
addItem({
type: MessageType.WARNING,
text: `High memory usage detected: ${(usage / (1024 * 1024 * 1024)).toFixed(2)} GB. If you experience a crash, please file a bug report by running /bug`,
});
}
64-bit Node.js has a default V8 max heap limit of ~4,096 MB (~4.09 GB). An application running under default memory flags crashes at ~4 GB long before usage can ever reach 7 GB. As a result, the built-in warning and the /bug auto-snapshot mechanism (MEMORY_SNAPSHOT_AUTO_THRESHOLD_BYTES = 2 GB in bugCommand.ts) are never brought to the user's attention.
C. Memory Auto-Configuration Boundary Condition
In packages/cli/index.ts:
const totalMemoryMB = os.totalmem() / (1024 * 1024);
const heapStats = v8.getHeapStatistics();
const currentMaxOldSpaceSizeMb = Math.floor(heapStats.heap_size_limit / 1024 / 1024);
const targetMaxOldSpaceSizeInMB = Math.floor(totalMemoryMB * 0.5);
if (targetMaxOldSpaceSizeInMB > currentMaxOldSpaceSizeMb) {
return [`--max-old-space-size=${targetMaxOldSpaceSizeInMB}`];
}
On machines with 8 GB RAM (or when relaunch is skipped / unconfigured), 8192 * 0.5 = 4096 MB, so targetMaxOldSpaceSizeInMB <= currentMaxOldSpaceSizeMb and no --max-old-space-size flag is added, leaving the heap limit capped at ~4 GB.
4. Suggested Mitigations
- Make
useMemoryMonitorDynamic & Heap-Aware:
Instead of a hardcoded 7 GB threshold, compare againstv8.getHeapStatistics().heap_size_limit:const heapStats = v8.getHeapStatistics(); const heapWarningThreshold = heapStats.heap_size_limit * 0.80; // 80% of max heap if (heapStats.used_heap_size > heapWarningThreshold) { // Warn user to run /compress, /clear, or /bug } - Implement Bounded In-Memory Window for Core & UI:
Introduce a maximum in-memory history turn window (e.g., retain the last 50–100 turns in active memory, offloading older turns to the session JSONL file on disk). - Emergency Auto-Snapshot / Checkpoint:
When heap usage exceeds 85% ofheap_size_limit, trigger an automatic session flush and dump a diagnostic snapshot viacaptureHeapSnapshot().
- Lingua principale
- TypeScript
- Stelle
- 109k
- Fork
- 15k
- Merge medio
- 1g 24m
- PR unite (30g)
- 91
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google-gemini/gemini-cli
-
npm ci fails with EALLOWREMOTE on npm 12Forse già presa @landry-kapgnep l’ha presa oggi. Apertastatus/need-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
google-gemini/gemini-cli#30525 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
hooks migrate preserves regex SessionStart alternatives that native exact trigger matching never runsForse già presa @ayam04 l’ha presa oggi. Apertastatus/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google-gemini/gemini-cli#30514 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
CLI reference documents unsupported bulk skills enable and disable commandsForse già presa @jadelike-wine l’ha presa 1 giorno fa. Apertastatus/need-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
google-gemini/gemini-cli#30505 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Footer ignores custom model displayName and drops Vertex AI model info despite hideModelInfo=falseForse già presa @bitwizard25 l’ha presa 2 giorni fa. Apertastatus/need-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
google-gemini/gemini-cli#30482 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
fix(extensions): allowUnsafeConfigPaths missing in GIT_EXTENSION_OPTIONS causes `extensions update` failureForse già presa @kccrcodes l’ha presa 4 giorni fa. Apertastatus/need-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
google-gemini/gemini-cli#30416 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google-gemini/gemini-cli
Issue simili
-
enhancement from-app needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
nightly-labs/openbot#19162 ·
I maintainer di solito rispondono entro 1 giorno
-
triage:in-progress
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Cotal-AI/Cotal#11229 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
omdsh-dev/DSH-better-sidebar#1290 ·
I maintainer di solito rispondono entro 1 giorno
-
Suggest a wallet: WalletChanForse già presa @apoorvlathey l’ha presa oggi. Apertaawaiting changes needs triage 📥
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ethereum/ethereum-org-website#20000 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno