Skip to content

feat(settings): warn that keep-awake cannot survive a closed laptop lid#3148

Merged
robbie-c merged 2 commits into
mainfrom
posthog-code/keep-awake-lid-caveat
Jul 5, 2026
Merged

feat(settings): warn that keep-awake cannot survive a closed laptop lid#3148
robbie-c merged 2 commits into
mainfrom
posthog-code/keep-awake-lid-caveat

Conversation

@robbie-c

@robbie-c robbie-c commented Jul 5, 2026

Copy link
Copy Markdown
Member

Problem

The "Keep awake while agents work" setting uses Electron's powerSaveBlocker("prevent-app-suspension"), which only prevents idle system sleep. Closing a laptop lid forces sleep on macOS (and by default on Windows) — no user-space API can block that. Users reasonably expect the toggle to keep an agent running with the lid closed, and it can't.

Change

  • Add hasBuiltInBattery() to the IPowerManager platform interface, implemented in the Electron adapter:
    • macOS: ioreg -rc AppleSmartBattery
    • Windows: Get-CimInstance Win32_Battery (covers Windows laptops, which also sleep on lid close by default)
    • Linux: /sys/class/power_supply/BAT*
    • Result is cached; detection failure falls back to false (no caveat shown).
  • Expose it via SleepService and a new sleep.hasBuiltInBattery host-router query.
  • On devices with a built-in battery, the setting description now reads: "Prevent your computer from going to sleep on its own while the agent is running a task. Closing the lid will still put it to sleep."

Testing

  • pnpm --filter typecheck green for platform, core, host-router, ui, workspace-server, code.
  • Core unit tests pass; IPowerManager test fakes updated.
  • Verified ioreg -rc AppleSmartBattery detection on a MacBook.

Related: recovery of turns interrupted by sleep is addressed separately.


Created with PostHog Code

The "Keep awake while agents work" power-save blocker only prevents
idle system sleep; closing a laptop lid forces sleep on macOS and
Windows regardless. Detect a built-in battery (macOS ioreg, Windows
Win32_Battery, Linux /sys/class/power_supply) and append a lid-close
caveat to the setting description on laptops.

Generated-By: PostHog Code
Task-Id: 6b1cbbfe-903b-400d-a76f-45e614c6d0f8
@trunk-io

trunk-io Bot commented Jul 5, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit ed0ec9b.

@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. packages/core/src/sleep/sleep.test.ts, line 37-117 (link)

    P2 Missing test for SleepService.hasBuiltInBattery

    The mock is wired up correctly, but the describe("SleepService") block has no test case that calls service.hasBuiltInBattery() and asserts it delegates to powerManager.hasBuiltInBattery. Given the team's preference for comprehensive tests, a test like it("delegates hasBuiltInBattery to the power manager", ...) would close the gap.

Reviews (1): Last reviewed commit: "feat(settings): warn that keep-awake can..." | Re-trigger Greptile

Comment on lines +440 to +444
description={
hasBuiltInBattery
? "Prevent your computer from going to sleep on its own while the agent is running a task. Closing the lid will still put it to sleep."
: "Prevent your computer from going to sleep on its own while the agent is running a task"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The base description text is duplicated across both branches of the ternary — the only difference is the extra sentence appended for laptops. Extracting the shared portion satisfies the OnceAndOnlyOnce simplicity rule and makes future copy changes a single-site edit.

Suggested change
description={
hasBuiltInBattery
? "Prevent your computer from going to sleep on its own while the agent is running a task. Closing the lid will still put it to sleep."
: "Prevent your computer from going to sleep on its own while the agent is running a task"
}
description={`Prevent your computer from going to sleep on its own while the agent is running a task.${hasBuiltInBattery ? " Closing the lid will still put it to sleep." : ""}`}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer it the original way

Generated-By: PostHog Code
Task-Id: 6b1cbbfe-903b-400d-a76f-45e614c6d0f8
@robbie-c robbie-c added the Stamphog This will request an autostamp by stamphog on small changes label Jul 5, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates denied this PR: it's classified as a feature spanning two areas (platform interface change + UI + host adapter + router), which requires human review. The deny-list also flagged "auth" due to a touched test file. A human reviewer needs to approve before this can be auto-merged.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 5, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates denied this PR: it spans two areas (platform interface, host adapter, router, and UI) and triggered the auth deny-list due to a touched test file. Both conditions require a human reviewer to approve before auto-merge.

@robbie-c robbie-c requested a review from a team July 5, 2026 19:31
@robbie-c robbie-c merged commit 7c1f4cc into main Jul 5, 2026
23 checks passed
@robbie-c robbie-c deleted the posthog-code/keep-awake-lid-caveat branch July 5, 2026 20:42
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.

2 participants