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: answer 422 to a timestamp or page cursor sqlite cannot store (#15389)
Vineeth Sai Varikuntla11f631059163
diff --git a/studio/backend/routes/chat_history.py b/studio/backend/routes/chat_history.pyindex f39797e5cb9..876a948cb6c 100644--- a/studio/backend/routes/chat_history.py+++ b/studio/backend/routes/chat_history.py@@ -109,6 +109,8 @@ def _reject_boolean(value: Any) -> Any:NotABoolean = Annotated[Optional[int], BeforeValidator(_reject_boolean)]+# sqlite INTEGER is signed 64-bit: a wider value raises OverflowError (a 500) where it is bound.+SqliteInt = Annotated[int, Field(ge = -(2**63), le = 2**63 - 1)]# llama.cpp spends 0xFFFFFFFF on its "draw one" sentinel, so a pin stops one below it.MAX_SAMPLING_SEED = 2**32 - 2@@ -185,8 +187,8 @@ class ChatThread(BaseModel):pairId: Optional[str] = NoneprojectId: Optional[str] = Nonearchived: bool = False- createdAt: int- updatedAt: Optional[int] = None+ createdAt: SqliteInt+ updatedAt: Optional[SqliteInt] = NoneopenaiCodeExecContainerId: Optional[str] = NoneanthropicCodeExecContainerId: Optional[str] = NoneforkedFromThreadId: Optional[str] = None@@ -286,8 +288,8 @@ class ChatThreadPatch(BaseModel):pairId: Optional[str] = NoneprojectId: Optional[str] = Nonearchived: Optional[bool] = None- createdAt: Optional[int] = None- updatedAt: Optional[int] = None+ createdAt: Optional[SqliteInt] = None+ updatedAt: Optional[SqliteInt] = NoneopenaiCodeExecContainerId: Optional[str] = NoneanthropicCodeExecContainerId: Optional[str] = None# Replaces the whole snapshot, except for anything the client could not read.@@ -307,7 +309,7 @@ class ChatMessage(BaseModel):content: Any = Field(default_factory = list)attachments: Optional[Any] = Nonemetadata: Optional[dict[str, Any]] = None- createdAt: int+ createdAt: SqliteIntclass ChatProject(BaseModel):@@ -319,8 +321,8 @@ class ChatProject(BaseModel):# Read only: a saved record cannot set the folder.workingFolder: Optional[str] = Nonearchived: bool = False- createdAt: int- updatedAt: int+ createdAt: SqliteInt+ updatedAt: SqliteIntlastActivityAt: Optional[int] = None@@ -347,8 +349,8 @@ class ChatProjectPatch(BaseModel):name: Optional[str] = Noneinstructions: Optional[str] = Nonearchived: Optional[bool] = None- createdAt: Optional[int] = None- updatedAt: Optional[int] = None+ createdAt: Optional[SqliteInt] = None+ updatedAt: Optional[SqliteInt] = Noneclass ChatThreadListResponse(BaseModel):@@ -1137,7 +1139,7 @@ async def _remove_sandboxes(thread_ids, delete_files: bool) -> "tuple[int, list[@router.get("/attachments")def list_attachments(limit: Annotated[int, Query(ge = 1, le = 100)] = 50,- offset: Annotated[int, Query(ge = 0)] = 0,+ offset: Annotated[int, Query(ge = 0, le = 2**63 - 1)] = 0,current_subject: str = Depends(get_current_subject),) -> dict:"""One bounded page of chat uploads for the settings Data tab."""@@ -1977,7 +1979,7 @@ class ChatForkRequest(BaseModel):# an omitted message selects the tip within the fork transaction.messageId: Optional[str] = NonenewThreadId: str- createdAt: int+ createdAt: SqliteIntclass ChatForkResponse(BaseModel):diff --git a/studio/backend/routes/prompts.py b/studio/backend/routes/prompts.pyindex aa0b759da0f..56377b92be0 100644--- a/studio/backend/routes/prompts.py+++ b/studio/backend/routes/prompts.py@@ -3,6 +3,8 @@"""Prompt storage API routes backed by studio.db."""+from typing import Annotated+from fastapi import APIRouter, Depends, HTTPExceptionfrom pydantic import BaseModel, Field@@ -20,21 +22,24 @@ from storage.studio_db import (router = APIRouter()+# sqlite INTEGER is signed 64-bit: a wider value raises OverflowError (a 500) where it is bound.+SqliteInt = Annotated[int, Field(ge = -(2**63), le = 2**63 - 1)]+class PromptEntry(BaseModel):id: str = Field(max_length = 128)name: str = Field(max_length = 500)text: str = Field(max_length = 100_000)- createdAt: int- updatedAt: int+ createdAt: SqliteInt+ updatedAt: SqliteIntclass PromptList(BaseModel):id: str = Field(max_length = 128)name: str = Field(max_length = 500)items: list[str] = Field(max_length = 10_000)- createdAt: int- updatedAt: int+ createdAt: SqliteInt+ updatedAt: SqliteIntclass BulkEntriesRequest(BaseModel):diff --git a/studio/backend/routes/scheduled_tasks.py b/studio/backend/routes/scheduled_tasks.pyindex a32a4510854..e6dba5fc6c6 100644--- a/studio/backend/routes/scheduled_tasks.py+++ b/studio/backend/routes/scheduled_tasks.py@@ -226,7 +226,7 @@ def create_scheduled_task(# Declared ahead of /{task_id} so "runs" is never read as a task id.@router.get("/runs", response_model = ScheduledTaskActivity)def scheduled_task_activity(- since: Optional[int] = Query(default = None, ge = 0),+ since: Optional[int] = Query(default = None, ge = 0, le = 2**63 - 1),current_subject: str = Depends(get_current_subject),):"""Runs finished since ``since`` (ms), for a client that notifies when results arrive."""diff --git a/studio/backend/tests/test_request_integer_bounds.py b/studio/backend/tests/test_request_integer_bounds.pynew file mode 100644index 00000000000..1ab988edd61--- /dev/null+++ b/studio/backend/tests/test_request_integer_bounds.py@@ -0,0 +1,97 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""A request integer sqlite cannot store is a refused request, not an OverflowError (a 500)."""++import pytest+from fastapi import FastAPI+from fastapi.testclient import TestClient++from auth.authentication import authenticated_via_api_key, get_current_subject+from routes import chat_history, prompts, scheduled_tasks++TOO_BIG = 2**63+TOO_SMALL = -(2**63) - 1+LARGEST = 2**63 - 1+++def client(tmp_path, monkeypatch):+ # A regressed project create makes its folder before it fails: keep that out of ~/Documents.+ monkeypatch.setenv("UNSLOTH_STUDIO_PROJECTS_HOME", str(tmp_path / "projects"))+ app = FastAPI()+ app.include_router(chat_history.router, prefix = "/api/chat")+ app.include_router(prompts.router, prefix = "/api/prompts")+ app.include_router(scheduled_tasks.router, prefix = "/api/scheduled-tasks")+ app.dependency_overrides[get_current_subject] = lambda: "owner"+ app.dependency_overrides[authenticated_via_api_key] = lambda: False+ # A handler that raises must show as a 500 here, not as an exception out of the client.+ client = TestClient(app, raise_server_exceptions = False)+ # A fork reads its source thread and tip message before it binds anything from the request.+ assert client.post("/api/chat/threads", json = _thread()).status_code == 200+ assert client.put("/api/chat/threads/t1/messages/m1", json = _message()).status_code == 200+ return client+++def _thread(**fields):+ return {"id": "t1", "modelType": "base", "createdAt": 1, **fields}+++def _message(**fields):+ return {"id": "m1", "threadId": "t1", "role": "user", "createdAt": 1, **fields}+++def _project(**fields):+ return {"id": "p1", "name": "p", "createdAt": 1, "updatedAt": 1, **fields}+++def _prompt(**fields):+ return {"id": "e1", "name": "n", "text": "t", "createdAt": 1, "updatedAt": 1, **fields}+++def _prompt_list(**fields):+ return {"id": "l1", "name": "n", "items": [], "createdAt": 1, "updatedAt": 1, **fields}+++CASES = [+ ("post", "/api/chat/threads", _thread, "createdAt"),+ ("post", "/api/chat/threads", _thread, "updatedAt"),+ ("patch", "/api/chat/threads/t1", lambda **f: f, "createdAt"),+ ("patch", "/api/chat/threads/t1", lambda **f: f, "updatedAt"),+ ("put", "/api/chat/threads/t1/messages/m1", _message, "createdAt"),+ ("post", "/api/chat/threads/t1/fork", lambda **f: {"newThreadId": "f1", **f}, "createdAt"),+ ("post", "/api/chat/projects", _project, "createdAt"),+ ("post", "/api/chat/projects", _project, "updatedAt"),+ ("patch", "/api/chat/projects/p1", lambda **f: f, "createdAt"),+ ("patch", "/api/chat/projects/p1", lambda **f: f, "updatedAt"),+ ("put", "/api/prompts/entries/e1", _prompt, "createdAt"),+ ("put", "/api/prompts/entries/e1", _prompt, "updatedAt"),+ ("put", "/api/prompts/lists/l1", _prompt_list, "createdAt"),+ ("put", "/api/prompts/lists/l1", _prompt_list, "updatedAt"),+]++[email protected]("value", [TOO_BIG, TOO_SMALL])[email protected]("method, path, body, field", CASES)+def test_a_timestamp_sqlite_cannot_hold_is_refused(client, method, path, body, field, value):+ response = getattr(client, method)(path, json = body(**{field: value}))++ assert response.status_code == 422, response.text+++ "path, param",+ [+ ("/api/chat/attachments", "offset"),+ ("/api/scheduled-tasks/runs", "since"),+ ],+)+def test_a_page_cursor_sqlite_cannot_hold_is_refused(client, path, param):+ assert client.get(path, params = {param: TOO_BIG}).status_code == 422+ assert client.get(path, params = {param: LARGEST}).status_code == 200+++def test_the_largest_storable_timestamp_is_still_saved(client):+ response = client.put("/api/prompts/entries/e1", json = _prompt(createdAt = LARGEST))++ assert response.status_code == 200, response.text