Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

fix(macos): accept LLAMA_REASONING in any case so llama-server starts (#8220)

Satyam Singhc1a7920cfca4
diff --git a/ods/bin/ods-host-agent.py b/ods/bin/ods-host-agent.py
index 2562262e7..df73eec67 100755
--- a/ods/bin/ods-host-agent.py
+++ b/ods/bin/ods-host-agent.py
@@ -20930,6 +20930,10 @@ def _launch_native_llama_server(env_path: Path, llama_bin: Path, llama_log: Path
gpu_layers = env.get("N_GPU_LAYERS", "").strip() or "auto"
model_path = _active_model_directory(env) / gguf_file
reasoning = env.get("LLAMA_REASONING", "off")
+ # Modes are case-insensitive, as in _pixel_model_reasoning_capable;
+ # llama-server only accepts the lowercase spelling.
+ if reasoning.strip().lower() in {"off", "on", "auto"}:
+ reasoning = reasoning.strip().lower()
reasoning_fmt = {"off": "none", "on": "deepseek"}.get(reasoning, reasoning)
# UI LAN access must not publish an unauthenticated inference endpoint.
bind_addr = "127.0.0.1"
diff --git a/ods/extensions/services/dashboard-api/tests/test_model_activate.py b/ods/extensions/services/dashboard-api/tests/test_model_activate.py
index f5285336e..dba5fc73c 100644
--- a/ods/extensions/services/dashboard-api/tests/test_model_activate.py
+++ b/ods/extensions/services/dashboard-api/tests/test_model_activate.py
@@ -2277,6 +2277,31 @@ class TestLaunchNativeLlamaServer:
assert "deepseek" in cmd
assert _kwargs["cwd"] == str(tmp_path)
+ # llama-server only accepts lowercase; "OFF" used to reach it verbatim
+ # and stop it from starting. A non-mode value still passes through.
+ @pytest.mark.parametrize("value, expected", [
+ ("OFF", "none"), ("Off", "none"), ("ON", "deepseek"), ("AUTO", "auto"), ("deepseek", "deepseek"),
+ ])
+ def test_reasoning_mode_is_case_insensitive(self, monkeypatch, tmp_path, value, expected):
+ env_path = tmp_path / ".env"
+ env_path.write_text(f"GGUF_FILE=test-model.gguf\nLLAMA_REASONING={value}\n", encoding="utf-8")
+ (tmp_path / "data" / "models").mkdir(parents=True)
+ llama_bin = tmp_path / "llama-server"
+ llama_bin.write_text("", encoding="utf-8")
+ calls = []
+
+ class _FakeProc:
+ pid = 4321
+
+ monkeypatch.setattr(_mod, "INSTALL_DIR", tmp_path)
+ monkeypatch.setattr(_mod.platform, "system", lambda: "Linux")
+ monkeypatch.setattr(subprocess, "Popen", lambda cmd, **kwargs: calls.append(cmd) or _FakeProc())
+
+ _launch_native_llama_server(env_path, llama_bin, tmp_path / "llama.log", tmp_path / "llama.pid")
+
+ cmd = calls[0]
+ assert cmd[cmd.index("--reasoning-format") + 1] == expected
+
# Windows launches through ods.ps1 native-llm-restart, which binds loopback.
@pytest.mark.parametrize('system', ['Darwin', 'Linux'])
def test_ui_lan_preference_does_not_publish_native_inference(self, monkeypatch, tmp_path, system):
diff --git a/ods/installers/macos/install-macos.sh b/ods/installers/macos/install-macos.sh
index 69896426c..32a55fabb 100755
--- a/ods/installers/macos/install-macos.sh
+++ b/ods/installers/macos/install-macos.sh
@@ -2379,6 +2379,10 @@ else
# from consuming the entire token budget on internal reasoning)
_reasoning=$(grep '^LLAMA_REASONING=' "$INSTALL_DIR/.env" 2>/dev/null | cut -d= -f2 || echo "")
[[ -z "$_reasoning" ]] && _reasoning="off"
+ # Modes are case-insensitive, as in ods-host-agent.py; llama-server
+ # only accepts the lowercase spelling.
+ _reasoning_lower="$(printf '%s' "$_reasoning" | tr '[:upper:]' '[:lower:]')"
+ case "$_reasoning_lower" in off|on|auto) _reasoning="$_reasoning_lower" ;; esac
# Map .env values (off/on/auto) to llama-server --reasoning-format values
case "$_reasoning" in
off) _reasoning_fmt="none" ;;
diff --git a/ods/installers/macos/lib/native-checkpoint-args.py b/ods/installers/macos/lib/native-checkpoint-args.py
index 871872215..54864c42b 100644
--- a/ods/installers/macos/lib/native-checkpoint-args.py
+++ b/ods/installers/macos/lib/native-checkpoint-args.py
@@ -146,6 +146,10 @@ def qualify(binary, values, draft=("", "", ""), *, spec_type="", spec_default=""
default_checkpoints = defaults and _unquote(values[1] if len(values) > 1 else "") == ""
handle_reasoning = defaults and reasoning is not None
reasoning_mode = _unquote(reasoning or "") or "off"
+ # Modes are case-insensitive, as in ods-host-agent.py; llama-server only
+ # accepts the lowercase spelling.
+ if reasoning_mode.lower() in REASONING_CHOICES:
+ reasoning_mode = reasoning_mode.lower()
fallback_format = _unquote(reasoning_format)
if fallback_format and not re.fullmatch(r"[A-Za-z0-9_.,-]{1,64}", fallback_format):
raise ValueError("--reasoning-format requires a llama.cpp format name")
diff --git a/ods/installers/macos/ods-macos.sh b/ods/installers/macos/ods-macos.sh
index 5ef46cb91..d8a22e2bb 100755
--- a/ods/installers/macos/ods-macos.sh
+++ b/ods/installers/macos/ods-macos.sh
@@ -835,6 +835,11 @@ start_native_llama() {
mkdir -p "$(dirname "$LLAMA_SERVER_PID_FILE")"
local reasoning="${ENV_LLAMA_REASONING:-off}"
+ # Modes are case-insensitive, as in ods-host-agent.py; llama-server only
+ # accepts the lowercase spelling.
+ local reasoning_lower
+ reasoning_lower="$(printf '%s' "$reasoning" | tr '[:upper:]' '[:lower:]')"
+ case "$reasoning_lower" in off|on|auto) reasoning="$reasoning_lower" ;; esac
# Map .env values (off/on/auto) to llama-server --reasoning-format values
local reasoning_fmt
case "$reasoning" in
diff --git a/ods/scripts/bootstrap-upgrade.sh b/ods/scripts/bootstrap-upgrade.sh
index 44a15ba6e..94f5b49a4 100644
--- a/ods/scripts/bootstrap-upgrade.sh
+++ b/ods/scripts/bootstrap-upgrade.sh
@@ -2268,6 +2268,10 @@ elif [[ -f "$INSTALL_DIR/data/.llama-server.pid" ]]; then
# from consuming the entire token budget on internal reasoning)
_reasoning=$(grep '^LLAMA_REASONING=' "$ENV_FILE" 2>/dev/null | cut -d= -f2 || echo "")
[[ -z "$_reasoning" ]] && _reasoning="off"
+ # Normalize mode names before deriving both launch and rollback
+ # arguments; custom reasoning-format names retain their spelling.
+ _reasoning_lower="$(printf '%s' "$_reasoning" | tr '[:upper:]' '[:lower:]')"
+ case "$_reasoning_lower" in off|on|auto) _reasoning="$_reasoning_lower" ;; esac
case "$_reasoning" in
off) _reasoning_fmt="none" ;;
on) _reasoning_fmt="deepseek" ;;
diff --git a/ods/tests/test_macos_runtime_llama_args.py b/ods/tests/test_macos_runtime_llama_args.py
index 6dff6fba7..eb3e1e429 100644
--- a/ods/tests/test_macos_runtime_llama_args.py
+++ b/ods/tests/test_macos_runtime_llama_args.py
@@ -144,7 +144,10 @@ class QualifiedArgumentTests(unittest.TestCase):
# --reasoning left at auto) logged "thinking = 1" and returned a reasoning
# trace as content; with --reasoning off it still put "<think>\n\n</think>\n\n"
# in every content. --reasoning off with the default format matched b8210.
- for value, expected in (("", "off"), ("off", "off"), ('"on"', "on"), ("auto", "auto")):
+ # Modes are case-insensitive, as the host agent reads them; llama-server
+ # only accepts lowercase.
+ for value, expected in (("", "off"), ("off", "off"), ('"on"', "on"), ("auto", "auto"),
+ ("OFF", "off"), ('"On"', "on"), ("AUTO", "auto")):
with self.subTest(value=value):
result, _ = run_with_help(HELP["b9014"], EMPTY, defaults=True, spec_default="none",
reasoning=value, reasoning_format="none")
@@ -345,6 +348,13 @@ for arg in ${MACOS_NATIVE_CHECKPOINT_ARGS[@]+"${MACOS_NATIVE_CHECKPOINT_ARGS[@]}
argv = self.run_bash(script)
self.assertEqual(argv[argv.index("--model") + 1], str(self.install / "data/models/Qwen3.5-9B-Q4_K_M.gguf"))
self.assert_argv(argv, release)
+ # An uppercase mode used to become --reasoning-format OFF, which
+ # llama-server rejects at startup.
+ (self.install / ".env").write_text(self.ENV.replace("LLAMA_REASONING=off", "LLAMA_REASONING=OFF"))
+ for release in ("b8210", "b9014"):
+ with self.subTest(release=release, reasoning="OFF"):
+ self.use_runtime(release)
+ self.assert_argv(self.run_bash(script), release)
(self.install / ".env").write_text(self.ENV + "LLAMA_SPEC_TYPE=none\n")
self.assert_argv(self.run_bash(script), "b9014", spec=False)
@@ -366,6 +376,11 @@ for arg in ${MACOS_NATIVE_CHECKPOINT_ARGS[@]+"${MACOS_NATIVE_CHECKPOINT_ARGS[@]}
argv = self.run_bash(script)
self.assertEqual(argv[argv.index("--model") + 1], str(self.install / "data/models/model.gguf"))
self.assert_argv(argv, release)
+ (self.install / ".env").write_text(self.ENV.replace("LLAMA_REASONING=off", "LLAMA_REASONING=Off"))
+ for release in ("b8210", "b9014"):
+ with self.subTest(release=release, reasoning="Off"):
+ self.use_runtime(release)
+ self.assert_argv(self.run_bash(script), release)
def test_bootstrap_full_model_swap(self):
source = (ROOT / "scripts/bootstrap-upgrade.sh").read_text(encoding="utf-8")
@@ -386,6 +401,51 @@ for arg in ${MACOS_NATIVE_CHECKPOINT_ARGS[@]+"${MACOS_NATIVE_CHECKPOINT_ARGS[@]}
(self.install / ".env").write_text("LLAMA_ARG_SPEC_DRAFT_N_MAX=0\n")
self.assertEqual(self.run_bash(script), ["--reasoning-format", "none"])
+ def test_bootstrap_reasoning_case_survives_fallback_and_rollback(self):
+ source = (ROOT / "scripts/bootstrap-upgrade.sh").read_text(encoding="utf-8")
+ block = section(source, " # Read reasoning mode from .env", " # Capture old model path")
+ rollback = section(source, ' if [[ -n "${_old_model_path:-}"',
+ ' _rollback_pid=')
+ rollback = rollback[rollback.index(' bash "'):]
+ script = (
+ "set -uo pipefail\n"
+ 'ENV_FILE="$INSTALL/.env"; INSTALL_DIR="$INSTALL"; LLAMA_SERVER_BIN="$RUNTIME"\n'
+ + self.STUBS +
+ "log() { echo \"$*\" >&2; }\n"
+ 'read_env_value() { grep -E "^$1=" "$ENV_FILE" | head -1 | cut -d= -f2-; }\n'
+ + block
+ )
+ forward = '\nfor arg in ${_llama_tuning_args[@]+"${_llama_tuning_args[@]}"}; do printf "%s\\0" "$arg"; done\n'
+ rollback_setup = (
+ '\nLLAMA_SERVER_PID_FILE="$INSTALL/data/llama.pid"\n'
+ '_old_model_path="$INSTALL/data/models/old.gguf"; _bind=127.0.0.1\n'
+ '_native_port=9999; _ctx_size=4096; _gpu_layers=0\n'
+ )
+ for raw, mode, fmt in (("OFF", "off", "none"), ("Off", "off", "none"),
+ ("ON", "on", "deepseek"), ("AUTO", "auto", "auto"),
+ ("deepseek", "deepseek", "deepseek"),
+ ("DeepSeek", "DeepSeek", "DeepSeek")):
+ for release in ("b8210", "b9014"):
+ with self.subTest(reasoning=raw, release=release):
+ self.use_runtime(release)
+ (self.install / ".env").write_text(f"LLAMA_REASONING={raw}\n")
+ argv = self.run_bash(script + forward)
+ if release == "b9014" and mode in {"off", "on", "auto"}:
+ self.assertEqual(argv[argv.index("--reasoning") + 1], mode)
+ self.assertNotIn("--reasoning-format", argv)
+ else:
+ self.assertEqual(argv[argv.index("--reasoning-format") + 1], fmt)
+ self.assertNotIn("--reasoning", argv)
+ # Exercise the real rollback launch through the existing
+ # service stub; forward argv alone cannot prove this path.
+ argv = self.run_bash(script + rollback_setup + rollback)
+ self.assertEqual(argv[argv.index("--reasoning-format") + 1], fmt)
+ self.assertNotIn("--reasoning", argv)
+ # Refused tuning keeps the mapped format when qualification
+ # falls back, rather than forwarding the raw mode spelling.
+ (self.install / ".env").write_text(f"LLAMA_REASONING={raw}\nLLAMA_ARG_SPEC_DRAFT_N_MAX=0\n")
+ self.assertEqual(self.run_bash(script + forward), ["--reasoning-format", fmt])
+
class LauncherContractTests(unittest.TestCase):
def test_pinned_release_is_checksummed_and_has_ngram_mod(self):