feat(desktop): proactive RAM memory management - #41553
Open
mo-dev-studio-eg wants to merge 1 commit into
Open
Conversation
Add a memory monitor that polls app.getAppMetrics() every 30s and requests
garbage collection when the peak working set crosses the action threshold.
GC runs in the main process (--expose-gc via js-flags), the sidecar utility
process (--expose-gc via execArgv, driven by a new { type: "gc" } message),
and the renderers (via a memory-pressure IPC event).
The sidecar now auto-restarts on OOM up to 3 times, guarded by the
appQuitting flag so shutdown is never preempted. Renderers that crash with
reason "oom" auto-reload once and surface a recovery toast; a second crash
falls back to the existing recovery dialog.
Pure threshold/pressure helpers live in memory-threshold.ts (no Electron or
logging imports) so they are unit-testable in a plain Bun context.
Co-authored-by: openhands <openhands@all-hands.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #
Type of change
What does this PR do?
Adds proactive RAM management to the desktop Electron app. A monitor polls
app.getAppMetrics()every 30s and runs GC (main process, sidecar, renderers) when the peak working set crosses 1.8 GiB.--expose-gcis set on the main process (js-flags) and sidecar (execArgv). The sidecar auto-restarts on OOM up to 3 times; renderers that crash withoomreload once and show a recovery toast, with a second crash falling back to the existing dialog. Pure threshold logic lives inmemory-threshold.ts(no Electron imports) so it is unit-testable.How did you verify your code works?
tsgo -bclean forpackages/desktopandpackages/app.bun test src/main/memory.test.ts-> 6 pass / 0 fail.Screenshots / recordings
Not a visible UI change (only a transient recovery toast on OOM).
Checklist
Note: created by an AI agent (OpenHands) on behalf of the user.