fix: avoid false idle reports from powerMonitor on macOS (naturalBreaks churn)#1798
Open
kyson-zhu-888 wants to merge 1 commit into
Open
fix: avoid false idle reports from powerMonitor on macOS (naturalBreaks churn)#1798kyson-zhu-888 wants to merge 1 commit into
kyson-zhu-888 wants to merge 1 commit into
Conversation
powerMonitor.getSystemIdleTime() can report false idle values on macOS (observed on macOS 26 / Darwin 25), oscillating between a few seconds and values above naturalBreaksInactivityResetTime even during active use. Since the inflated value is non-zero, the native fallback is never reached, causing clearBreakScheduler/naturalBreakFinished churn that keeps resetting the break countdown so breaks never fire. Use the native node-desktop-idle-v2 (IOHID) source directly on darwin, which ioreg HIDIdleTime confirms is accurate; keep existing behaviour elsewhere. Refs hovancik#1797 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #1798 +/- ##
==========================================
+ Coverage 67.39% 68.31% +0.91%
==========================================
Files 16 17 +1
Lines 506 527 +21
==========================================
+ Hits 341 360 +19
- Misses 165 167 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What
On macOS 26 (Tahoe / Darwin 25),
powerMonitor.getSystemIdleTime()reports false idle values — it oscillates between a few seconds and values abovenaturalBreaksInactivityResetTime, even during active use. BecauseNaturalBreaksManager.idleTimetrustspowerMonitor.getSystemIdleTime()first and only falls back to the nativenode-desktop-idle-v2when it returns0, the inflated (non-zero) value means the accurate native source is never reached.The oscillation makes
_checkIdleTime()fireclearBreakScheduler(idle > reset time) and thennaturalBreakFinished(idle < 20s) in rapid succession, every 1–2 minutes. EachnaturalBreakFinishedcallsreset()on the planner, restarting the break countdown. Net effect: withnaturalBreaksenabled, breaks never fire.Fixes #1797.
Change
Use the native
node-desktop-idle-v2(IOHID) source directly ondarwin; keep the existing behaviour on every other platform.Why the native source is trustworthy
node-desktop-idle-v2reads IOHID. Querying the same IOHID source directly is accurate:So only
powerMonitor.getSystemIdleTime()misbehaves on this OS — likely a macOS 26 / Electron regression in the CGEventSource-backed idle API.Testing
standardpasses on the changed file.test/naturalBreaksManager.jsstill passes (it only assertsidleTime === 0when natural breaks are off).naturalBreaks=true: monitoredmain.logfor 5 minutes during active use → 0 idle-churn events (vs. one pause/resume pair every 1–2 min before). Breaks now schedule and fire correctly, and genuine idle periods still reset the countdown as intended.Scope
Single-file, single-expression change, guarded by
process.platform === 'darwin'. Non-macOS behaviour is unchanged. ThepowerMonitorevent subscriptions inmain.js(suspend/lock-screen/resume/unlock-screen) are unrelated and untouched.