Skip to content

Prevent sleep while running for increased reliability #663

Description

@KayleeWilliams

Currently when running long-tasks there is a risk of the device falling asleep, this can cause connection issues & interrupt the active task. This is a feature I've found useful on the Codex app.

We should ensure it only runs while a thread is active/running.

I think this would use https://www.electronjs.org/docs/latest/api/power-save-blocker ? And we'd want to use prevent-app-suspension so the app isn't suspended but the screen etc can still turn off e.g. so policies like auto-locking the device after 10 mins of inactivity isn't affected by long running tasks.

I can work on this feature in my free time if needed.

Activity

  1. leo-mathurin commented on Aug 6, 2026

    @leo-mathurin

    I have a working implementation of this, following what the issue proposed: a powerSaveBlocker("prevent-app-suspension") held only while an agent has an active turn, so the display can still turn off and lock policies are unaffected.

    Scope decisions to keep it small:

    • New setting in Settings > General, off by default, desktop only: "Caffeinate while agents are running"
    • Only agents hosted by this desktop app count (primary local and WSL backends). Agents on SSH, relay, or remote environments survive local sleep, so they do not hold the machine awake.
    • Releases below 10% battery while discharging, re-acquires when charging or back above the threshold (Battery Status API, event driven, no polling).
    • The blocker lives in the main process behind the typed IPC bridge; a crashed or closed renderer releases it, and quitting the app drops the OS assertion.

    Verified live on macOS: the assertion shows up in pmset -g assertions seconds after a turn starts and is released when the turn settles. About 300 lines of product code plus tests and a short user doc.

    Windows and Linux go through the same cross-platform Electron API, but I could only verify end to end on macOS. If a Windows or Linux user wants to try the branch and confirm (powercfg /requests on Windows, systemd-inhibit --list on Linux), that would be great.

    Opening a PR shortly.

  2. locked and limited conversation to collaborators on Aug 15, 2026
  3. converted this issue into a discussion #7049 on Aug 15, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions