[PR #15551] app: restore macOS runtime env for managed server #77493

Open
opened 2026-05-05 10:09:37 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/15551
Author: @Horacehxw
Created: 4/13/2026
Status: 🔄 Open

Base: mainHead: fix-darwin-launchctl-env


📝 Commits (2)

  • 9c92411 app: restore macOS runtime env for managed server
  • 20b9965 fix(server): gate launchctl tests on darwin, add timeout and cache

📊 Changes

4 files changed (+219 additions, -0 deletions)

View changed files

📝 app/server/server.go (+1 -0)
app/server/server_darwin_env.go (+73 -0)
app/server/server_darwin_test.go (+140 -0)
app/server/server_windows_env.go (+5 -0)

📄 Description

Summary

Restore selected runtime environment variables from launchctl getenv when the macOS desktop app launches a managed ollama serve process.

On Apple Silicon macOS setups, users can configure runtime workarounds such as:

  • GGML_METAL_TENSOR_DISABLE=1
  • OLLAMA_KV_CACHE_TYPE=q8_0
  • OLLAMA_FLASH_ATTENTION=1

These may be present in the user's launchd session, but not in the desktop app process environment. In that case the managed serve child never sees them, even though server.cmd() already copies os.Environ().

This patch adds a small darwin-only fallback: for a narrow allowlist of runtime env vars, if a key is missing from the app process env, read it from launchctl getenv and inject it into the managed server env.

Why this change

I reproduced a case on Apple M5 Pro + macOS 26.4 + Ollama 0.20.6 where:

  • launchctl print gui/$(id -u)/com.ollama.ollama showed GGML_METAL_TENSOR_DISABLE=1
  • but /Applications/Ollama.app/Contents/Resources/ollama serve did not have that env in ps eww
  • and model loads failed with Metal compile errors and 500

Typical failing log sequence:

  • ggml_metal_device_init: has tensor = true
  • ggml_metal_init: the device does not have a precompiled Metal library - this is unexpected
  • ggml_metal_init: will try to compile it on the fly
  • MPPTensorOpsMatMul2dImpl.h ... static_assert failed due to requirement '__is_same_v<bfloat, half>'
  • SIGABRT: abort

With GGML_METAL_TENSOR_DISABLE=1, the same machine can load the model successfully.

Scope

This intentionally does not introduce generic env passthrough logic.

It only restores a small allowlist of documented runtime env vars plus GGML_METAL_TENSOR_DISABLE, and only when the variable is absent from the current process env.

Explicit process env still wins.

Tests

Added coverage for:

  • filling missing allowlisted variables from launchctl
  • preserving explicit process env over launchctl values
  • ignoring missing/empty launchctl values
  • ensuring Server.cmd() includes recovered values in cmd.Env

Verification

Passed locally:

go test ./app/server
  • Closes or helps with: #15548

🔄 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/15551 **Author:** [@Horacehxw](https://github.com/Horacehxw) **Created:** 4/13/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-darwin-launchctl-env` --- ### 📝 Commits (2) - [`9c92411`](https://github.com/ollama/ollama/commit/9c9241197b3fbdaed54fc8c9e31909644c5ae60d) app: restore macOS runtime env for managed server - [`20b9965`](https://github.com/ollama/ollama/commit/20b9965df1c476dc60d57f9bb8a7575f61798c21) fix(server): gate launchctl tests on darwin, add timeout and cache ### 📊 Changes **4 files changed** (+219 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `app/server/server.go` (+1 -0) ➕ `app/server/server_darwin_env.go` (+73 -0) ➕ `app/server/server_darwin_test.go` (+140 -0) ➕ `app/server/server_windows_env.go` (+5 -0) </details> ### 📄 Description ## Summary Restore selected runtime environment variables from `launchctl getenv` when the macOS desktop app launches a managed `ollama serve` process. On Apple Silicon macOS setups, users can configure runtime workarounds such as: - `GGML_METAL_TENSOR_DISABLE=1` - `OLLAMA_KV_CACHE_TYPE=q8_0` - `OLLAMA_FLASH_ATTENTION=1` These may be present in the user's launchd session, but not in the desktop app process environment. In that case the managed `serve` child never sees them, even though `server.cmd()` already copies `os.Environ()`. This patch adds a small darwin-only fallback: for a narrow allowlist of runtime env vars, if a key is missing from the app process env, read it from `launchctl getenv` and inject it into the managed server env. ## Why this change I reproduced a case on Apple M5 Pro + macOS 26.4 + Ollama 0.20.6 where: - `launchctl print gui/$(id -u)/com.ollama.ollama` showed `GGML_METAL_TENSOR_DISABLE=1` - but `/Applications/Ollama.app/Contents/Resources/ollama serve` did not have that env in `ps eww` - and model loads failed with Metal compile errors and `500` Typical failing log sequence: - `ggml_metal_device_init: has tensor = true` - `ggml_metal_init: the device does not have a precompiled Metal library - this is unexpected` - `ggml_metal_init: will try to compile it on the fly` - `MPPTensorOpsMatMul2dImpl.h ... static_assert failed due to requirement '__is_same_v<bfloat, half>'` - `SIGABRT: abort` With `GGML_METAL_TENSOR_DISABLE=1`, the same machine can load the model successfully. ## Scope This intentionally does not introduce generic env passthrough logic. It only restores a small allowlist of documented runtime env vars plus `GGML_METAL_TENSOR_DISABLE`, and only when the variable is absent from the current process env. Explicit process env still wins. ## Tests Added coverage for: - filling missing allowlisted variables from launchctl - preserving explicit process env over launchctl values - ignoring missing/empty launchctl values - ensuring `Server.cmd()` includes recovered values in `cmd.Env` ## Verification Passed locally: ```bash go test ./app/server ``` ## Related - Closes or helps with: #15548 --- <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:09:37 -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#77493