[PR #14452] fix: BoolWithDefault returns defaultValue on invalid env var values #40550

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

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14452
Author: @Anandesh-Sharma
Created: 2/26/2026
Status: 🔄 Open

Base: mainHead: fix-bool-with-default-invalid-env


📝 Commits (1)

  • 3af759f fix: BoolWithDefault returns defaultValue on invalid env var values

📊 Changes

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

View changed files

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

📄 Description

Summary

  • Fix BoolWithDefault to return the provided defaultValue instead of hardcoded true when strconv.ParseBool fails on invalid environment variable values
  • Add a warning log message when an invalid boolean value is encountered, helping users diagnose misconfigured env vars
  • Update existing TestBool expectations and add new TestBoolWithDefault test cases covering invalid values like "yes", "on", "enabled"

Details

The bug is on this line where return true should be return defaultValue. This causes feature flags like OLLAMA_FLASH_ATTENTION to be silently enabled when set to common-but-invalid values (e.g., "yes", "on", "enabled") instead of falling back to their default.

strconv.ParseBool only accepts: "1", "0", "t", "f", "T", "F", "TRUE", "FALSE", "true", "false", "True", "False".

Test plan

  • Updated TestBool to expect false for invalid values (since Bool wraps BoolWithDefault with default false)
  • Added TestBoolWithDefault covering valid values, and invalid values with both true and false defaults

Fixes #14389

🤖 Generated with Claude Code


🔄 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/14452 **Author:** [@Anandesh-Sharma](https://github.com/Anandesh-Sharma) **Created:** 2/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-bool-with-default-invalid-env` --- ### 📝 Commits (1) - [`3af759f`](https://github.com/ollama/ollama/commit/3af759f6277fc0b0d60708ab30d2dc8e75d1b5b3) fix: BoolWithDefault returns defaultValue on invalid env var values ### 📊 Changes **2 files changed** (+36 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `envconfig/config.go` (+2 -1) 📝 `envconfig/config_test.go` (+34 -3) </details> ### 📄 Description ## Summary - Fix `BoolWithDefault` to return the provided `defaultValue` instead of hardcoded `true` when `strconv.ParseBool` fails on invalid environment variable values - Add a warning log message when an invalid boolean value is encountered, helping users diagnose misconfigured env vars - Update existing `TestBool` expectations and add new `TestBoolWithDefault` test cases covering invalid values like "yes", "on", "enabled" ## Details The bug is on [this line](https://github.com/ollama/ollama/blob/main/envconfig/config.go#L159) where `return true` should be `return defaultValue`. This causes feature flags like `OLLAMA_FLASH_ATTENTION` to be silently enabled when set to common-but-invalid values (e.g., "yes", "on", "enabled") instead of falling back to their default. `strconv.ParseBool` only accepts: "1", "0", "t", "f", "T", "F", "TRUE", "FALSE", "true", "false", "True", "False". ## Test plan - [x] Updated `TestBool` to expect `false` for invalid values (since `Bool` wraps `BoolWithDefault` with default `false`) - [x] Added `TestBoolWithDefault` covering valid values, and invalid values with both `true` and `false` defaults Fixes #14389 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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-23 01:25:35 -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#40550