gpui: Prevent idle sleep during AI response streaming - #53130
Conversation
|
Hi, I'd like to take a stab at this. After reading the code, the root cause is clear: My planned fix:
The rendering side already works — it just never fires for external ACP agents today. This is a ~15-line change. Before I open a draft PR: is there anything already in-flight here I should be aware of? Also, should I build on PR #50360 or start fresh from main? |
cb634e4 to
532dfb4
Compare
maxbrunsfeld
left a comment
There was a problem hiding this comment.
This seems like a good change
We do already have some similar logic, for macOS only, here:
zed/crates/livekit_client/src/livekit_client/playback.rs
Lines 880 to 915 in 590aaaf
In that case, we're telling the OS not to throttle the app because we are playing audio.
As part of this PR, could you replace that PreventAppNapGuard with your new cross-platform abstraction?
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
532dfb4 to
be01ad5
Compare
rebase |
025129c to
f9aa6f2
Compare
f9aa6f2 to
5830615
Compare
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you for the idea — I've polished it based on the feedback, seems good enough to merge after this Wednesday's release and test.
Release Notes:
Context / Motivation:
When an AI agent takes a long time to generate a response, the operating system might enter an idle sleep (or display sleep) state if there is no user interaction (mouse or keyboard). This can interrupt the workflow. This PR aims to prevent the system from sleeping during an active AI turn by invoking native OS APIs, and provides a UI toggle for users to control this behavior.
Key Changes:
Cross-Platform Idle Sleep Prevention in GPUI (
gpui,gpui_*)prevent_idle_sleepmethod to thePlatformtrait. It returns a RAII-basedPreventIdleSleepToken, which automatically restores the original sleep policy when dropped.NSProcessInfo'sbeginActivityWithOptionswithNSActivityIdleDisplaySleepDisabled.SetThreadExecutionStateto prevent display and system sleep, incorporating a reference counter to handle concurrent requests safely.ashpdto requestorg.freedesktop.portal.Inhibit(inhibitingIdleandSuspendstates) via D-Bus.AI Agent State Integration (
crates/acp_thread)AcpThread: Acquires the token at the beginning ofrun_turn, and automatically releases it when the turn completes normally, errors out, or is explicitly canceled by the user.Settings and UI (
crates/agent_settings,crates/agent_ui)AgentOutputIdleSleepControlto global state.ThreadView(AI conversation panel). Users can hover to view the tooltip and click to toggle the feature on or off.