Skip to content

[macos] 空闲时常驻音频输出会话,阻止系统空闲睡眠导致整夜耗电 #1184

Open

Description

@HernandoR

现象

现象

  • 环境:MacBook Pro(M3 Max),macOS 26(Darwin 25.6.0),电池供电。OpenLess 1.3.18。
  • 触发条件:OpenLess 一启动就会出现,无需使用听写;之后在后台运行(未录音、未播放声音),用户按电源键锁屏/关闭显示器后离开,不合盖。
  • 当前表现:OpenLess 的 WebKit GPU 进程(com.apple.WebKit.GPU.xpc)在 coreaudiod 中持续持有音频输出上下文,coreaudiod 据此创建 PreventUserIdleSystemSleep assertion,即使没有任何声音播放也不释放。系统因此无法进入空闲睡眠,整夜保持唤醒直到电量耗尽。退出 OpenLess 后该进程消失,assertion 同时释放。
  • 证据:

验证时只运行 OpenLess(已退出其他可能占用音频的应用),pmset -g assertions,PID 24081 为 OpenLess 的 WebKit GPU 进程:

pid 421(coreaudiod): [0x00035d8c00018824] 00:01:26 PreventUserIdleSystemSleep named: "com.apple.audio.30-7A-D2-73-9A-51:output.context.preventuseridlesleep"
    Created for PID: 24081.
    Resources: audio-out 30-7A-D2-73-9A-51:output

蓝牙耳机断开后,会切换到内置扬声器继续持有(当时 OpenLess 的 WebKit GPU 进程为 PID 2492):

pid 421(coreaudiod): PreventUserIdleSystemSleep named: "com.apple.audio.BuiltInSpeakerDevice.context.preventuseridlesleep"
    Created for PID: 2492.
    Resources: audio-out BuiltInSpeakerDevice

pmset -g log(2026-10-12 晚):19:47 按电源键关闭显示器后,上述 assertion 在每 15 分钟的 Summary 中持续存在,期间没有任何 Sleep 记录,直到次日 07:44 电量降到 1% 进入 Low Power Sleep:

2026-10-12 19:47:53 +0900 Notification  Display is turned off
2026-10-13 03:02:53 +0900 Assertions    PID 421(coreaudiod) Summary PreventUserIdleSystemSleep "com.apple.audio.BuiltInSpeakerDevice.context.preventuseridlesleep" 07:13:17
2026-10-13 07:44:35 +0900 Sleep         Entering Sleep state due to 'Low Power Sleep':TCPKeepAlive=inactive Using Batt (Charge:1%)

ps -p 2492 -o comm= → .../com.apple.WebKit.GPU.xpc/...;退出 OpenLess 后 pmset -g assertions 中不再有该 assertion。

影响

影响

  • macOS 笔记本用户在电池供电下锁屏离开(不合盖)时,系统无法自动睡眠。实测 M3 Max 约 12 小时从 79% 耗尽到 1%。
  • 用户难以定位:活动监视器和 pmset 中显示的是 coreaudiod / WebKit GPU 进程,而不是 OpenLess。
  • 合盖或手动「睡眠」可以规避,但依赖用户习惯;作为常驻后台的听写工具,影响面较大。

建议接受标准

建议接受标准

  • OpenLess 空闲(未录音、未播放提示音)时,pmset -g assertions 中不存在由 OpenLess(含其 WebKit GPU 进程)创建的 PreventUserIdleSystemSleep 音频 assertion。
  • 播放提示音等短音频后,音频输出上下文在数秒内释放。
  • 锁屏并关闭显示器后,系统能按 pmset 的 sleep 设置正常进入空闲睡眠(pmset -g log 中可见 Sleep 记录)。
  • 快捷键唤起听写、提示音等现有功能不受影响。

TODO / 不确定项

  • 尚未确认是哪里一直开着音频输出:WebView 里的 AudioContext 或 <audio> 没有 suspend/close,还是原生侧。推测是前端的 AudioContext 常驻,未验证。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions