Repository navigation
Studio: add a Keep computer awake setting to the desktop app - #17659
Conversation
A switch in Settings > General > Power stops the computer from sleeping on its own while Unsloth runs; the display can still turn off. The block is an OS power request (Windows), an IOKit assertion (macOS), or a session/logind inhibitor (Linux), so it ends with the process.
|
Two reds on
|
…17668) ## Summary `Frontend build + bundle sanity` intermittently fails on PRs that do not touch the browser (seen on #17641 and #17659): ``` not ok - an unsaved chat's tabs follow it to the key a reload gives it, by either way the chat page names it location: 'studio/frontend/tests/browser-tab-session.test.ts:160:1' + actual - expected + false, + [] - true, - [ - 'https://draft.example/' - ] ``` The test came in with #17596. After a reload, the browser store asks storage whether the chat shown before the reload was saved (`chatIsUnsaved` in `tab-session.ts`), and that lookup starts with a dynamic `import()`. In the test, the import goes through the module hooks registered by `browser-store-resolver.mjs`. The test waited one `setTimeout(0)` and then asserted that the lookup had landed. On a busy runner the import can take longer than one timer tick, so the unsaved chat's tabs had not been handed over yet. The store is right: it handles the lookup landing either before or after the chat is named, and that is what the test is checking. Only the test's wait was too short. ## Change - The test stub's `__storedThreads` is now a `Set` that counts `has` calls, which is how the stub answers each lookup. `reloaded()` counts a lookup when the session it reloads from shows a `single:` chat, which is the only case where the store looks one up. - `settled()` waits until every started lookup has been answered (10 s cap, then fails with "a stored-chat lookup never answered"), then waits one more tick for the store's `.then`. No product code changes. ## Testing - Sabotage: with a 5 ms delay added to the stub's `getStoredChatThread`, main's version of the test fails with the same diff as CI. With this change it passes with a 5 ms delay and with a 60 ms one. - Without the delay: `tests/browser-tab-session.test.ts` 7 passed, 3 runs. - `tsc -p tsconfig.test.json`: no errors in the file.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9e0a9dbef
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// Reports the block actually held, so a setting that failed to apply reads as off. | ||
| #[tauri::command] | ||
| pub async fn get_keep_awake() -> Option<bool> { | ||
| SUPPORTED.then(is_held) |
There was a problem hiding this comment.
Wait for startup restoration before reading the setting
When the saved preference is true, initialize starts apply(true) on a detached thread. If the General tab calls this command before that work finishes, is_held() returns false; the settings hook loads only once, so the checkbox stays off even after inhibition succeeds. Make the initial read await initialization or notify the UI when restoration completes, so users can see that the computer is still being kept awake.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 98bd484. Reads and writes wait for the startup restoration thread on a blocking worker; the join remains serialized so concurrent commands cannot bypass restoration. A lightweight Rust synchronization regression fails on the previous implementation and passes with the fix. Local checks pass (the workflow trigger check was rerun successfully after installing its missing PyYAML dependency).
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…17659) (#18125) `tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding` fails on main in the CPU `rest-2` shard since #17659 (seen on the staging run of #18122): ``` E AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding, ... E + 'tests/studio/test_keep_awake_initialization.py:10: read_text()' ``` ## Cause `tests/studio/test_keep_awake_initialization.py` (added in #17659) reads `studio/src-tauri/src/keep_awake.rs` with `read_text()`. Without an encoding that uses the locale codepage on Windows (cp1252, cp932, ...), so the test breaks there as soon as the Rust file gains a non-ASCII byte. The lint is right; the new test missed it. ## Fix `read_text(encoding = "utf-8")`. ## Verification - main: the lint fails with the line above. - this branch: `tests/test_source_read_encoding.py` 16 passed.
What changed
The desktop app has a new Keep computer awake switch in Settings > General, under a new Power section. While it is on, Unsloth stops the computer from going to sleep on its own for as long as the app runs, so a long training run, download or served model is not cut off by idle sleep. The display can still turn off. The switch is off by default, saved like Close to system tray, and turned back on at launch.
The block is the OS's own sleep request, so it ends with the process; a crash cannot leave the computer unable to sleep:
PowerSetRequest(PowerRequestSystemRequired)power request, listed bypowercfg /requestswith its reason.PreventUserIdleSystemSleepassertion, listed bypmset -g assertions.org.freedesktop.PowerManagement.Inhibit(KDE Plasma, Xfce, LXQt), thenorg.gnome.SessionManager.Inhibitwith the suspend flag (GNOME, Cinnamon), then a logindidleinhibitor for sessions with neither. The xdg portal'sInhibitis not used: on Plasma 6.8 its inhibitions outlived bothRequest.Closeand the caller's exit.On Linux the block owns its D-Bus connection, because the desktop drops an inhibitor as soon as its holder's connection closes.
The switch reads back whether the block is actually held, so if no inhibitor is available it shows off and turning it on shows the error. The row is searchable ("sleep", "caffeinate" and the translated words also find it), and the strings are translated in every locale.
How it was verified
node scripts/typecheck.mjs --testsand the frontend test suite instudio/frontend. 12 tests in date, usage and memory-estimate files fail the same way onmainwithout this change../install.sh --localand launched the desktop app withcargo tauri dev; the Power section and switch render in Settings > General.Not tested here
cargo checkforx86_64-pc-windows-msvcandaarch64-apple-darwinin an isolated crate, since the full app does not cross-compile here.