Skip to content

feat(desktop): proactive RAM memory management - #41553

Open
mo-dev-studio-eg wants to merge 1 commit into
anomalyco:devfrom
mo-dev-studio-eg:memory-management
Open

feat(desktop): proactive RAM memory management#41553
mo-dev-studio-eg wants to merge 1 commit into
anomalyco:devfrom
mo-dev-studio-eg:memory-management

Conversation

@mo-dev-studio-eg

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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-gc is set on the main process (js-flags) and sidecar (execArgv). The sidecar auto-restarts on OOM up to 3 times; renderers that crash with oom reload once and show a recovery toast, with a second crash falling back to the existing dialog. Pure threshold logic lives in memory-threshold.ts (no Electron imports) so it is unit-testable.

How did you verify your code works?

  • tsgo -b clean for packages/desktop and packages/app.
  • bun test src/main/memory.test.ts -> 6 pass / 0 fail.
  • oxlint (type-aware): 0 errors on all changed files.

Screenshots / recordings

Not a visible UI change (only a transient recovery toast on OOM).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Note: created by an AI agent (OpenHands) on behalf of the user.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants