[PR #5437] [Other] keep_awake: the PC stays awake while the model serves, and while setup runs #5425

Open
opened 2026-11-07 16:35:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5437
Author: @mazzyler
Created: 11/6/2026
Status: 🔄 Open

Base: main ← Head: pr/keep-awake


📝 Commits (1)

  • 5312684 [Other] keepawake: keep_awake holds the PC awake for the serving session and for setup, and prevent_sleep works on Linux and macOS

📊 Changes

6 files changed (+284 additions, -24 deletions)

View changed files

📝 apps/host/server/run-config-check.mjs (+2 -1)
📝 docs/DETAILS.md (+2 -1)
📝 serve/keepawake.py (+153 -16)
📝 serve/server.py (+7 -1)
📝 serve/test_keepawake.py (+91 -5)
📝 setup.py (+29 -0)

📄 Description

What this changes

A local model can answer only while the PC is awake. Strata already had an
opt-in key, prevent_sleep, that held the PC awake while a request was
running or waiting
. When the model was loaded and idle between requests, the
PC could still go to sleep, and the next request had to wait for it to wake.
On Linux and macOS the key did nothing: the implementation was Windows-only.

This PR:

  • adds "keep_awake": true (opt-in, like prevent_sleep): it holds the same
    state for the whole serving session, from the server's start to its exit;
    requests coming and going do not drop it;
  • makes prevent_sleep work on Linux and macOS as well:
    • Linux: a systemd-inhibit --what=sleep:idle --mode=block child process;
    • macOS: a caffeinate -i child process;
    • a request acquires and releases the hold; a session hold survives the
      requests and is cleared when the server exits;
    • a system without systemd-inhibit/caffeinate, or without logind/D-Bus,
      prints one startup line and nothing changes;
  • makes setup.py hold the same state while the first run is preparing the
    model
    : the download and the build can take hours, and a sleeping PC loses
    the transfer. The server's own keep_awake takes over when it starts.
    STRATA_KEEP_AWAKE=0 turns the setup part off.

What stays the same

  • Nothing is on by default: without keep_awake/prevent_sleep the server
    creates no keeper (no thread, no child process) and a request pays nothing.
  • The API, the config format and prevent_sleep's request-scoped behavior are
    unchanged; keep_awake is a new key accepted by the app's run-config check.
  • The setup holds the PC awake by default; STRATA_KEEP_AWAKE=0 turns that off.

Which part of the machine is kept awake

  • Windows: SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
    stops the system from going to sleep. It deliberately does not set
    ES_DISPLAY_REQUIRED: the screen may still turn off on its usual timer.
    One daemon thread sets and clears the state (it belongs to the thread that
    set it).
  • Linux / macOS: the child process holds the sleep/idle inhibitor; the
    display may still blank.
  • Other systems: prevent_sleep/keep_awake is a no-op; one startup line
    says so (the setup prints nothing).

A failure to set or keep the state is one line in the log; it never fails a
request.

Validation

  • python -m unittest serve.test_keepawake -v: 13 tests OK on Windows. The
    Windows API is mocked; the Linux/macOS keeper starts and stops a real child
    process; a session hold survives a request's acquire/release and is cleared
    at close; the setup wrapper is covered by an env test.
  • On Windows by hand: a DeepSeek-V4.1 server started with "keep_awake": true
    served requests normally; its startup line was
    keep_awake: the system stays awake (Windows) while the server runs.
  • The app's run-config check accepts the key (KNOWN_KEYS, BOOLS).

Not run: the systemd-inhibit path on a real Linux machine and caffeinate on
a Mac (no hardware here). The tests mock the lookup and use a real child process
for the mechanism, so logind/D-Bus behavior on a desktop that actually idles is
unconfirmed.


🔄 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/5437 **Author:** [@mazzyler](https://github.com/mazzyler) **Created:** 11/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/keep-awake` --- ### 📝 Commits (1) - [`5312684`](https://github.com/Niko1221/Strata/commit/5312684121ebeeccbb231bef9a51d1f49cf3d84f) [Other] keepawake: keep_awake holds the PC awake for the serving session and for setup, and prevent_sleep works on Linux and macOS ### 📊 Changes **6 files changed** (+284 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `apps/host/server/run-config-check.mjs` (+2 -1) 📝 `docs/DETAILS.md` (+2 -1) 📝 `serve/keepawake.py` (+153 -16) 📝 `serve/server.py` (+7 -1) 📝 `serve/test_keepawake.py` (+91 -5) 📝 `setup.py` (+29 -0) </details> ### 📄 Description ## What this changes A local model can answer only while the PC is awake. Strata already had an opt-in key, `prevent_sleep`, that held the PC awake **while a request was running or waiting**. When the model was loaded and idle between requests, the PC could still go to sleep, and the next request had to wait for it to wake. On Linux and macOS the key did nothing: the implementation was Windows-only. This PR: - adds `"keep_awake": true` (opt-in, like `prevent_sleep`): it holds the same state for the **whole serving session**, from the server's start to its exit; requests coming and going do not drop it; - makes `prevent_sleep` work on Linux and macOS as well: - Linux: a `systemd-inhibit --what=sleep:idle --mode=block` child process; - macOS: a `caffeinate -i` child process; - a request acquires and releases the hold; a session hold survives the requests and is cleared when the server exits; - a system without `systemd-inhibit`/`caffeinate`, or without logind/D-Bus, prints one startup line and nothing changes; - makes `setup.py` hold the same state **while the first run is preparing the model**: the download and the build can take hours, and a sleeping PC loses the transfer. The server's own `keep_awake` takes over when it starts. `STRATA_KEEP_AWAKE=0` turns the setup part off. ## What stays the same - Nothing is on by default: without `keep_awake`/`prevent_sleep` the server creates no keeper (no thread, no child process) and a request pays nothing. - The API, the config format and `prevent_sleep`'s request-scoped behavior are unchanged; `keep_awake` is a new key accepted by the app's run-config check. - The setup holds the PC awake by default; `STRATA_KEEP_AWAKE=0` turns that off. ## Which part of the machine is kept awake - **Windows:** `SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)` stops the system from going to sleep. It deliberately does **not** set `ES_DISPLAY_REQUIRED`: the screen may still turn off on its usual timer. One daemon thread sets and clears the state (it belongs to the thread that set it). - **Linux / macOS:** the child process holds the sleep/idle inhibitor; the display may still blank. - **Other systems:** `prevent_sleep`/`keep_awake` is a no-op; one startup line says so (the setup prints nothing). A failure to set or keep the state is one line in the log; it never fails a request. ## Validation - `python -m unittest serve.test_keepawake -v`: **13 tests OK** on Windows. The Windows API is mocked; the Linux/macOS keeper starts and stops a real child process; a session hold survives a request's acquire/release and is cleared at close; the setup wrapper is covered by an env test. - On Windows by hand: a DeepSeek-V4.1 server started with `"keep_awake": true` served requests normally; its startup line was `keep_awake: the system stays awake (Windows) while the server runs`. - The app's run-config check accepts the key (`KNOWN_KEYS`, `BOOLS`). Not run: the `systemd-inhibit` path on a real Linux machine and `caffeinate` on a Mac (no hardware here). The tests mock the lookup and use a real child process for the mechanism, so logind/D-Bus behavior on a desktop that actually idles is unconfirmed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5425
No description provided.