[PR #15053] server: prevent system sleep during inference #46241

Open
opened 2026-04-25 01:44:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15053
Author: @mokshagnachintha
Created: 3/25/2026
Status: 🔄 Open

Base: mainHead: feature/prevent-system-sleep


📝 Commits (1)

  • 2c35508 server: prevent system sleep during inference

📊 Changes

7 files changed (+299 additions, -0 deletions)

View changed files

cmd/sleep_darwin.go (+48 -0)
cmd/sleep_default.go (+18 -0)
cmd/sleep_linux.go (+80 -0)
cmd/sleep_windows.go (+42 -0)
📝 server/routes.go (+11 -0)
server/sleep.go (+47 -0)
server/sleep_test.go (+53 -0)

📄 Description

Description

Resolves #4072

This PR implements platform-specific system sleep prevention that keeps the system awake while Ollama is actively processing inference requests.

Changes

  • Added cross-platform sleep prevention module with implementations for Windows (SetThreadExecutionState), macOS (caffeinate), and Linux (systemd-inhibit/dbus-send)
  • Integrated sleep prevention into GenerateHandler and ChatHandler at the request level
  • Includes comprehensive unit tests

Testing

  • Local testing
  • Unit tests for sleep prevention lifecycle
  • No breaking changes to existing API

Platform Support

  • Windows: SetThreadExecutionState API
  • macOS: caffeinate command
  • Linux: systemd-inhibit / dbus-send
  • Fallback: Graceful no-op on unsupported platforms

Technical Details

  • Automatically prevents sleep during inference, no configuration needed
  • Uses defer pattern to ensure cleanup even on errors
  • Zero overhead when no inference is running

🔄 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/15053 **Author:** [@mokshagnachintha](https://github.com/mokshagnachintha) **Created:** 3/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/prevent-system-sleep` --- ### 📝 Commits (1) - [`2c35508`](https://github.com/ollama/ollama/commit/2c3550878b3f77dd8f3bc0dba5a990c5acfdbcf8) server: prevent system sleep during inference ### 📊 Changes **7 files changed** (+299 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `cmd/sleep_darwin.go` (+48 -0) ➕ `cmd/sleep_default.go` (+18 -0) ➕ `cmd/sleep_linux.go` (+80 -0) ➕ `cmd/sleep_windows.go` (+42 -0) 📝 `server/routes.go` (+11 -0) ➕ `server/sleep.go` (+47 -0) ➕ `server/sleep_test.go` (+53 -0) </details> ### 📄 Description ## Description Resolves #4072 This PR implements platform-specific system sleep prevention that keeps the system awake while Ollama is actively processing inference requests. ## Changes - Added cross-platform sleep prevention module with implementations for Windows (SetThreadExecutionState), macOS (caffeinate), and Linux (systemd-inhibit/dbus-send) - Integrated sleep prevention into GenerateHandler and ChatHandler at the request level - Includes comprehensive unit tests ## Testing - [x] Local testing - [x] Unit tests for sleep prevention lifecycle - [x] No breaking changes to existing API ## Platform Support - ✅ Windows: SetThreadExecutionState API - ✅ macOS: caffeinate command - ✅ Linux: systemd-inhibit / dbus-send - ✅ Fallback: Graceful no-op on unsupported platforms ## Technical Details - Automatically prevents sleep during inference, no configuration needed - Uses defer pattern to ensure cleanup even on errors - Zero overhead when no inference is running --- <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-04-25 01:44:26 -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#46241