Repository navigation
Commit 0935472
fix(desktop): hold the sleep block through a safe wrapper, not local FFI
Review follow-up on PR #6036.
AGENTS.md states "No `unsafe` code" without qualification, and the previous
revision of this branch added Win32 FFI (PowerCreateRequest / PowerSetRequest /
PowerClearRequest plus integer round-tripping of the raw HANDLE). That is the
policy as written, so the local FFI goes.
prevent_sleep.rs now reaches the platform mechanism through keepawake, which
also retires the IOKit `extern "C"` block and the CoreFoundation string
plumbing this module already carried on main. The file goes from 8 unsafe
blocks to zero.
The thread-lifetime constraint that ruled out SetThreadExecutionState still
holds, so it is solved structurally rather than by choice of API: a dedicated
thread creates the guard, parks on a channel, and drops the guard when the
channel disconnects. SleepBlock::drop drops the sender and then JOINS that
thread, so release is synchronous -- when drop returns, the OS request is
provably gone, released on the same thread that took it. acquire and release
can keep arriving on three different Tauri worker threads without the request
evaporating or leaking.
Dependency cost, measured rather than assumed: keepawake adds exactly ONE
package to Cargo.lock. Every transitive dependency it names (windows, zbus,
objc2-core-foundation, objc2-io-kit, derive_builder, thiserror, cfg-if) was
already in the tree, and the lock diff contains no version changes. The
Win32_System_Power feature added to windows-sys by the previous revision is
removed, returning that line to its state on main.
keepawake is target-gated to macOS and Windows. Its Linux path needs a live
D-Bus session, and Linux here is a deliberate no-op, so gating keeps a Linux
build free of a new runtime requirement.
Verified: cargo check clean; cargo fmt clean; prevent_sleep tests 4/4 including
ensure_block_holds_a_real_os_block_and_is_idempotent, which takes a real OS
block through keepawake and asserts a second acquire reuses the same worker
thread rather than stranding one; full desktop-tauri suite 2319 passed / 1
failed, that one being managed_agents::runtime::tests::
claude_spawn_uses_the_probed_cli_executable, which mutates process-global PATH
and races other tests in the same process -- it passes in isolation and this
branch does not touch that module.
Not clean, and pre-existing: clippy -D warnings fails on Windows in
buzz-terminal (unused std::io / Instant / portable_pty::Child imports that are
only used behind #[cfg(unix)]). That crate is not in this diff.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Michael Feth <[email protected]>1 parent a99170b commit 0935472
3 files changed
Lines changed: 154 additions & 210 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
66 | | - | |
| 71 | + | |
| 72 | + | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
| |||
0 commit comments