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(dashboard-api): read the configured model through the owner's host agent (#8251)

Mike Bradleycd1fcdab3bf1
diff --git a/ods/bin/ods-host-agent.py b/ods/bin/ods-host-agent.py
index 0b14c19a9..f368a24a4 100755
--- a/ods/bin/ods-host-agent.py
+++ b/ods/bin/ods-host-agent.py
@@ -8369,6 +8369,26 @@ def _valid_gguf_filename(value: object) -> bool:
)
+def _configured_model_identity(env: dict) -> dict:
+ """The configured model's name, GGUF file and context from .env, each bounded.
+
+ For the Dashboard API when it cannot read the owner's private .env. A
+ value that does not validate is reported as None, never echoed.
+ """
+ context = None
+ for key in ("CTX_SIZE", "MAX_CONTEXT"):
+ value = str(env.get(key) or "")
+ if re.fullmatch(r"[1-9][0-9]{0,8}", value):
+ context = int(value)
+ break
+ llm_model, gguf_file = env.get("LLM_MODEL"), env.get("GGUF_FILE")
+ return {
+ "llmModel": llm_model if _valid_pixel_model_name(llm_model) else None,
+ "ggufFile": gguf_file if _valid_gguf_filename(gguf_file) else None,
+ "contextSize": context,
+ }
+
+
def _local_gguf_filename_from_id(model_id: str) -> str | None:
"""Map a Dashboard/local model id to a safe GGUF filename candidate."""
token = str(model_id or "").strip()
@@ -13761,16 +13781,22 @@ class AgentHandler(BaseHTTPRequestHandler):
json_response(self, 500, {"error": f"Failed to list models: {exc}"})
def _handle_model_config(self):
- """Expose the two bounded mode identities, never private .env values."""
+ """Expose bounded configuration identities, never private .env values.
+
+ The Dashboard API asks here when the install owner's private .env is
+ not readable by its UID: the persisted mode, and the configured
+ model's name, GGUF file and context, each validated.
+ """
if not check_auth(self):
return
try:
- mode = _normalize_ods_mode(load_env(INSTALL_DIR / ".env").get("ODS_MODE"))
+ env = load_env(INSTALL_DIR / ".env")
except (OSError, UnicodeError):
- mode = "unknown"
+ env = None
json_response(self, 200, {
- "configuredMode": mode,
+ "configuredMode": _normalize_ods_mode(env.get("ODS_MODE")) if env is not None else "unknown",
"effectiveMode": _normalize_ods_mode(STARTUP_ODS_MODE),
+ "configuredModel": _configured_model_identity(env) if env is not None else None,
}, no_store=True)
def _handle_model_status(self):
diff --git a/ods/extensions/services/dashboard-api/helpers.py b/ods/extensions/services/dashboard-api/helpers.py
index b17f510cf..2a87edc99 100644
--- a/ods/extensions/services/dashboard-api/helpers.py
+++ b/ods/extensions/services/dashboard-api/helpers.py
@@ -25,6 +25,7 @@ from config import (
from env_values import parse_env_value
from host_metrics import apple_host_metrics, linux_scope, windows_host_metrics
from host_agent_client import AgentClientError, AgentHTTPError, async_request_json as request_agent_json
+from host_agent_client import request_json as request_agent_json_sync
from models import ServiceStatus, DiskUsage, ModelInfo, BootstrapStatus
from service_health_dns import ServiceHealthResolver
@@ -1313,86 +1314,110 @@ def get_disk_usage() -> DiskUsage:
return DiskUsage(path=path, used_gb=round(used / (1024**3), 2), total_gb=round(total / (1024**3), 2), percent=percent)
+def owner_model_config() -> Optional[dict]:
+ """The configured model as the install owner's host agent reads it from .env.
+
+ For an install owner other than UID 1000, whose private .env this API
+ cannot read (Workstation06, 2026-10-26: nvuser, UID 1001). The agent
+ returns only validated identities. None when it cannot answer.
+ """
+ try:
+ snapshot = request_agent_json_sync("GET", "/v1/model/config", timeout=5)
+ except AgentClientError:
+ return None
+ model = snapshot.get("configuredModel") if isinstance(snapshot, dict) else None
+ return model if isinstance(model, dict) else None
+
+
def get_model_info() -> Optional[ModelInfo]:
"""Get current model info from .env config."""
env_path = Path(INSTALL_DIR) / ".env"
- if env_path.exists():
- try:
- env_values = {}
- with open(env_path) as f:
- for line in f:
- if "=" not in line or line.lstrip().startswith("#"):
- continue
- key, value = line.split("=", 1)
- key = key.strip()
- if not key:
- continue
- value = parse_env_value(value)
- env_values[key] = value
-
- model_name = env_values.get("LLM_MODEL")
- if model_name:
- size_gb, quant = 15.0, None
- # CTX_SIZE/MAX_CONTEXT come straight from .env and may be
- # non-numeric (e.g. "auto", "8k", or a trailing comment); fall
- # back to the default rather than 500-ing every caller. Mirrors
- # the guard already used in routers/models.py.
- context = 32768
- for key in ("CTX_SIZE", "MAX_CONTEXT"):
- try:
- candidate = int(env_values.get(key) or 0)
- except (TypeError, ValueError):
- continue
- if candidate > 0:
- context = candidate
- break
+ if not env_path.exists():
+ return None
+ try:
+ env_values = {}
+ with open(env_path) as f:
+ for line in f:
+ if "=" not in line or line.lstrip().startswith("#"):
+ continue
+ key, value = line.split("=", 1)
+ key = key.strip()
+ if not key:
+ continue
+ value = parse_env_value(value)
+ env_values[key] = value
+ except PermissionError:
+ # An install owner other than UID 1000 keeps its private .env from this
+ # API: every status poll logged the refusal and the Dashboard showed no
+ # configured model. The owner's host agent reads it instead.
+ owner = owner_model_config() or {}
+ env_values = {"LLM_MODEL": owner.get("llmModel") or "", "GGUF_FILE": owner.get("ggufFile") or "",
+ "CTX_SIZE": str(owner.get("contextSize") or "")}
+ except OSError as e:
+ logger.warning("Failed to read .env for model info: %s", e)
+ return None
- import re as _re
-
- name_lower = model_name.lower()
- if "gemma-4-e2b" in name_lower:
- size_gb = 2.8
- elif "gemma-4-e4b" in name_lower:
- size_gb = 5.3
- elif "gemma-4-26b" in name_lower:
- size_gb = 18.0
- elif "gemma-4-31b" in name_lower:
- size_gb = 19.8
- elif _re.search(r'\b2b\b', name_lower):
- size_gb = 1.5
- elif _re.search(r'\b4b\b', name_lower):
- size_gb = 2.8
- elif _re.search(r'\b7b\b', name_lower):
- size_gb = 4.0
- elif _re.search(r'\b8b\b', name_lower):
- size_gb = 4.5
- elif _re.search(r'\b9b\b', name_lower):
- size_gb = 5.8
- elif _re.search(r'\b14b\b', name_lower):
- size_gb = 8.0
- elif _re.search(r'\b26b\b', name_lower):
- size_gb = 18.0
- elif _re.search(r'\b30b\b', name_lower):
- size_gb = 18.6
- elif _re.search(r'\b31b\b', name_lower):
- size_gb = 19.8
- elif _re.search(r'\b32b\b', name_lower):
- size_gb = 16.0
- elif _re.search(r'\b70b\b', name_lower):
- size_gb = 35.0
-
- gguf_file = env_values.get("GGUF_FILE", "").lower()
- if "awq" in name_lower:
- quant = "AWQ"
- elif "gptq" in name_lower:
- quant = "GPTQ"
- elif "gguf" in name_lower or gguf_file.endswith(".gguf"):
- quant = "GGUF"
-
- return ModelInfo(name=model_name, size_gb=size_gb, context_length=context, quantization=quant)
- except OSError as e:
- logger.warning("Failed to read .env for model info: %s", e)
- return None
+ model_name = env_values.get("LLM_MODEL")
+ if not model_name:
+ return None
+ size_gb, quant = 15.0, None
+ # CTX_SIZE/MAX_CONTEXT come straight from .env and may be
+ # non-numeric (e.g. "auto", "8k", or a trailing comment); fall
+ # back to the default rather than 500-ing every caller. Mirrors
+ # the guard already used in routers/models.py.
+ context = 32768
+ for key in ("CTX_SIZE", "MAX_CONTEXT"):
+ try:
+ candidate = int(env_values.get(key) or 0)
+ except (TypeError, ValueError):
+ continue
+ if candidate > 0:
+ context = candidate
+ break
+
+ import re as _re
+
+ name_lower = model_name.lower()
+ if "gemma-4-e2b" in name_lower:
+ size_gb = 2.8
+ elif "gemma-4-e4b" in name_lower:
+ size_gb = 5.3
+ elif "gemma-4-26b" in name_lower:
+ size_gb = 18.0
+ elif "gemma-4-31b" in name_lower:
+ size_gb = 19.8
+ elif _re.search(r'\b2b\b', name_lower):
+ size_gb = 1.5
+ elif _re.search(r'\b4b\b', name_lower):
+ size_gb = 2.8
+ elif _re.search(r'\b7b\b', name_lower):
+ size_gb = 4.0
+ elif _re.search(r'\b8b\b', name_lower):
+ size_gb = 4.5
+ elif _re.search(r'\b9b\b', name_lower):
+ size_gb = 5.8
+ elif _re.search(r'\b14b\b', name_lower):
+ size_gb = 8.0
+ elif _re.search(r'\b26b\b', name_lower):
+ size_gb = 18.0
+ elif _re.search(r'\b30b\b', name_lower):
+ size_gb = 18.6
+ elif _re.search(r'\b31b\b', name_lower):
+ size_gb = 19.8
+ elif _re.search(r'\b32b\b', name_lower):
+ size_gb = 16.0
+ elif _re.search(r'\b70b\b', name_lower):
+ size_gb = 35.0
+
+ gguf_file = env_values.get("GGUF_FILE", "").lower()
+ if "awq" in name_lower:
+ quant = "AWQ"
+ elif "gptq" in name_lower:
+ quant = "GPTQ"
+ elif "gguf" in name_lower or gguf_file.endswith(".gguf"):
+ quant = "GGUF"
+
+ return ModelInfo(name=model_name, size_gb=size_gb, context_length=context, quantization=quant)
def get_bootstrap_status() -> BootstrapStatus:
diff --git a/ods/extensions/services/dashboard-api/routers/models.py b/ods/extensions/services/dashboard-api/routers/models.py
index ff5e44912..c0a8e786e 100644
--- a/ods/extensions/services/dashboard-api/routers/models.py
+++ b/ods/extensions/services/dashboard-api/routers/models.py
@@ -43,6 +43,7 @@ from helpers import (
get_llama_metrics,
get_loaded_model,
is_plausible_single_request_tps,
+ owner_model_config,
record_model_performance,
)
from host_agent_client import (
@@ -394,6 +395,10 @@ def _read_active_model() -> Optional[str]:
for line in _ENV_PATH.read_text(encoding="utf-8").splitlines():
if line.startswith("GGUF_FILE="):
return parse_env_value(line.split("=", 1)[1])
+ except PermissionError:
+ # The install owner's private .env (an owner other than UID 1000):
+ # its host agent reads the active file for this API.
+ return (owner_model_config() or {}).get("ggufFile")
except OSError:
pass
return None
diff --git a/ods/extensions/services/dashboard-api/tests/test_helpers.py b/ods/extensions/services/dashboard-api/tests/test_helpers.py
index 9e688a039..427f07bbe 100644
--- a/ods/extensions/services/dashboard-api/tests/test_helpers.py
+++ b/ods/extensions/services/dashboard-api/tests/test_helpers.py
@@ -1543,6 +1543,57 @@ class TestGetModelInfoErrors:
monkeypatch.setattr(builtins, "open", failing_open)
assert get_model_info() is None
+ @staticmethod
+ def _deny_env(monkeypatch):
+ import builtins
+ orig_open = builtins.open
+
+ def denied(path, *a, **kw):
+ if str(path).endswith(".env"):
+ raise PermissionError(13, "Permission denied", str(path))
+ return orig_open(path, *a, **kw)
+
+ monkeypatch.setattr(builtins, "open", denied)
+
+ def test_private_owner_env_uses_the_owner_host_agent(self, install_dir, monkeypatch):
+ """Workstation06 (owner UID 1001): every status poll logged the
+ refusal and the Dashboard header showed no configured model."""
+ import helpers
+
+ (install_dir / ".env").write_text('LLM_MODEL=stale-process-model\n')
+ self._deny_env(monkeypatch)
+ calls = []
+
+ def owner(method, path, *, timeout):
+ calls.append((method, path, timeout))
+ return {"configuredMode": "local", "effectiveMode": "local", "configuredModel": {
+ "llmModel": "qwen3.6-35b-a3b", "ggufFile": "Qwen3.6-35B-A3B-UD-Q4_K_M.gguf",
+ "contextSize": 131072}}
+
+ monkeypatch.setattr(helpers, "request_agent_json_sync", owner)
+ info = get_model_info()
+ assert (info.name, info.context_length, info.quantization) == ("qwen3.6-35b-a3b", 131072, "GGUF")
+ assert calls == [("GET", "/v1/model/config", 5)]
+
+ @pytest.mark.parametrize("answer", [
+ "unavailable", None, {"configuredMode": "local"}, {"configuredModel": None},
+ {"configuredModel": {"llmModel": None, "ggufFile": None, "contextSize": None}},
+ ])
+ def test_private_owner_env_without_an_owner_model_has_none(self, install_dir, monkeypatch, answer):
+ import helpers
+ from host_agent_client import AgentUnavailable
+
+ (install_dir / ".env").write_text('LLM_MODEL=stale-process-model\n')
+ self._deny_env(monkeypatch)
+
+ def owner(method, path, *, timeout):
+ if answer == "unavailable":
+ raise AgentUnavailable("host agent unavailable")
+ return answer
+
+ monkeypatch.setattr(helpers, "request_agent_json_sync", owner)
+ assert get_model_info() is None
+
# --- get_bootstrap_status eta/percent branches ---
diff --git a/ods/extensions/services/dashboard-api/tests/test_host_agent.py b/ods/extensions/services/dashboard-api/tests/test_host_agent.py
index 157dcc0e2..82bdb43cb 100644
--- a/ods/extensions/services/dashboard-api/tests/test_host_agent.py
+++ b/ods/extensions/services/dashboard-api/tests/test_host_agent.py
@@ -11264,6 +11264,10 @@ class TestDockerServiceHealthSnapshot:
assert len(calls) == 2
+# .env values that name no model: the configured model's identities are all None.
+_NO_CONFIGURED_MODEL = {"llmModel": None, "ggufFile": None, "contextSize": None}
+
+
class TestModelConfig:
@pytest.mark.parametrize(("startup", "expected"), [
@@ -11278,7 +11282,8 @@ class TestModelConfig:
(tmp_path / ".env").write_text("ODS_MODE=local\nHF_TOKEN=private-fixture\n", encoding="utf-8")
handler = _FakeHandler(b"")
_mod.AgentHandler._handle_model_config(handler)
- assert handler.parse_response() == {"configuredMode": "local", "effectiveMode": expected}
+ assert handler.parse_response() == {"configuredMode": "local", "effectiveMode": expected,
+ "configuredModel": _NO_CONFIGURED_MODEL}
@pytest.mark.parametrize(("contents", "expected"), [
(None, "unknown"), ("", "unknown"), ("ODS_MODE=\n", "unknown"),
@@ -11297,7 +11302,8 @@ class TestModelConfig:
handler = _FakeHandler(b"")
_mod.AgentHandler._handle_model_config(handler)
assert handler.response_code == 200
- assert handler.parse_response() == {"configuredMode": expected, "effectiveMode": "hybrid"}
+ assert handler.parse_response() == {"configuredMode": expected, "effectiveMode": "hybrid",
+ "configuredModel": _NO_CONFIGURED_MODEL}
assert ("Cache-Control", "no-store") in handler.response_headers
@pytest.mark.parametrize("failure", [PermissionError, UnicodeError])
@@ -11314,7 +11320,30 @@ class TestModelConfig:
monkeypatch.setattr(_mod, "load_env", denied)
handler = _FakeHandler(b"")
_mod.AgentHandler._handle_model_config(handler)
- assert handler.parse_response() == {"configuredMode": "unknown", "effectiveMode": "local"}
+ assert handler.parse_response() == {"configuredMode": "unknown", "effectiveMode": "local",
+ "configuredModel": None}
+
+ @pytest.mark.parametrize(("contents", "expected"), [
+ ("LLM_MODEL=qwen3.6-35b-a3b\nGGUF_FILE=Qwen3.6-35B-A3B-UD-Q4_K_M.gguf\nCTX_SIZE=131072\n",
+ {"llmModel": "qwen3.6-35b-a3b", "ggufFile": "Qwen3.6-35B-A3B-UD-Q4_K_M.gguf", "contextSize": 131072}),
+ # The legacy context key counts when the canonical one is not a positive count.
+ ("LLM_MODEL=qwen3:30b-a3b\nCTX_SIZE=auto\nMAX_CONTEXT=65536\n",
+ {"llmModel": "qwen3:30b-a3b", "ggufFile": None, "contextSize": 65536}),
+ # A value that does not validate is reported as None, never echoed.
+ ("LLM_MODEL=$(reboot)\nGGUF_FILE=../models/x.gguf\nCTX_SIZE=0\n", _NO_CONFIGURED_MODEL),
+ ])
+ def test_configured_model_identity_is_bounded(self, tmp_path, monkeypatch, contents, expected):
+ """The Dashboard API reads this when the owner's private .env is not
+ readable by its UID (Workstation06: owner nvuser, UID 1001)."""
+ monkeypatch.setattr(_mod, "INSTALL_DIR", tmp_path)
+ monkeypatch.setattr(_mod, "AGENT_API_KEY", "test-key")
+ monkeypatch.setattr(_mod, "STARTUP_ODS_MODE", "local")
+ (tmp_path / ".env").write_text(contents + "HF_TOKEN=private-fixture\n", encoding="utf-8")
+ handler = _FakeHandler(b"")
+ _mod.AgentHandler._handle_model_config(handler)
+ response = handler.parse_response()
+ assert response["configuredModel"] == expected
+ assert "private-fixture" not in json.dumps(response)
def test_authenticated_fixed_route_reads_atomic_replacement(self, tmp_path, monkeypatch):
import urllib.error
@@ -11347,7 +11376,8 @@ class TestModelConfig:
headers = {"Authorization": "Bearer model-config-secret"}
for mode in ("local", "cloud"):
with urllib.request.urlopen(urllib.request.Request(url, headers=headers), timeout=2) as response:
- assert json.load(response) == {"configuredMode": mode, "effectiveMode": "hybrid"}
+ assert json.load(response) == {"configuredMode": mode, "effectiveMode": "hybrid",
+ "configuredModel": _NO_CONFIGURED_MODEL}
assert response.headers["Cache-Control"] == "no-store"
if mode == "local":
replacement = tmp_path / ".env-new"
diff --git a/ods/extensions/services/dashboard-api/tests/test_models.py b/ods/extensions/services/dashboard-api/tests/test_models.py
index 3fb357101..c8124cd01 100644
--- a/ods/extensions/services/dashboard-api/tests/test_models.py
+++ b/ods/extensions/services/dashboard-api/tests/test_models.py
@@ -37,6 +37,32 @@ def test_active_model_reader_preserves_unmatched_quote(monkeypatch, tmp_path):
assert models_router._read_active_model() == "model-v2.gguf'"
[email protected](("owner", "expected"), [
+ ({"llmModel": "qwen3.6-35b-a3b", "ggufFile": "Qwen3.6-35B-A3B-UD-Q4_K_M.gguf", "contextSize": 131072},
+ "Qwen3.6-35B-A3B-UD-Q4_K_M.gguf"),
+ (None, None),
+])
+def test_active_model_reader_asks_the_owner_agent_for_a_private_env(monkeypatch, tmp_path, owner, expected):
+ """An install owner other than UID 1000 keeps .env from this API's UID."""
+ from pathlib import Path
+ import routers.models as models_router
+
+ env_path = tmp_path / ".env"
+ env_path.write_text("GGUF_FILE=stale.gguf\n", encoding="utf-8")
+ monkeypatch.setattr(models_router, "_ENV_PATH", env_path)
+ original = Path.read_text
+
+ def read_text(path, *args, **kwargs):
+ if path == env_path:
+ raise PermissionError(13, "Permission denied", str(path))
+ return original(path, *args, **kwargs)
+
+ monkeypatch.setattr(Path, "read_text", read_text)
+ monkeypatch.setattr(models_router, "owner_model_config", lambda: owner)
+
+ assert models_router._read_active_model() == expected
+
+
def test_huggingface_artifacts_group_complete_shards_and_require_integrity():
import routers.models as models_router
diff --git a/ods/tests/test_dashboard_data_permissions.py b/ods/tests/test_dashboard_data_permissions.py
index 13f050e78..ba38cf9f3 100644
--- a/ods/tests/test_dashboard_data_permissions.py
+++ b/ods/tests/test_dashboard_data_permissions.py
@@ -201,6 +201,7 @@ ods_prepare_dashboard_data "$INSTALL_DIR" false
_load_permission_fixture_source(ROOT / "bin/ods-host-agent.py", namespace, {
"load_env", "parse_env_text", "_normalize_ods_mode", "_ODS_MODES",
"_LEGACY_ODS_MODE_ALIASES", "check_auth", "json_response",
+ "_configured_model_identity", "_valid_pixel_model_name", "_valid_gguf_filename",
}, handler_methods={"do_GET", "log_message", "_handle_model_config"})
context = multiprocessing.get_context("fork")
port_receiver, port_sender = context.Pipe(duplex=False)
@@ -249,7 +250,7 @@ ods_prepare_dashboard_data "$INSTALL_DIR" false
raw = response.read()
assert b"private-fixture-secret" not in raw and b"OPENAI_API_KEY" not in raw
snapshot = json.loads(raw)
- assert set(snapshot) == {"configuredMode", "effectiveMode"}
+ assert set(snapshot) == {"configuredMode", "effectiveMode", "configuredModel"}
snapshots.append(snapshot)
return snapshot
@@ -266,8 +267,9 @@ ods_prepare_dashboard_data "$INSTALL_DIR" false
result = result_receiver.recv()
client.join(5)
self.assertEqual(client.exitcode, 0)
- self.assertEqual(result, {"mode": mode, "denied": True,
- "snapshots": [{"configuredMode": mode, "effectiveMode": "local"}]})
+ no_model = {"llmModel": None, "ggufFile": None, "contextSize": None}
+ self.assertEqual(result, {"mode": mode, "denied": True, "snapshots": [
+ {"configuredMode": mode, "effectiveMode": "local", "configuredModel": no_model}]})
finally:
if client.is_alive():
client.terminate()