[PR #15668] fix(windows): prevent system sleep during model downloads and inference #77550

Open
opened 2026-05-05 10:13:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15668
Author: @bhaveshbansal47
Created: 4/18/2026
Status: 🔄 Open

Base: mainHead: fix/prevent-system-sleep-windows


📝 Commits (1)

  • 1b054d7 fix(windows): prevent system sleep during model downloads and inference

📊 Changes

6 files changed (+44 additions, -0 deletions)

View changed files

📝 llm/llm_windows.go (+16 -0)
📝 llm/server.go (+1 -0)
llm/sleep_common.go (+7 -0)
📝 server/download.go (+1 -0)
server/sleep_common.go (+7 -0)
server/sleep_windows.go (+12 -0)

📄 Description

Summary

  • Adds preventSleep() to llm/llm_windows.go using SetThreadExecutionState (ES_CONTINUOUS | ES_SYSTEM_REQUIRED) via kernel32.dll
  • Calls defer preventSleep()() in server/download.go's run() to block sleep for the full duration of every blob download
  • Calls defer preventSleep()() in llm/server.go's Completion() (after semaphore acquire) to block sleep during inference
  • Provides no-op stubs in llm/sleep_common.go and server/sleep_common.go for non-Windows builds

Test plan

  • Start a large model download (e.g. ollama pull llama3:70b) on Windows and verify the machine does not sleep
  • Run a long inference prompt on Windows and verify the machine stays awake
  • Confirm normal sleep resumes after download/inference completes
  • Verify Linux/macOS builds are unaffected (no-op stubs compile cleanly)

🔄 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/ollama/ollama/pull/15668 **Author:** [@bhaveshbansal47](https://github.com/bhaveshbansal47) **Created:** 4/18/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/prevent-system-sleep-windows` --- ### 📝 Commits (1) - [`1b054d7`](https://github.com/ollama/ollama/commit/1b054d7b2a9c1e4b2086716813f87ca4c8b96fe6) fix(windows): prevent system sleep during model downloads and inference ### 📊 Changes **6 files changed** (+44 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `llm/llm_windows.go` (+16 -0) 📝 `llm/server.go` (+1 -0) ➕ `llm/sleep_common.go` (+7 -0) 📝 `server/download.go` (+1 -0) ➕ `server/sleep_common.go` (+7 -0) ➕ `server/sleep_windows.go` (+12 -0) </details> ### 📄 Description ## Summary - Adds `preventSleep()` to `llm/llm_windows.go` using `SetThreadExecutionState` (ES_CONTINUOUS | ES_SYSTEM_REQUIRED) via `kernel32.dll` - Calls `defer preventSleep()()` in `server/download.go`'s `run()` to block sleep for the full duration of every blob download - Calls `defer preventSleep()()` in `llm/server.go`'s `Completion()` (after semaphore acquire) to block sleep during inference - Provides no-op stubs in `llm/sleep_common.go` and `server/sleep_common.go` for non-Windows builds ## Test plan - [ ] Start a large model download (e.g. `ollama pull llama3:70b`) on Windows and verify the machine does not sleep - [ ] Run a long inference prompt on Windows and verify the machine stays awake - [ ] Confirm normal sleep resumes after download/inference completes - [ ] Verify Linux/macOS builds are unaffected (no-op stubs compile cleanly) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-05 10:13:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#77550