Repository navigation
agentHost: use native macOS power status for keep-awake - #351263
Open
Megan Rogge (meganrogge) wants to merge 3 commits into
Open
Megan Rogge (meganrogge) wants to merge 3 commits into
Megan Rogge (meganrogge) wants to merge 3 commits into
Conversation
Electron can report AC power while the Mac is on battery. Use pmset's power-source stream and native status probe in the desktop host, with polling as a fallback. Co-authored-by: Copilot <[email protected]>
Megan Rogge (meganrogge)
requested review from
Robo (deepak1556)
and
a balanced review from Copilot
November 30, 2026 17:36
Megan Rogge (meganrogge)
requested
a max review from Copilot
and removed request for
Copilot
November 30, 2026 17:40
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Power-change notifications leave the sleep blocker active during asynchronous rechecks, potentially preventing idle sleep on battery for up to five seconds or longer if further notifications supersede probes.
2 open issues
What changed in this PR
Updates desktop Agent Host keep-awake detection on macOS to use native power information instead of unreliable Electron battery reporting, addressing #349903.
Changes:
- Reuses native
pmsetchecks and adds power-change monitoring with five-second safety polling. - Handles asynchronous probes, stale results, watcher recovery, and disposal.
- Expands tests and documents the macOS behavior.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/electron-main/agentHostPowerSaveBlocker.test.ts |
Adds polling, monitor recovery, stale-result, and lifecycle tests. |
src/vs/platform/agentHost/node/agentHostPowerSaveBlocker.ts |
Exports the native battery-status helper for reuse. |
src/vs/platform/agentHost/electron-main/agentHostPowerSaveBlocker.ts |
Adds native macOS monitoring and asynchronous power checks. |
src/vs/platform/agentHost/AGENTS.md |
Documents native macOS power detection and polling. |
Review effort: Max
Parse pmset pslog power-source lines so an unplug releases the hold without waiting for the probe, and cover the monitor adapter with a fake child process. Co-authored-by: Copilot <[email protected]>
Release plugged-in-only holds before checking a changed power source, including partial native notifications. Keep the stream adapter independent of power-source parsing and cover stale probes and disposal. Co-authored-by: Copilot <[email protected]>
This branch has not been deployed
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.


Fixes #349903
Summary
Use macOS
pmsetpower status and its power-source event stream for the desktop Agent Host keep-awake blocker instead of relying on Electron battery reporting. Keep a five-second polling fallback, and release the blocker when the machine switches to battery.Validation
pnpm run compile-client— passedpnpm run typecheck-client— passed./scripts/test.sh --run src/vs/platform/agentHost/test/electron-main/agentHostPowerSaveBlocker.test.ts --run src/vs/platform/agentHost/test/node/agentHostPowerSaveBlocker.test.ts— 18 passed, 2 pendingpnpm run oxlint src/vs/platform/agentHost/electron-main/agentHostPowerSaveBlocker.ts src/vs/platform/agentHost/node/agentHostPowerSaveBlocker.ts src/vs/platform/agentHost/test/electron-main/agentHostPowerSaveBlocker.test.ts— passedThe physical unplug/replug behavior was not verified on hardware.