Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: ignore an SSLKEYLOGFILE the process cannot write instead of failing every HTTPS client (#12166)
Daniel Hanf9150d23173d
diff --git a/unsloth_cli/__init__.py b/unsloth_cli/__init__.pyindex e7526431509..e0498e44a8a 100644--- a/unsloth_cli/__init__.py+++ b/unsloth_cli/__init__.py@@ -62,6 +62,15 @@ _startup_guard = (_check_working_directory(_sys.argv[1:], _os.environ, _sys.platform) if _is_entry_point else None)+from unsloth_cli._ssl_keylog import (+ drop_unwritable_ssl_keylog_file as _drop_unwritable_ssl_keylog_file,+)++# After the move out of System32, so a relative path is judged where ssl will open it, and+# before any command module builds an HTTPS client; the Studio backend's workers inherit it.+if _is_entry_point:+ _drop_unwritable_ssl_keylog_file()+import typerfrom importlib.metadata import version as package_version, PackageNotFoundError@@ -99,6 +108,7 @@ def _prepare_entry_point():if _entry_point_prepared:return_reconfigure_entry_point_streams()+ _drop_unwritable_ssl_keylog_file()_expand_attached_np_short()# Set last, so a raise leaves the work retryable rather than silently skipped._entry_point_prepared = Truediff --git a/unsloth_cli/_ssl_keylog.py b/unsloth_cli/_ssl_keylog.pynew file mode 100644index 00000000000..68a1a363d0c--- /dev/null+++ b/unsloth_cli/_ssl_keylog.py@@ -0,0 +1,33 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import os+import sys+++def drop_unwritable_ssl_keylog_file():+ """Unset SSLKEYLOGFILE when this process cannot append to it.++ ssl.create_default_context opens that path for every context it builds, so an+ unwritable one makes every HTTPS client raise: httpx at construction, which+ kills the Studio backend on import, and requests on every call. Some security+ software sets it machine-wide to a path no user process can open.+ """+ path = os.environ.get("SSLKEYLOGFILE")+ if not path:+ return False+ try:+ with open(path, "a"):+ pass+ return False+ except OSError as exc:+ os.environ.pop("SSLKEYLOGFILE", None)+ try:+ print(+ f"Unsloth: ignoring SSLKEYLOGFILE={path!r}, which this process cannot "+ f"write ({type(exc).__name__}); TLS key logging is off.",+ file = sys.stderr,+ )+ except Exception:+ pass+ return Truediff --git a/unsloth_cli/tests/test_ssl_keylog.py b/unsloth_cli/tests/test_ssl_keylog.pynew file mode 100644index 00000000000..4df07125a3a--- /dev/null+++ b/unsloth_cli/tests/test_ssl_keylog.py@@ -0,0 +1,73 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""An SSLKEYLOGFILE the process cannot write must not take down every HTTPS client."""++from __future__ import annotations++import os+import ssl+import subprocess+import sys+from pathlib import Path++_REPO_ROOT = Path(__file__).resolve().parents[2]+if str(_REPO_ROOT) not in sys.path:+ sys.path.insert(0, str(_REPO_ROOT))++from unsloth_cli._ssl_keylog import drop_unwritable_ssl_keylog_file+++def test_an_unwritable_key_log_is_dropped_and_tls_works(tmp_path, monkeypatch):+ # A directory stands in for the unopenable path; open(..., "a") fails on it everywhere.+ monkeypatch.setenv("SSLKEYLOGFILE", str(tmp_path))+ try:+ ssl.create_default_context()+ broken = False+ except OSError:+ broken = True+ assert broken, "the stand-in path must break ssl the way the real one does"+ assert drop_unwritable_ssl_keylog_file() is True+ assert "SSLKEYLOGFILE" not in os.environ+ ssl.create_default_context()+++def test_a_writable_key_log_is_kept(tmp_path, monkeypatch):+ target = tmp_path / "keys.log"+ monkeypatch.setenv("SSLKEYLOGFILE", str(target))+ assert drop_unwritable_ssl_keylog_file() is False+ assert os.environ["SSLKEYLOGFILE"] == str(target)+++def test_unset_is_left_alone(monkeypatch):+ monkeypatch.delenv("SSLKEYLOGFILE", raising = False)+ assert drop_unwritable_ssl_keylog_file() is False+ assert "SSLKEYLOGFILE" not in os.environ+++def _run(code, env_path):+ env = dict(os.environ, SSLKEYLOGFILE = str(env_path), PYTHONPATH = str(_REPO_ROOT))+ return subprocess.run(+ [sys.executable, "-c", code], capture_output = True, text = True, env = env, timeout = 300+ )+++def test_the_entry_point_clears_it_before_any_client_is_built(tmp_path):+ # The Desktop app starts the backend exactly this way (argv[0] = "unsloth", then import).+ code = (+ "import sys, os, ssl; sys.argv[0] = 'unsloth'; import unsloth_cli; "+ "ssl.create_default_context(); import httpx; httpx.AsyncClient(); "+ "print('KEYLOG', os.environ.get('SSLKEYLOGFILE'))"+ )+ result = _run(code, tmp_path)+ assert result.returncode == 0, result.stderr+ assert "KEYLOG None" in result.stdout+ assert "ignoring SSLKEYLOGFILE" in result.stderr+++def test_a_plain_import_leaves_the_host_environment_alone(tmp_path):+ result = _run(+ "import os, unsloth_cli; print('KEYLOG', os.environ.get('SSLKEYLOGFILE'))", tmp_path+ )+ assert result.returncode == 0, result.stderr+ assert f"KEYLOG {tmp_path}" in result.stdout