[PR #2851] [CLOSED] --keep-awake N: hold the system awake while the engine serves (#1727) #4296

Closed
opened 2026-11-07 15:34:40 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2851
Author: @suprfire
Created: 10/17/2026
Status: ❌ Closed

Base: main ← Head: f-keep-awake


📝 Commits (1)

  • 8acf07a --keep-awake N: hold the system awake while the engine serves (#1727)

📊 Changes

2 files changed (+56 additions, -2 deletions)

View changed files

📝 docs/DETAILS.md (+8 -0)
📝 src/program/generate.cpp (+48 -2)

📄 Description

Closes #1727 (the feature request for a native prevent-sleep option during active inference on Windows).

What it changes

A new opt-in engine flag, --keep-awake N (an argument in the config's args):

  • 0 (or no flag) - off.
  • 1 - hold the system awake for as long as the engine runs (armed at READY).
  • 2 - hold it only while a request runs (request start to DONE/STOP/ERR), and hold the display too.

It calls SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED [| ES_DISPLAY_REQUIRED]) on the serving thread and clears back to ES_CONTINUOUS when the arm ends. Windows only; a no-op elsewhere. --keep-awake without --serve is refused with a message.

What it leaves alone

No default changes: with the flag absent nothing calls SetThreadExecutionState, so the default path is byte-identical. No new dependency (windows.h was already included). The 2 arm hooks the existing BusyScope (busy from a request's start to the end of its iteration), so QUIT and the between-request commands (SAVE/RESTORE/VRAM) do not arm it.

Why

Windows counts a CPU-bound server as idle. Nothing in the engine asked the system to stay up, so a long prompt read can run into the display and sleep timers, and an S3 sleep kills the running request (the expert arena survives in RAM, so the model does not reload - the request is what is lost).

How I checked it

RTX 3080 Ti 12 GB + Ryzen 9 5900X + 64 GB DDR4, Windows 11 (10.0.26200), engine built from this commit (CUDA 13.4, sm_86), Swift IQ3_XXS, --keep-awake 1:

  • The start block shows --keep-awake: SetThreadExecutionState(0x80000001) -> 0x80000000 (error 0) - the return is the previous state, so the request was accepted.
  • powercfg /requests (elevated) lists the engine under SYSTEM while it serves.
  • With the AC sleep timer at 60 s the machine stayed up 4.5+ minutes with the engine serving and its uptime never reset; the same machine slept inside a minute with the flag off (Kernel-Power 42 and powercfg /lastwake confirm the off-case sleeps).
  • The flag is refused without --serve, and --help lists the three values.

What I did not test

  • The 2 arm (only 1 was measured) and its display hold.
  • A machine whose sleep state is S0 low-power idle rather than S3 (this box is S3).
  • HIP/SYCL: the change is inside #ifdef _WIN32 and compiles out on those backends.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2851 **Author:** [@suprfire](https://github.com/suprfire) **Created:** 10/17/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `f-keep-awake` --- ### 📝 Commits (1) - [`8acf07a`](https://github.com/Niko1221/Strata/commit/8acf07ad87a7fa47de48d1130310487a02531da1) --keep-awake N: hold the system awake while the engine serves (#1727) ### 📊 Changes **2 files changed** (+56 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+8 -0) 📝 `src/program/generate.cpp` (+48 -2) </details> ### 📄 Description Closes #1727 (the feature request for a native prevent-sleep option during active inference on Windows). ## What it changes A new opt-in engine flag, `--keep-awake N` (an argument in the config's `args`): - `0` (or no flag) - off. - `1` - hold the system awake for as long as the engine runs (armed at `READY`). - `2` - hold it only while a request runs (request start to `DONE`/`STOP`/`ERR`), and hold the display too. It calls `SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED [| ES_DISPLAY_REQUIRED])` on the serving thread and clears back to `ES_CONTINUOUS` when the arm ends. Windows only; a no-op elsewhere. `--keep-awake` without `--serve` is refused with a message. ## What it leaves alone No default changes: with the flag absent nothing calls `SetThreadExecutionState`, so the default path is byte-identical. No new dependency (`windows.h` was already included). The `2` arm hooks the existing `BusyScope` (busy from a request's start to the end of its iteration), so `QUIT` and the between-request commands (`SAVE`/`RESTORE`/`VRAM`) do not arm it. ## Why Windows counts a CPU-bound server as idle. Nothing in the engine asked the system to stay up, so a long prompt read can run into the display and sleep timers, and an S3 sleep kills the running request (the expert arena survives in RAM, so the model does not reload - the request is what is lost). ## How I checked it RTX 3080 Ti 12 GB + Ryzen 9 5900X + 64 GB DDR4, Windows 11 (10.0.26200), engine built from this commit (CUDA 13.4, sm_86), Swift IQ3_XXS, `--keep-awake 1`: - The start block shows `--keep-awake: SetThreadExecutionState(0x80000001) -> 0x80000000 (error 0)` - the return is the previous state, so the request was accepted. - `powercfg /requests` (elevated) lists the engine under SYSTEM while it serves. - With the AC sleep timer at **60 s** the machine stayed up **4.5+ minutes** with the engine serving and its uptime never reset; the same machine slept inside a minute with the flag off (Kernel-Power 42 and `powercfg /lastwake` confirm the off-case sleeps). - The flag is refused without `--serve`, and `--help` lists the three values. ## What I did not test - The `2` arm (only `1` was measured) and its display hold. - A machine whose sleep state is S0 low-power idle rather than S3 (this box is S3). - HIP/SYCL: the change is inside `#ifdef _WIN32` and compiles out on those backends. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:34:40 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4296
No description provided.