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(llama): accept Docker reasoning modes in any case (#8279)

Mike Bradley3221546cd43d
diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml
index 2994e8e13..9fbbc20ca 100644
--- a/.github/workflows/test-linux.yml
+++ b/.github/workflows/test-linux.yml
@@ -520,6 +520,9 @@ jobs:
- name: CPU-Only Path Tests
run: bash tests/test-cpu-only-path.sh
+ - name: Docker Reasoning Mode Entrypoint
+ run: python3 -m unittest discover -s tests -p 'test_llama_reasoning_*.py' -v
+
- name: Hermes Default and Opt-in Owner-card Access
run: |
bash tests/test-hermes-proxy-caddyfile.sh
diff --git a/ods/.env.example b/ods/.env.example
index 942e83e23..107ca9ffd 100644
--- a/ods/.env.example
+++ b/ods/.env.example
@@ -218,6 +218,12 @@ MODEL_RUNTIME_PROFILE_SOURCE=
SYSTEM_RAM_GB=32
# Optional llama.cpp image override (installer sets this automatically for runtime profiles)
+# Docker launches /app/llama-server (official images) or llama-server on PATH
+# (the local Arc build). Custom images needing a different startup wrapper
+# must set entrypoint in their Compose override. Command args pass unchanged.
+# LLAMA_REASONING accepts on/off/auto in any case. Environment validation
+# rejects unknown values; direct Compose launches pass them through unchanged
+# so llama.cpp can report the error.
# LLAMA_SERVER_IMAGE=ghcr.io/ggml-org/llama.cpp:server-cuda-b11429@sha256:883915ea20a4b350e98f7284098f4d400c21e9b366e248d397cd42d90602a84c
# Optional explicit fallback if a custom llama.cpp image tag disappears
# LLAMA_SERVER_IMAGE_FALLBACK=ghcr.io/ggml-org/llama.cpp:server-cuda-b9014@sha256:fcf285820892e7ce3218379634e3590826fc697e8b6745b9392072462e355c4f
diff --git a/ods/.env.schema.json b/ods/.env.schema.json
index 7c301f6cc..141526ade 100644
--- a/ods/.env.schema.json
+++ b/ods/.env.schema.json
@@ -1678,8 +1678,13 @@
},
"LLAMA_REASONING": {
"type": "string",
- "description": "llama.cpp reasoning/thinking mode: off (default) | auto | on. Off prevents thinking models from consuming the entire token budget on internal reasoning.",
- "enum": ["off", "auto", "on"],
+ "description": "llama.cpp reasoning/thinking mode: off (default) | auto | on, in any letter case. Off prevents thinking models from consuming the entire token budget on internal reasoning.",
+ "enum": [
+ "off", "auto", "on", "AUTO", "AUTo", "AUtO", "AUto",
+ "AuTO", "AuTo", "AutO", "Auto", "OFF", "OFf", "ON",
+ "OfF", "Off", "On", "aUTO", "aUTo", "aUtO", "aUto",
+ "auTO", "auTo", "autO", "oFF", "oFf", "oN", "ofF"
+ ],
"default": "off"
},
"LLAMA_ARG_FLASH_ATTN": {
diff --git a/ods/docker-compose.base.yml b/ods/docker-compose.base.yml
index 4cb6ef7c5..ff2a600aa 100644
--- a/ods/docker-compose.base.yml
+++ b/ods/docker-compose.base.yml
@@ -25,6 +25,9 @@ services:
image: ${LLAMA_SERVER_IMAGE:-ghcr.io/ggml-org/llama.cpp:server-b9014@sha256:2e7953dfef88f302bf0683bffa7dc1f8d86ef75910380bc41126ec5b8bedaf53}
container_name: ods-llama-server
restart: unless-stopped
+ # Normalize reasoning modes on every launch, including CLI restarts,
+ # model switches and direct Compose use. The wrapper execs the server.
+ entrypoint: ["/bin/sh", "/opt/ods/llama-server-entrypoint.sh"]
# config/llama-server/models.ini is not mounted: llama-server reads a
# preset file only with --models-preset (router mode), which ODS does not
# use; the model comes from --model below. ODS still writes models.ini as
@@ -34,6 +37,7 @@ services:
# Fixed chat templates ODS vendors from llama.cpp (any-model WP5), read
# only when LLAMA_ARG_CHAT_TEMPLATE_FILE below names one.
- ./config/chat-templates:/chat-templates:ro,z
+ - ./extensions/services/llama-server/llama-server-entrypoint.sh:/opt/ods/llama-server-entrypoint.sh:ro,z
ports:
- "127.0.0.1:${OLLAMA_PORT:-11434}:8080"
command:
diff --git a/ods/extensions/services/llama-server/llama-server-entrypoint.sh b/ods/extensions/services/llama-server/llama-server-entrypoint.sh
new file mode 100644
index 000000000..60dcbb8df
--- /dev/null
+++ b/ods/extensions/services/llama-server/llama-server-entrypoint.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Normalize known reasoning modes at every Docker launch. Preserve unknown
+# values for llama.cpp to diagnose, and keep empty distinct from unset.
+set -eu
+
+case "${LLAMA_ARG_REASONING-}" in
+ [Oo][Nn]) export LLAMA_ARG_REASONING=on ;;
+ [Oo][Ff][Ff]) export LLAMA_ARG_REASONING=off ;;
+ [Aa][Uu][Tt][Oo]) export LLAMA_ARG_REASONING=auto ;;
+esac
+
+# Official images use /app; the local Arc SYCL image installs on PATH.
+# Replace this process so the server receives the original args and signals.
+if [ -x /app/llama-server ]; then
+ exec /app/llama-server "$@"
+fi
+exec llama-server "$@"
diff --git a/ods/installers/lib/pixel-host-install.sh b/ods/installers/lib/pixel-host-install.sh
index d4b0e0266..3134aa1a8 100644
--- a/ods/installers/lib/pixel-host-install.sh
+++ b/ods/installers/lib/pixel-host-install.sh
@@ -4846,7 +4846,8 @@ _ods_pixel_write_onboarding() {
# route keeps the historical no-think default. The renderer preserves a
# previously validated reasoning preference for the same model route.
if [[ -n "${LLAMA_REASONING+x}" ]]; then
- if [[ "${LLAMA_REASONING:-off}" =~ ^(off|none|false|0)$ ]]; then
+ # Case-insensitive, as ods-host-agent.py reads LLAMA_REASONING.
+ if [[ "$(printf '%s' "${LLAMA_REASONING:-off}" | tr '[:upper:]' '[:lower:]')" =~ ^(off|none|false|0)$ ]]; then
reasoning=false
else
reasoning=true
diff --git a/ods/tests/test-pixel-host-install.sh b/ods/tests/test-pixel-host-install.sh
index dd5ce2ab2..8732ccb6b 100644
--- a/ods/tests/test-pixel-host-install.sh
+++ b/ods/tests/test-pixel-host-install.sh
@@ -2121,6 +2121,12 @@ _ods_pixel_write_onboarding "$owner" "$home" "$TEST_ROOT/qwen-reasoning-onboardi
/usr/bin/openclaw /opt/ods/pixel-plugin "$digest"
check python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); assert v["modelReasoning"] is True' \
"$TEST_ROOT/qwen-reasoning-onboarding.json"
+# Case-insensitive, as the host agent reads LLAMA_REASONING: OFF is off.
+LLAMA_REASONING=OFF
+_ods_pixel_write_onboarding "$owner" "$home" "$TEST_ROOT/qwen-reasoning-upper-off.json" \
+ /usr/bin/openclaw /opt/ods/pixel-plugin "$digest"
+check python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); assert v["modelReasoning"] is False' \
+ "$TEST_ROOT/qwen-reasoning-upper-off.json"
LLAMA_REASONING=off
MAX_CONTEXT=4096
if _ods_pixel_write_onboarding "$owner" "$home" "$TEST_ROOT/undersized-onboarding.json" \
diff --git a/ods/tests/test_llama_reasoning_compose.py b/ods/tests/test_llama_reasoning_compose.py
new file mode 100644
index 000000000..1742eeb34
--- /dev/null
+++ b/ods/tests/test_llama_reasoning_compose.py
@@ -0,0 +1,96 @@
+import json
+import os
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+ENTRY = ROOT / "extensions/services/llama-server/llama-server-entrypoint.sh"
+MODES = ["cpu", "nvidia", "intel", "arc", "amd", "amd-rocm", "apple"]
+ENV = {
+ "WEBUI_SECRET": "dummy-webui",
+ "SEARXNG_SECRET": "dummy-searxng",
+ "LITELLM_KEY": "dummy-litellm",
+ "N8N_USER": "dummy-user",
+ "N8N_PASS": "dummy-pass",
+ "LLAMA_REASONING": "OFF",
+}
+
+
+def compose_config(files):
+ cmd = ["docker", "compose"]
+ for f in files:
+ cmd += ["-f", str(f)]
+ cmd += ["config", "--format", "json"]
+ env = {**os.environ, **ENV}
+ r = subprocess.run(cmd, cwd=ROOT, env=env, capture_output=True,
+ text=True, timeout=30, check=True)
+ return json.loads(r.stdout)
+
+
+def base_files():
+ return [ROOT / "docker-compose.base.yml"]
+
+
+def overlay(mode):
+ return ROOT / f"docker-compose.{mode}.yml"
+
+
+class TestComposeModes(unittest.TestCase):
+ def _check(self, cfg):
+ svc = cfg["services"]["llama-server"]
+ env = svc.get("environment", {})
+ if isinstance(env, list):
+ env = dict(e.split("=", 1) for e in env if "=" in e)
+ self.assertEqual(env.get("LLAMA_ARG_REASONING"), "OFF",
+ "LLAMA_ARG_REASONING not OFF")
+ self.assertEqual(svc.get("entrypoint"),
+ ["/bin/sh", "/opt/ods/llama-server-entrypoint.sh"],
+ "entrypoint mismatch")
+ vols = svc.get("volumes", [])
+ matches = [v for v in vols
+ if isinstance(v, dict)
+ and v.get("target") == "/opt/ods/llama-server-entrypoint.sh"]
+ self.assertEqual(len(matches), 1, "entrypoint mount count != 1")
+ m = matches[0]
+ self.assertTrue(m.get("read_only"), "entrypoint mount not read-only")
+ src = Path(m["source"])
+ if not src.is_absolute():
+ src = (ROOT / src).resolve()
+ self.assertEqual(src, ENTRY.resolve(), "entrypoint source mismatch")
+ cmd = svc.get("command", [])
+ if isinstance(cmd, str):
+ cmd = cmd.split()
+ self.assertIn("--model", cmd, "missing --model")
+ self.assertIn("--metrics", cmd, "missing --metrics")
+
+ def test_all_modes(self):
+ for mode in MODES:
+ with self.subTest(mode=mode):
+ cfg = compose_config(base_files() + [overlay(mode)])
+ self._check(cfg)
+
+ def test_user_entrypoint_override_wins(self):
+ override = {
+ "services": {
+ "llama-server": {
+ "entrypoint": ["/bin/true"],
+ }
+ }
+ }
+ with tempfile.NamedTemporaryFile(
+ "w", suffix=".yml", encoding="utf-8", delete=False) as f:
+ json.dump(override, f)
+ tmp = Path(f.name)
+ try:
+ cfg = compose_config(base_files() + [overlay("cpu"), tmp])
+ svc = cfg["services"]["llama-server"]
+ self.assertEqual(svc.get("entrypoint"), ["/bin/true"],
+ "user entrypoint override lost")
+ finally:
+ tmp.unlink(missing_ok=True)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/ods/tests/test_llama_reasoning_entrypoint.py b/ods/tests/test_llama_reasoning_entrypoint.py
new file mode 100644
index 000000000..f940a912b
--- /dev/null
+++ b/ods/tests/test_llama_reasoning_entrypoint.py
@@ -0,0 +1,182 @@
+import json
+import os
+import selectors
+import signal
+import subprocess
+import sys
+import tempfile
+import time
+import unittest
+from pathlib import Path
+
+WRAPPER = (
+ Path(__file__).resolve().parents[1]
+ / "extensions/services/llama-server/llama-server-entrypoint.sh"
+)
+
+# Fake server: prints a JSON line with argv/pid/env, flushes, then either
+# exits with FAKE_EXIT or waits for SIGTERM via signal.pause().
+FAKE_SERVER_SOURCE = """#!{python}
+import json, os, signal, sys
+print(json.dumps({{
+ "argv": sys.argv,
+ "pid": os.getpid(),
+ "reasoning_present": "LLAMA_ARG_REASONING" in os.environ,
+ "reasoning_value": os.environ.get("LLAMA_ARG_REASONING"),
+}}), flush=True)
+mode = os.environ.get("FAKE_MODE", "exit")
+if mode == "wait":
+ while True:
+ signal.pause()
+else:
+ sys.exit(int(os.environ.get("FAKE_EXIT", "0")))
+"""
+
+
+class LlamaReasoningEntrypointTest(unittest.TestCase):
+ def setUp(self):
+ self.assertTrue(WRAPPER.is_file(), f"wrapper missing: {WRAPPER}")
+ self.assertFalse(
+ os.path.exists("/app/llama-server") and os.access("/app/llama-server", os.X_OK),
+ "unit test host must not have executable /app/llama-server",
+ )
+ self._tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self._tmp.cleanup)
+ self.tmpdir = Path(self._tmp.name)
+ self.bindir = self.tmpdir / "bin"
+ self.bindir.mkdir()
+ fake = self.bindir / "llama-server"
+ fake.write_text(FAKE_SERVER_SOURCE.format(python=sys.executable))
+ fake.chmod(0o755)
+ self.fake = fake
+
+ def _env(self, reasoning=..., extra=None):
+ env = {k: v for k, v in os.environ.items() if k not in ("LLAMA_ARG_REASONING", "FAKE_MODE", "FAKE_EXIT")}
+ env["PATH"] = f"{self.bindir}{os.pathsep}{env.get('PATH', '')}"
+ if reasoning is not ...:
+ env["LLAMA_ARG_REASONING"] = reasoning
+ if extra:
+ env.update(extra)
+ return env
+
+ def _run(self, args, reasoning=..., extra=None):
+ return subprocess.run(
+ ["/bin/sh", str(WRAPPER), *args],
+ env=self._env(reasoning, extra),
+ capture_output=True,
+ text=True,
+ timeout=30,
+ )
+
+ def _run_json(self, args, reasoning=..., extra=None):
+ proc = self._run(args, reasoning, extra)
+ self.assertEqual(proc.returncode, 0, proc.stderr)
+ return json.loads(proc.stdout)
+
+ def _read_json_line(self, proc, timeout=10.0):
+ """Read one JSON line from proc.stdout with a bounded timeout."""
+ sel = selectors.DefaultSelector()
+ try:
+ sel.register(proc.stdout, selectors.EVENT_READ)
+ deadline = time.monotonic() + timeout
+ buf = b""
+ while b"\n" not in buf:
+ remaining = deadline - time.monotonic()
+ if remaining <= 0:
+ self.fail("timed out waiting for fake server output")
+ events = sel.select(timeout=remaining)
+ if not events:
+ self.fail("timed out waiting for fake server output")
+ chunk = os.read(proc.stdout.fileno(), 4096)
+ if not chunk:
+ self.fail(f"fake server closed stdout before newline; got {buf!r}")
+ buf += chunk
+ line, _, _rest = buf.partition(b"\n")
+ return json.loads(line.decode("utf-8"))
+ finally:
+ sel.close()
+
+ def _kill_group(self, proc):
+ try:
+ os.killpg(proc.pid, signal.SIGKILL)
+ except ProcessLookupError:
+ # The scoped process group already exited; no child remains.
+ pass
+ try:
+ proc.wait(timeout=30)
+ except subprocess.TimeoutExpired:
+ self.fail("process did not exit after SIGKILL")
+
+ def test_case_insensitive_off(self):
+ for value in ("OFF", "Off", "oFf", "off"):
+ with self.subTest(value=value):
+ data = self._run_json([], reasoning=value)
+ self.assertTrue(data["reasoning_present"])
+ self.assertEqual(data["reasoning_value"], "off")
+
+ def test_case_insensitive_on(self):
+ for value in ("ON", "oN", "On", "on"):
+ with self.subTest(value=value):
+ data = self._run_json([], reasoning=value)
+ self.assertTrue(data["reasoning_present"])
+ self.assertEqual(data["reasoning_value"], "on")
+
+ def test_case_insensitive_auto(self):
+ for value in ("AUTO", "Auto", "aUtO", "auto"):
+ with self.subTest(value=value):
+ data = self._run_json([], reasoning=value)
+ self.assertTrue(data["reasoning_present"])
+ self.assertEqual(data["reasoning_value"], "auto")
+
+ def test_unknown_values_unchanged(self):
+ for value in ("custom-format", " OFF ", "on;echo hi", "$(echo hi)", "`echo hi`", "*", "on off"):
+ with self.subTest(value=value):
+ data = self._run_json([], reasoning=value)
+ self.assertTrue(data["reasoning_present"])
+ self.assertEqual(data["reasoning_value"], value)
+
+ def test_empty_vs_unset(self):
+ empty = self._run_json([], reasoning="")
+ self.assertTrue(empty["reasoning_present"])
+ self.assertEqual(empty["reasoning_value"], "")
+
+ unset = self._run_json([], reasoning=...)
+ self.assertFalse(unset["reasoning_present"])
+ self.assertIsNone(unset["reasoning_value"])
+
+ def test_argv_preserved(self):
+ args = ["a b", "c'd", 'e"f', "$HOME", "`echo hi`", "*", "x\ty", ""]
+ data = self._run_json(args, reasoning="on")
+ # sys.argv[0] is the resolved fake executable path, not literal "llama-server".
+ self.assertEqual(data["argv"][0], str(self.fake))
+ self.assertEqual(data["argv"][1:], args)
+
+ def test_child_exit_code_propagates(self):
+ proc = self._run([], reasoning="on", extra={"FAKE_EXIT": "42"})
+ self.assertEqual(proc.returncode, 42)
+
+ def test_pid_matches_and_sigterm(self):
+ env = self._env("on", extra={"FAKE_MODE": "wait"})
+ proc = subprocess.Popen(
+ ["/bin/sh", str(WRAPPER)],
+ env=env,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ start_new_session=True,
+ )
+ try:
+ data = self._read_json_line(proc, timeout=10.0)
+ self.assertEqual(data["pid"], proc.pid)
+ os.kill(proc.pid, signal.SIGTERM)
+ proc.wait(timeout=30)
+ self.assertEqual(proc.returncode, -signal.SIGTERM)
+ finally:
+ self._kill_group(proc)
+ if proc.stdout is not None:
+ proc.stdout.close()
+ if proc.stderr is not None:
+ proc.stderr.close()
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/ods/tests/test_llama_reasoning_schema.py b/ods/tests/test_llama_reasoning_schema.py
new file mode 100644
index 000000000..95c11df2f
--- /dev/null
+++ b/ods/tests/test_llama_reasoning_schema.py
@@ -0,0 +1,51 @@
+"""Exercise the installer/CLI validator with the same modes Docker accepts."""
+
+import itertools
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+BASE_ENV = """WEBUI_SECRET=test-webui-secret
+SEARXNG_SECRET=test-searxng-secret
+N8N_PASS=test-pass-1234
+LITELLM_KEY=sk-test-key-1234
+"""
+
+
+class ReasoningSchemaTest(unittest.TestCase):
+ def validate(self, value, key="LLAMA_REASONING"):
+ with tempfile.TemporaryDirectory(prefix="ods-reasoning-schema-") as temp:
+ env_file = Path(temp) / ".env"
+ env_file.write_text(BASE_ENV + f"{key}={value}\n", encoding="utf-8")
+ return subprocess.run(
+ ["/bin/bash", str(ROOT / "scripts/validate-env.sh"),
+ str(env_file), str(ROOT / ".env.schema.json")],
+ capture_output=True, text=True, timeout=30,
+ )
+
+ def test_all_known_case_variants_validate(self):
+ for mode in ("off", "on", "auto"):
+ for letters in itertools.product(*[(c, c.upper()) for c in mode]):
+ value = "".join(letters)
+ with self.subTest(value=value):
+ result = self.validate(value)
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+
+ def test_unknown_modes_still_fail_validation(self):
+ for value in ("enabled", "custom-format", "on off"):
+ with self.subTest(value=value):
+ result = self.validate(value)
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
+ self.assertIn("LLAMA_REASONING: invalid value", result.stdout)
+
+ def test_other_case_sensitive_settings_are_unchanged(self):
+ result = self.validate("AUTO", key="N_GPU_LAYERS")
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
+ self.assertIn("N_GPU_LAYERS", result.stdout)
+
+
+if __name__ == "__main__":
+ unittest.main()