Skip to content

feat(power): keep awake for a set time, pause on battery, let the lid sleep - #5

Open
decrypted wants to merge 1 commit into
mainfrom
feat/keep-awake-timed
Open

decrypted wants to merge 1 commit into
mainfrom
feat/keep-awake-timed

Conversation

@decrypted

@decrypted decrypted commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

What

Keep computer awake gets:

  • Timed modes: 1 / 3 / 6 / 8 / 10 h. Afterwards it returns to the previous mode. The mode stays on with an optional computerAwakeTimer { until, resumeMode, hours }, so older builds just see On. Expiry survives restarts (persisted deadline) and sleep (re-checked on resume). The status shows "Until 14:30 · Active".
  • Only while plugged in (default on): on battery every sleep block is released and the mode and timer are kept; blocks come back on AC.
  • Battery floor (default 50 %, choices 20/30/50/70): when allowed on battery, the block is released below the floor. It resumes on AC or at floor + 5.
  • Closing the lid sleeps (Linux, default on): the inhibitor takes --what=sleep only instead of sleep:handle-lid-switch. logind's default LidSwitchIgnoreInhibited=yes then lets the lid suspend.

Why

Keep-awake held a Linux laptop awake with the lid closed on battery until it ran empty.

Power polling (kept minimal after a performance review)

Mode Linux macOS Windows
Off / Agent idle nothing nothing nothing
On (AC, or paused on battery) 1 readdir + 1 read / 60 s events only events only
Floor mode on battery adaptive 1–10 min pmset at the same cadence no floor
No battery one read, then nothing same same

A failed read is "unknown": it keeps the previous decision and retries. It never turns into "no battery".

Testing

  • oxlint, oxfmt, pnpm tc, localization checks and tests on box (main/power, ipc, status-bar, settings/agents, web preload, shared/app-lifecycle).
  • agent-awake-service.test.ts covers timer expiry (fire, resume, startup), battery pause and resume, the floor, the Linux sysfs reader, and failed-read retry.
  • Not yet tried on real hardware (unplug, lid, macOS).

Risk

Medium. Laptop users stop being kept awake on battery by default, and the Linux lid now suspends by default: both intended. No charge floor on Windows.

🤖 Generated with Claude Code

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​207
Prod 29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1222 $\color{#cf222e}{\Huge{\mathbf{−}}}$​169 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1053

@decrypted
decrypted force-pushed the feat/keep-awake-timed branch 2 times, most recently from 20d8633 to e0630a7 Compare November 18, 2026 08:42
decrypted added a commit that referenced this pull request Nov 18, 2026
Upstream 8abbc91..2f5abbc (245 commits). Branches rebased onto it:
fix/linux-port-scan-inode-cache (#1; now on upstream's linux-proc-net-listeners
parser, which gained a uid field), feat/port-detection-setting (#2),
feat/remote-autoconnect-setting (#3), feat/reduce-motion-setting (#4),
feat/keep-awake-timed (#5), feat/sleep-project-and-group (#6),
feat/project-group-filter (#7; group hider composed over upstream's
folder-nested exemption), fix/worktree-create-missing-base-hint (#8), ci/fork-build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@decrypted
decrypted force-pushed the feat/keep-awake-timed branch from e0630a7 to 49e0c7d Compare November 19, 2026 08:18
decrypted added a commit that referenced this pull request Nov 19, 2026
Upstream 2f5abbc..7bc705a (345 commits). Branches rebased onto it:
#1 fix/linux-port-scan-inode-cache, #2 feat/port-detection-setting, #3 feat/remote-autoconnect-setting,
#4 feat/reduce-motion-setting, #5 feat/keep-awake-timed, #6 feat/sleep-project-and-group,
#7 feat/project-group-filter, #8 fix/worktree-create-missing-base-hint; plus ci/fork-build.

- #2: upstream stablyai#43836 took the refreshing flag away from the background scanner; the
  detection-off reset no longer clears it.
- #4: upstream's HoverScrollText and the composer glow use the motion-safe / motion-reduce
  variants; the bot activity list scrolls with motionSafeScrollBehavior.
- #7: kept upstream's bot-listed workspace exclusion next to the project-group scope.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@decrypted
decrypted force-pushed the feat/keep-awake-timed branch 2 times, most recently from bb4294f to 4849289 Compare November 23, 2026 08:19
decrypted added a commit that referenced this pull request Nov 23, 2026
Upstream 3df243e..0b23e7a (1046 commits). Tree verified on the scratch
integration branch: tc and check:changed (42 checks) green.

- follow the upstream test cut (stablyai#46786): drop test-only reset exports and
  edits to deleted tests (#3)
- #4: upstream's new reduced-motion CSS/matchMedia moved onto the setting
- #5: union with upstream's WSL-host keep-awake counts; option types moved
  out for max-lines
- #7: hiddenProjectGroupIds moved into ClientUiWorkspaceFilterFields (max-lines)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@decrypted
decrypted force-pushed the feat/keep-awake-timed branch 2 times, most recently from 90926b3 to f668000 Compare November 25, 2026 08:11
decrypted added a commit that referenced this pull request Nov 25, 2026
Rebase conflicts were sibling additions only: locale blocks (#2 en.json,
#5 tr.json), main.css next to upstream's forced-colors plugin icon rule (#4),
and #3's launch hold next to upstream's retireStateOfRemovedEnvironments.
#4 keeps routing BotItemReplyJump through readPrefersReducedMotion().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@decrypted
decrypted force-pushed the feat/keep-awake-timed branch 2 times, most recently from d7e7c13 to 9ec1cdf Compare November 27, 2026 08:13
decrypted added a commit that referenced this pull request Nov 27, 2026
Upstream 0fce80c..a788fad (404 commits). Conflicts: lazyZodSchema
wrapping (#2, #7), main.css spinner rule (#4), ko/ru locales (#5);
#4's pane-title fade fix dropped (upstream removed that block), outage
nudge moved onto motion-reduce. Fork CI: Azure apt mirror for the
node-pty floor smoke.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… sleep

Squashed from ten commits for the 2026-11-30 upstream sync (upstream's team
feature control for Keep computer awake rewrote the same lines).

The status bar "Keep computer awake" menu gains a "Keep awake for"
section with 1, 3, 6, 8 and 10 hours. A timed choice keeps the computer
awake until the deadline and then returns to the mode that was active
before (On, Agent or Off).

The timer is stored as an optional computerAwakeTimer setting
({ until, resumeMode, hours }) next to computerAwakeMode, which stays
'on' while it runs, so older builds simply see On. Choosing any plain
mode clears it, and a timer left over under a non-On mode is ignored.

The main-process AgentAwakeService owns expiry: it schedules a timeout
for the deadline, re-checks and reschedules on power resume because
timers stall while the system sleeps, and expires a deadline that passed
while Orca was closed on startup. On expiry it writes the previous mode
back through the settings store so every window updates.

The status bar and the settings row show "Until 14:30" in the UI
language's clock style; settings adds "Until 14:30, then Agent".

feat(power): let the computer sleep on battery and with the lid closed

Keep-awake drained a laptop's battery: unplugged, lid closed, the Linux
inhibitor (systemd-inhibit --what=sleep:handle-lid-switch) kept it from
suspending and nothing watched the battery. Three safeguards apply to
every awake mode (On, Agent, timed):

- computerAwakeOnlyWhilePluggedIn (default true): on battery, release
  every block (powerSaveBlocker, the Linux inhibitor, macOS caffeinate)
  while keeping the chosen mode and timer; take them again on AC.
- computerAwakeBatteryFloorPercent (default 50, choices 20/30/50/70):
  with blocks allowed on battery, release them below the floor and
  resume on AC or 5 points above it, so a charge at the floor does not
  flap the block.
- computerAwakeLidCloseSleeps (default true): the Linux inhibitor takes
  only the sleep lock. logind's LidSwitchIgnoreInhibited= defaults to
  yes, which ignores high-level sleep locks for lid events while
  low-level handle-lid-switch locks are always honoured, so a sleep-only
  lock still blocks idle suspend but lets a closed lid suspend. Off keeps
  today's sleep:handle-lid-switch lock. macOS caffeinate -i -s never
  held a closed lid awake and Windows follows the plan's lid action, so
  both stay unchanged and the toggle shows on Linux only.

ComputerAwakePowerGate reads the power supply only while a block is
wanted: once when it becomes wanted, every 60 s after that (15 min after
finding no battery), and on powerMonitor on-ac, on-battery and resume.
Linux reads /sys/class/power_supply (Mains/USB online, system Battery
capacity, peripheral batteries skipped), macOS runs pmset -g batt, and
Windows uses powerMonitor.isOnBatteryPower() without a charge level, so
only the on-battery pause applies there. A machine without a battery
never pauses.

The status shows "Paused on battery" or "Paused below 50 %". The
settings row nests the three options under the awake control, and the
status bar menu adds "Only while plugged in" plus a link to them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@decrypted
decrypted force-pushed the feat/keep-awake-timed branch from 9ec1cdf to 7e8a67b Compare November 30, 2026 11:10
decrypted added a commit that referenced this pull request Nov 30, 2026
Upstream a788fad..9fa1d98 (1236 commits). Branches: #2 port detection,
#3 remote auto-connect, #4 reduce motion, #5 keep-awake (squashed to one commit), #6 project sleep,
#7 project-group filter, #8 base-branch hint, #9 mouse history buttons (new in local/build), ci/fork-build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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