feat(memory): graduated memory pressure mitigation#3366
Merged
gregpriday merged 4 commits intodevelopfrom Mar 16, 2026
Merged
Conversation
Collaborator
Author
|
Review status: Ready (pending Windows CI confirmation)
|
- Add MemoryPressureActions interface with clearCaches and hibernateIdleProjects - Implement warmup guard (5 intervals), tier 1 (cache clear + GC), tier 2 (hibernation) - Add hibernateUnderMemoryPressure to HibernationService with agent state guards - Wire actions into startAppMetricsMonitor in main.ts with V8 GC exposure
- Add 9 tests for ProcessMemoryMonitor tier 1/tier 2 mitigation, warmup, cooldown - Add 6 tests for HibernationService.hibernateUnderMemoryPressure guards - Test backward compatibility with no-args startAppMetricsMonitor call
- Use async/await instead of direct return to satisfy Promise<void> type
- Remove config.enabled guard from hibernateUnderMemoryPressure so it works independently of time-based auto-hibernation - Add waiting state to ACTIVE_AGENT_STATES to protect agents awaiting user input - Replace console.log/error with structured logInfo/logError in memory-pressure hibernation - Make GC and cache clearing best-effort independent in clearCaches callback - Parameterize agent state test to cover all protected states (working, running, waiting, directing)
392c75e to
488de67
Compare
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.
Summary
ProcessMemoryMonitortoHibernationServiceso sustained memory pressure triggers automatic mitigation rather than just logging a warningResolves #3286
Changes
electron/services/ProcessMemoryMonitor.ts: newsetMitigationCallbacks()method wires up tier-1 and tier-2 callbacks; pressure detection now counts consecutive intervals above threshold and triggers mitigation at configurable thresholds (default: Tier 1 at 1 interval, Tier 2 at 3 intervals); cooldown tracked per-tierelectron/services/HibernationService.ts: newhibernateIdleForMemoryPressure()method that accepts a max-idle-minutes parameter (default 30 min vs the time-based 24 hr default), filters out the active project and any terminals with an in-progress agent state, and routes through the existinggracefulKillByProject()pathelectron/main.ts: wires the two services together at startup, passing Chromium session cache clearing and GC callbacks for Tier 1, and the hibernation method for Tier 2Testing
Unit test suites pass for both
ProcessMemoryMonitorandHibernationService. Typecheck, lint ratchet, and Prettier checks all clean.