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: use the browser's timezone for today's date in chat (#11852)
Nilay6a169935db65
diff --git a/studio/backend/core/inference/chat_generation_runs.py b/studio/backend/core/inference/chat_generation_runs.pyindex 81b0bfe0d53..5d6bdae9b29 100644--- a/studio/backend/core/inference/chat_generation_runs.py+++ b/studio/backend/core/inference/chat_generation_runs.py@@ -66,7 +66,12 @@ class _SSEDecoder:return values-def _background_request(app: Any, run_id: str, cancel_event: threading.Event) -> Request:+def _background_request(+ app: Any,+ run_id: str,+ cancel_event: threading.Event,+ timezone_headers: dict[str, str] | None = None,+) -> Request:scope = {"type": "http","asgi": {"version": "3.0", "spec_version": "2.3"},@@ -80,6 +85,10 @@ def _background_request(app: Any, run_id: str, cancel_event: threading.Event) ->(b"x-unsloth-generation-run", run_id.encode("ascii", "ignore")),# Durable runs replay their event log to the UI, which needs the Unsloth control frames (see routes.inference).(b"x-unsloth-events", b"1"),+ *(+ (name.encode("latin-1"), value.encode("latin-1"))+ for name, value in (timezone_headers or {}).items()+ ),],"client": ("127.0.0.1", 0),"server": ("127.0.0.1", 0),@@ -739,13 +748,15 @@ class ChatGenerationSupervisor:from routes.inference import produce_openai_chat_completions- payload = ChatCompletionRequest.model_validate(run["requestPayload"])+ request_payload = dict(run["requestPayload"])+ timezone_headers = request_payload.pop(db.TIMEZONE_HEADERS_FIELD, None)+ payload = ChatCompletionRequest.model_validate(request_payload)# Switching, idle reload and auto-download all happen in the call below, and llama.cpp's first-token# budget only starts after it. One touch afterwards cannot cover a preparation longer than the lease# itself.response = await produce_openai_chat_completions(payload,- _background_request(self.app, run_id, cancel_event),+ _background_request(self.app, run_id, cancel_event, timezone_headers),owner,cancel_on_disconnect = False,)diff --git a/studio/backend/routes/chat_generation_runs.py b/studio/backend/routes/chat_generation_runs.pyindex d2bdd9a0661..775f74a50b4 100644--- a/studio/backend/routes/chat_generation_runs.py+++ b/studio/backend/routes/chat_generation_runs.py@@ -27,6 +27,10 @@ from core.inference.llama_keepwarm import inference_lifecycle_gatefrom models.inference import ChatCompletionRequestfrom storage import chat_generation_runs_db as dbfrom utils.api_errors import safe_validation_errors+from utils.current_date_prompt_settings import (+ CURRENT_DATE_TIMEZONE_HEADER,+ CURRENT_DATE_TIMEZONE_OFFSET_HEADER,+)router = APIRouter()_EVENT_WAIT_EXECUTOR = ThreadPoolExecutor(@@ -243,6 +247,14 @@ def _sanitize_request(payload: CreateChatGenerationRun) -> dict[str, Any]:return sanitized+def _timezone_headers(request: Request) -> dict[str, str]:+ return {+ name: value+ for name in (CURRENT_DATE_TIMEZONE_HEADER, CURRENT_DATE_TIMEZONE_OFFSET_HEADER)+ if 0 < len(value := request.headers.get(name, "").strip()) <= 64+ }++def _require_run(run_id: str) -> dict[str, Any]:run = db.get_run(run_id)if run is None:@@ -299,6 +311,8 @@ async def create_chat_generation_run(current_subject: str = Depends(get_current_subject),):sanitized = _sanitize_request(payload)+ if timezone_headers := _timezone_headers(request):+ sanitized[db.TIMEZONE_HEADERS_FIELD] = timezone_headers# Serialize the off-loop commit with model lifecycle work, so a run is registered either before the gate opens or# after an unload/swap, never mid-swap.async with inference_lifecycle_gate():diff --git a/studio/backend/storage/chat_generation_runs_db.py b/studio/backend/storage/chat_generation_runs_db.pyindex 98868b7058b..818cfc7d398 100644--- a/studio/backend/storage/chat_generation_runs_db.py+++ b/studio/backend/storage/chat_generation_runs_db.py@@ -341,6 +341,11 @@ def _loads(value: str | None, fallback: Any) -> Any:return fallback+# Kept with the run for the producer but outside its identity, so a retried create from a browser whose offset moved+# (DST) still matches the committed run.+TIMEZONE_HEADERS_FIELD = "timezone_headers"++def canonical_request(*,thread_id: str,@@ -359,7 +364,11 @@ def canonical_request("threadId": thread_id,"userMessageId": user_message_id,"assistantMessageId": assistant_message_id,- "requestPayload": request_payload,+ "requestPayload": {+ key: value+ for key, value in request_payload.items()+ if key != TIMEZONE_HEADERS_FIELD+ },},sort_keys = True,separators = (",", ":"),diff --git a/studio/backend/tests/test_account_deactivated_account_fences.py b/studio/backend/tests/test_account_deactivated_account_fences.pyindex f79d421583a..a719360ab6e 100644--- a/studio/backend/tests/test_account_deactivated_account_fences.py+++ b/studio/backend/tests/test_account_deactivated_account_fences.py@@ -144,7 +144,8 @@ async def test_owner_run_cannot_take_a_deactivated_accounts_supervisor_slot(start = lambda run_id, **identity: started.append(run_id),)request = SimpleNamespace(- app = SimpleNamespace(state = SimpleNamespace(chat_generation_supervisor = supervisor))+ app = SimpleNamespace(state = SimpleNamespace(chat_generation_supervisor = supervisor)),+ headers = {},)committed: list = []diff --git a/studio/backend/tests/test_chat_generation_supervisor.py b/studio/backend/tests/test_chat_generation_supervisor.pyindex a01d2afb88b..c81daac2f7e 100644--- a/studio/backend/tests/test_chat_generation_supervisor.py+++ b/studio/backend/tests/test_chat_generation_supervisor.py@@ -5,10 +5,12 @@ import asyncioimport jsonimport threadingimport time+from datetime import date, datetime, timezonefrom types import SimpleNamespacefrom unittest.mock import AsyncMockimport pytest+from starlette.requests import Requestfrom core.inference import llama_keepwarmfrom core.inference.chat_generation_runs import (@@ -22,6 +24,7 @@ from routes import inferencefrom state import active_generationsfrom storage import chat_generation_runs_db as runs_dbfrom storage import studio_db+from utils.current_date_prompt_settings import _request_local_date@pytest.fixture@@ -72,7 +75,8 @@ def _create_payload(content = "Hello"):def _route_request(supervisor):return SimpleNamespace(- app = SimpleNamespace(state = SimpleNamespace(chat_generation_supervisor = supervisor))+ app = SimpleNamespace(state = SimpleNamespace(chat_generation_supervisor = supervisor)),+ headers = {},)@@ -197,6 +201,67 @@ async def test_background_producer_persists_chunks_and_completes(durable_run, mo] == chunks+async def test_producer_dates_the_prompt_in_the_browser_timezone(monkeypatch):+ studio_db.upsert_chat_thread(+ {"id": "thread-1", "title": "Chat", "modelType": "base", "modelId": "local", "createdAt": 1}+ )+ studio_db.upsert_chat_message(+ {"id": "user-1", "threadId": "thread-1", "role": "user", "content": [], "createdAt": 2}+ )+ browser = Request(+ {+ "type": "http",+ "method": "POST",+ "path": "/api/inference/chat-runs",+ "query_string": b"",+ "headers": [+ (b"x-unsloth-timezone", b"Pacific/Kiritimati"),+ (b"x-unsloth-timezone-offset-minutes", b"-840"),+ ],+ "app": SimpleNamespace(state = SimpleNamespace()),+ }+ )+ await run_routes.create_chat_generation_run(_create_payload(), browser, "alice")+ instant = datetime(2026, 9, 24, 10, 5, tzinfo = timezone.utc)+ observed = []++ async def body():+ yield "data: [DONE]\n\n"++ async def fake(payload, request, _subject, *, cancel_on_disconnect):+ observed.append((sorted(payload.model_extra), _request_local_date(request, instant)))+ return SimpleNamespace(status_code = 200, body_iterator = body())++ monkeypatch.setattr(inference, "produce_openai_chat_completions", fake)+ supervisor = ChatGenerationSupervisor(SimpleNamespace(state = SimpleNamespace()))+ await supervisor._produce("run-1")+ assert observed == [(["generation_run_id"], date(2026, 9, 25))]+++async def test_a_create_retried_across_a_dst_change_returns_the_committed_run():+ studio_db.upsert_chat_thread(+ {"id": "thread-1", "title": "Chat", "modelType": "base", "modelId": "local", "createdAt": 1}+ )+ studio_db.upsert_chat_message(+ {"id": "user-1", "threadId": "thread-1", "role": "user", "content": [], "createdAt": 2}+ )++ def browser(offset):+ request = _route_request(None)+ request.headers = {+ "x-unsloth-timezone": "America/Los_Angeles",+ "x-unsloth-timezone-offset-minutes": offset,+ }+ return request++ first = await run_routes.create_chat_generation_run(_create_payload(), browser("420"), "alice")+ retry = await run_routes.create_chat_generation_run(_create_payload(), browser("480"), "alice")+ assert (first["created"], retry["created"]) == (True, False)+ assert retry["requestPayload"]["timezone_headers"]["x-unsloth-timezone-offset-minutes"] == "420"++@pytest.mark.asyncioasync def test_a_prefill_reporting_only_progress_renews_the_lease(durable_run, monkeypatch):"""A 250K prefill outruns the 1200s lease before its first token, and the