Skip to content

Commit 9b651db

Browse files
committed
fix: handle invalid OLLAMA_STREAM_USAGE values by warning and disabling stream_options instead of silently defaulting to enabled
1 parent 6ee7566 commit 9b651db

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

crates/goose/src/providers/ollama.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,19 @@ fn resolve_ollama_stream_usage() -> bool {
7272
let config = crate::config::Config::global();
7373
match config.get_param::<bool>("OLLAMA_STREAM_USAGE") {
7474
Ok(val) => val,
75-
// Default to true: Ollama supports stream_options since mid-2025 and
76-
// most installs will benefit from token usage tracking. Users on older
77-
// Ollama builds that hang can set OLLAMA_STREAM_USAGE=false to opt out.
78-
Err(_) => true,
75+
// Key not set: default to true. Ollama supports stream_options since
76+
// mid-2025 and most installs benefit from token usage tracking.
77+
Err(crate::config::ConfigError::NotFound(_)) => true,
78+
// Invalid value (e.g. "0", "yes", typo): warn and disable stream_options
79+
// so users who intended to opt out aren't silently left hanging.
80+
Err(e) => {
81+
tracing::warn!(
82+
"Invalid OLLAMA_STREAM_USAGE value ({}); disabling stream_options. \
83+
Use true or false.",
84+
e
85+
);
86+
false
87+
}
7988
}
8089
}
8190

0 commit comments

Comments
 (0)