[PR #14706] envconfig: fix BoolWithDefault returning true on parse error #46046

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

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14706
Author: @alvinttang
Created: 3/8/2026
Status: 🔄 Open

Base: mainHead: fix/bool-parse-error-returns-default


📝 Commits (1)

  • 2e897ce envconfig: fix BoolWithDefault returning true on parse error

📊 Changes

2 files changed (+35 additions, -4 deletions)

View changed files

📝 envconfig/config.go (+2 -1)
📝 envconfig/config_test.go (+33 -3)

📄 Description

Summary

BoolWithDefault in envconfig/config.go returns hardcoded true when strconv.ParseBool fails on an invalid environment variable value. This means setting something like OLLAMA_FLASH_ATTENTION=banana would silently enable flash attention instead of falling back to the default value (false).

This fix:

  • Returns defaultValue instead of true on parse error
  • Logs a warning so users can identify misconfigured environment variables
  • Updates tests to reflect the corrected behavior and adds explicit BoolWithDefault test cases

Reproduction

OLLAMA_FLASH_ATTENTION=banana ollama serve
# Before: flash attention silently enabled
# After: flash attention uses default (off), with a warning logged

Test plan

  • go test ./envconfig/ -run TestBool passes
  • go test ./envconfig/ -run TestBoolWithDefault passes
  • Manual verification with invalid env var values

🔄 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/14706 **Author:** [@alvinttang](https://github.com/alvinttang) **Created:** 3/8/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/bool-parse-error-returns-default` --- ### 📝 Commits (1) - [`2e897ce`](https://github.com/ollama/ollama/commit/2e897ce6d382e15a180ac49b56940f39282498b7) envconfig: fix BoolWithDefault returning true on parse error ### 📊 Changes **2 files changed** (+35 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `envconfig/config.go` (+2 -1) 📝 `envconfig/config_test.go` (+33 -3) </details> ### 📄 Description ## Summary `BoolWithDefault` in `envconfig/config.go` returns hardcoded `true` when `strconv.ParseBool` fails on an invalid environment variable value. This means setting something like `OLLAMA_FLASH_ATTENTION=banana` would silently **enable** flash attention instead of falling back to the default value (`false`). This fix: - Returns `defaultValue` instead of `true` on parse error - Logs a warning so users can identify misconfigured environment variables - Updates tests to reflect the corrected behavior and adds explicit `BoolWithDefault` test cases ## Reproduction ```bash OLLAMA_FLASH_ATTENTION=banana ollama serve # Before: flash attention silently enabled # After: flash attention uses default (off), with a warning logged ``` ## Test plan - [x] `go test ./envconfig/ -run TestBool` passes - [x] `go test ./envconfig/ -run TestBoolWithDefault` passes - [ ] Manual verification with invalid env var values --- <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:36:15 -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#46046