feat(power): keep the Mac awake while agents are running#71
Merged
Conversation
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
Prevent macOS idle system sleep while ≥1 agent or terminal stream is active, so long-running turns keep going when the user steps away (lid open) instead of dying on a heartbeat timeout.
How
platform/power.rs: aSleepGuardref-counter backed by a swappableSleepAssertionBackendtrait — realIoKitBackend(IOPMAssertionCreateWithName/Release,PreventUserIdleSystemSleep) on macOS,NoopBackendelsewhere.ActiveStreams(the single source of truth for "is anything running") owns oneSleepGuardand driveson_count_changeoff its map size on every register/unregister, under the existing map mutex. First stream acquires the assertion; last one out releases it. Terminal sessions participate viaset_session_active.Scope
Idle system sleep only — the display may still sleep (battery friendly), and closing the lid on battery still sleeps as usual (SMC-enforced; out of scope). No schema/pipeline/frontend change.
Verification
cargo testgreen;cargo clippy --all-targets -- -D warningsclean.PreventUserIdleSystemSleep"Helmor is running an agent" line appear inpmset -g assertions, and releasing clears it.