Skip to content

feat(memory): graduated memory pressure mitigation#3366

Merged
gregpriday merged 4 commits intodevelopfrom
feature/issue-3286-memory-pressure-no-automated
Mar 16, 2026
Merged

feat(memory): graduated memory pressure mitigation#3366
gregpriday merged 4 commits intodevelopfrom
feature/issue-3286-memory-pressure-no-automated

Conversation

@gregpriday
Copy link
Collaborator

Summary

  • Connects ProcessMemoryMonitor to HibernationService so sustained memory pressure triggers automatic mitigation rather than just logging a warning
  • Adds a two-tier graduated response: Tier 1 clears safe Chromium caches (appcache, shadercache, cachestorage) and requests V8 GC; Tier 2 hibernates idle terminals in non-active projects when pressure persists across multiple polling intervals
  • Adds a cooldown mechanism to prevent thrashing, respects the existing hibernation user setting, and never touches the active project or any terminal where an agent is working

Resolves #3286

Changes

  • electron/services/ProcessMemoryMonitor.ts: new setMitigationCallbacks() 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-tier
  • electron/services/HibernationService.ts: new hibernateIdleForMemoryPressure() 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 existing gracefulKillByProject() path
  • electron/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 2
  • Tests updated for both services covering the new mitigation paths, cooldown logic, agent-state guards, and active-project exclusion

Testing

Unit test suites pass for both ProcessMemoryMonitor and HibernationService. Typecheck, lint ratchet, and Prettier checks all clean.

@gregpriday
Copy link
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)
@gregpriday gregpriday force-pushed the feature/issue-3286-memory-pressure-no-automated branch from 392c75e to 488de67 Compare March 16, 2026 06:30
@gregpriday gregpriday merged commit c41f717 into develop Mar 16, 2026
3 checks passed
@gregpriday gregpriday deleted the feature/issue-3286-memory-pressure-no-automated branch March 16, 2026 06:31
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.

Memory pressure has no automated mitigation — monitor warns but takes no action

1 participant