Skip to content

fix(scan): keep Windows awake while a scan runs - #1361

Merged
marcinz606 merged 2 commits into
marcinz606:mainfrom
thetalkingdrum:fix/windows-scan-keep-awake
Oct 11, 2026
Merged

marcinz606 merged 2 commits into
marcinz606:mainfrom
thetalkingdrum:fix/windows-scan-keep-awake

Conversation

@thetalkingdrum

@thetalkingdrum thetalkingdrum commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

A scan runs for minutes without keyboard or mouse input, so Windows idle sleep can suspend the PC in the middle of a pass. The pass then ends at the wake with the unread part of the frame left as zeros, and the IR validity mask still marks the whole frame as valid. In one unattended session, four frames were cut off this way: each file was saved within two seconds of a System Idle wake (Kernel-Power sleep and Power-Troubleshooter wake events), with data ending at 0.7%, 26%, 58% and 66% of the frame width. Since the incomplete-pass check in #1146 such a frame raises an error instead of being saved, but the scan is still lost.

power_assertion.py held a real assertion on macOS only. On Windows it now sets the calling thread's execution state with ES_SYSTEM_REQUIRED, so the display can still turn off. run_batch acquires and releases it on one thread, as the state requires. The second commit holds it for run_scan as well, so a single-frame scan is covered. Both paths now have a test.

Linux still gets the inert assertion. The user guide says to turn off automatic suspend before a long roll. A logind inhibitor would need a Linux desktop to test, so it is not part of this PR.

Tested with a fake kernel32 for acquire, release, refusal and failure, with the scan worker tests, and against the real API: the thread's state reads 0x80000001 while held and 0x80000000 after release. Not tested with a full unattended roll on hardware.

🤖 Generated with Claude Code

@thetalkingdrum
thetalkingdrum marked this pull request as ready for review October 11, 2026 15:44
thetalkingdrum and others added 2 commits October 11, 2026 17:44
A scan batch runs for many minutes without keyboard or mouse input, so
Windows idle sleep can suspend the PC in the middle of a pass. The pass
then ends at the wake with the unread part of the frame left as zeros,
and the IR validity mask still says the whole frame is valid. Four frames
of one session were cut off this way: each was saved within two seconds
of a System Idle wake, at 0.7%, 26%, 58% and 66% of the frame.

power_assertion.py held a real assertion on macOS only. On Windows the
assertion is now the calling thread's execution state with
ES_SYSTEM_REQUIRED, so the display may still turn off. run_batch acquires
and releases it on one thread, as the state requires. Linux still gets
an inert assertion.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A single-frame scan runs for minutes without input, so idle sleep can cut
it off the same way as a batch. run_scan now acquires the assertion like
run_batch and releases it in its finally block. Tests cover the single
scan, its error path and the batch, which had none.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thetalkingdrum
thetalkingdrum force-pushed the fix/windows-scan-keep-awake branch from cf34f22 to c34c705 Compare October 11, 2026 15:45
@marcinz606
marcinz606 merged commit fd2dbe2 into marcinz606:main Oct 11, 2026
1 check passed
@thetalkingdrum

Copy link
Copy Markdown
Contributor Author

I could make a pr for linux as well but I can't test it. Would you rather do it? @marcinz606

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants