Skip to content

agentHost: use native macOS power status for keep-awake - #351263

Open
Megan Rogge (meganrogge) wants to merge 3 commits into
microsoft:mainfrom
meganrogge:agents/fix-vscode-issue-349903
Open

Megan Rogge (meganrogge) wants to merge 3 commits into
microsoft:mainfrom
meganrogge:agents/fix-vscode-issue-349903

Conversation

@meganrogge

Copy link
Copy Markdown
Collaborator

Fixes #349903

Summary

Use macOS pmset power 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 — passed
  • pnpm 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 pending
  • pnpm 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 — passed

The physical unplug/replug behavior was not verified on hardware.

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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 pmset checks 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

No deployments
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.

Agent host keep-awake still prevents idle sleep on battery on macOS

2 participants