[PR #3241] [CLOSED] [TUI] serve: keepawake primes its daemon before the first acquire (a fast request could miss the hold) #4520

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3241
Author: @Buddychek
Created: 10/19/2026
Status: ❌ Closed

Base: main ← Head: fix/keepawake-start-race


📝 Commits (1)

  • acffabb serve: keepawake primes its daemon before the first acquire - a request that finishes before the thread exists (acquire then release) lost the transient count>0 transition and never held; the loop signals it has entered and acquire waits for that. Same root cause as the test-side fixture in #1901, fixed in the runtime. serve/test_keepawake.py 6/6 OK on Windows, no real power API called

📊 Changes

1 file changed (+10 additions, -0 deletions)

View changed files

📝 serve/keepawake.py (+10 -0)

📄 Description

Problem and result

serve/keepawake.py starts its daemon thread lazily. A request that finishes before the thread exists (acquire then release, a fast request) lost the transient count > 0 transition, so the machine-sleep hold never engaged: the server answered the request and the PC could sleep mid-session.

After: the loop signals it has entered and acquire waits for that, so the first acquire can no longer race the thread start. Same root cause as the test-side fixture in #1901, fixed in the runtime.

Closed in the 0.2.0-beta tracker reset; rebased on main and re-verified per the reset note. #1901 fixed the same race on the test side.

Approach

The daemon loop sets an "entered" event as its first act; acquire waits for that event before counting, so the count>0 transition is always observed.

Validation

Passed, rebased on 0.2.0-beta main (e88ee39d): python -m unittest serve.test_keepawake → 6/6 OK, exit 0. Windows 11, Python 3.15; no real power API called.
Not run: real suspend/resume on battery; CI.

Limits

Windows keepawake path only; the fix adds a startup handshake, no change to the power API calls themselves.


🔄 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/3241 **Author:** [@Buddychek](https://github.com/Buddychek) **Created:** 10/19/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/keepawake-start-race` --- ### 📝 Commits (1) - [`acffabb`](https://github.com/Niko1221/Strata/commit/acffabbca0cd2cea00472db7151fe512d2491e73) serve: keepawake primes its daemon before the first acquire - a request that finishes before the thread exists (acquire then release) lost the transient count>0 transition and never held; the loop signals it has entered and acquire waits for that. Same root cause as the test-side fixture in #1901, fixed in the runtime. serve/test_keepawake.py 6/6 OK on Windows, no real power API called ### 📊 Changes **1 file changed** (+10 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `serve/keepawake.py` (+10 -0) </details> ### 📄 Description ### Problem and result `serve/keepawake.py` starts its daemon thread lazily. A request that finishes before the thread exists (acquire then release, a fast request) lost the transient `count > 0` transition, so the machine-sleep hold never engaged: the server answered the request and the PC could sleep mid-session. After: the loop signals it has entered and `acquire` waits for that, so the first acquire can no longer race the thread start. Same root cause as the test-side fixture in #1901, fixed in the runtime. ### Related discussion Closed in the 0.2.0-beta tracker reset; rebased on main and re-verified per the reset note. #1901 fixed the same race on the test side. ### Approach The daemon loop sets an "entered" event as its first act; `acquire` waits for that event before counting, so the count>0 transition is always observed. ### Validation Passed, rebased on 0.2.0-beta main (`e88ee39d`): `python -m unittest serve.test_keepawake` → 6/6 OK, exit 0. Windows 11, Python 3.15; no real power API called. Not run: real suspend/resume on battery; CI. ### Limits Windows keepawake path only; the fix adds a startup handshake, no change to the power API calls themselves. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:36: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#4520
No description provided.