Skip to content

feat(power): keep the Mac awake while agents are running#71

Merged
Legacynnn merged 6 commits into
mainfrom
Legacynnn/agents-continue-on-sleep
Jun 27, 2026
Merged

feat(power): keep the Mac awake while agents are running#71
Legacynnn merged 6 commits into
mainfrom
Legacynnn/agents-continue-on-sleep

Conversation

@Legacynnn

Copy link
Copy Markdown
Owner

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

  • New platform/power.rs: a SleepGuard ref-counter backed by a swappable SleepAssertionBackend trait — real IoKitBackend (IOPMAssertionCreateWithName/Release, PreventUserIdleSystemSleep) on macOS, NoopBackend elsewhere.
  • ActiveStreams (the single source of truth for "is anything running") owns one SleepGuard and drives on_count_change off 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 via set_session_active.
  • Best-effort: a failed assertion is logged and ignored, never blocking a send. macOS auto-releases a process's assertions on exit, so a crash can't strand the Mac awake.

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

  • Unit + ref-count tests (fake backend): acquire-once-for-concurrent-streams / release-on-last, rejected-duplicate is a no-op, terminal sessions participate.
  • Full cargo test green; cargo clippy --all-targets -- -D warnings clean.
  • Real-IOKit check: acquiring makes a PreventUserIdleSystemSleep "Helmor is running an agent" line appear in pmset -g assertions, and releasing clears it.

@Legacynnn
Legacynnn merged commit eef2c52 into main Jun 27, 2026
13 checks passed
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.

1 participant