Skip to content

feat(resource-profile): introduce adaptive resource profiles for system-wide scaling#4629

Merged
gregpriday merged 4 commits intodevelopfrom
feature/issue-4324-introduce-adaptive-resource-2
Mar 30, 2026
Merged

feat(resource-profile): introduce adaptive resource profiles for system-wide scaling#4629
gregpriday merged 4 commits intodevelopfrom
feature/issue-4324-introduce-adaptive-resource-2

Conversation

@gregpriday
Copy link
Copy Markdown
Collaborator

Summary

  • Introduces ResourceProfileService — a central coordinator in the main process that monitors memory pressure, event loop lag, battery state, and worktree count, then selects one of three profiles: Performance, Balanced, or Efficiency.
  • Broadcasts profile changes via IPC to the pty-host, workspace-host, and renderer so each process adjusts its local parameters (polling intervals, WebGL budget, hibernation thresholds, git concurrency) without internal restructuring.
  • Hysteresis prevents oscillation: the system requires 30s of sustained pressure before downgrading and 60s of relief before upgrading.

Resolves #4324

Changes

  • electron/services/ResourceProfileService.ts — new service: profile evaluation, transition logic, hysteresis timers, IPC broadcast
  • shared/types/resourceProfile.tsResourceProfile enum, ResourceProfileConfig type with all tunable parameters
  • electron/window/windowServices.ts — initializes and wires ResourceProfileService into the main process lifecycle
  • electron/pty-host.ts / electron/workspace-host.ts — subscribe to profile updates and propagate config to ResourceGovernor and WorkspaceService
  • electron/services/HibernationService.ts, ProcessTreeCache.ts — accept dynamic config overrides from the active profile
  • src/hooks/useResourceProfile.ts — renderer hook for consuming the current profile
  • src/services/terminal/TerminalWebGLManager.ts — respects WebGL context budget from active profile
  • electron/services/__tests__/ResourceProfileService.test.ts — 294-line unit test suite covering profile evaluation, hysteresis, and IPC dispatch

Testing

  • Unit tests cover all profile transition paths, hysteresis timing, battery state influence, and worktree count thresholds.
  • Balanced profile produces identical parameters to current hardcoded defaults (backwards compatibility verified in tests).
  • npm run check passes clean with no errors.

Greg Priday added 4 commits March 30, 2026 06:36
…em-wide scaling

- Add ResourceProfileService with hysteresis-based profile transitions (Performance/Balanced/Efficiency)
- Add shared ResourceProfile types and per-profile configuration constants
- Add set-resource-profile PtyHostRequest type and pty-host handler for ProcessTreeCache adjustment
- Add update-monitor-config WorkspaceHostRequest type and handler for live polling interval changes
- Add setPollInterval method to ProcessTreeCache for runtime interval adjustment
- Add setMemoryPressureThresholdMs setter to HibernationService for profile-based threshold injection
- Add setResourceProfile method to PtyClient and updateMonitorConfig method to WorkspaceClient
- Convert TerminalWebGLManager.MAX_CONTEXTS from static readonly to getter/setter pattern
- Add RESOURCE_PROFILE_CHANGED IPC channel with preload bridge and ElectronAPI type
- Add useResourceProfile hook wired into App component for renderer-side WebGL budget adjustment
- Wire ResourceProfileService lifecycle into windowServices.ts with lazy dep injection
- Add comprehensive test suite (11 tests) covering hysteresis, warmup, oscillation prevention, and null deps
- Fix worktree count signal to use actual worktree count via WorkspaceClient.getAllStatesAsync instead of project count
- Move disposed check before state mutation in applyProfile to prevent stale state on post-disposal calls
- Add lower-bound validation (Math.max(1, n)) to TerminalWebGLManager.setMaxContexts
- Remove getWorktreeCount dep in favor of cached count with async refresh on each eval tick
- Add RESOURCE_PROFILE_CHANGED to inlined CHANNELS in preload.cts
- Replace any types with ResourceProfilePayload in preload bridge
- Remove unused logWarn import from ResourceProfileService
- Fix powerMonitor.isOnBatteryPower to be called as function
- Add ResourceProfile type assertion in pty-host message handler
…k types

- Use typed Mock interfaces for mock deps instead of any casts
- Use vi.Mock type for module-level mock references
- Use as unknown as Type pattern for mock-to-interface casts
@gregpriday gregpriday force-pushed the feature/issue-4324-introduce-adaptive-resource-2 branch from 35233d6 to 31e35c1 Compare March 30, 2026 04:36
@gregpriday gregpriday merged commit 097404b into develop Mar 30, 2026
2 of 3 checks passed
@gregpriday gregpriday deleted the feature/issue-4324-introduce-adaptive-resource-2 branch March 30, 2026 04:36
gregpriday added a commit that referenced this pull request Apr 8, 2026
…adaptive-resource-2

feat(resource-profile): introduce adaptive resource profiles for system-wide scaling
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.

Introduce adaptive resource profiles for system-wide scaling

1 participant