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: recount tokens when status sync adopts a resident GGUF (#10467)
Chaitanya Laxmanb921a2cba2ac
diff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.tsindex 70da2860376..12fd7930ecc 100644--- a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts+++ b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts@@ -758,12 +758,10 @@ async function syncInferenceStatusToStore(options?: {// status so attach gates survive a refresh.syncModelCapabilities(checkpointId, statusRes);- // Against an already-resident model, history can load before this first status- // has a checkpoint, so its own recount never runs. The thread guard stops a null- // thread publishing an empty count.+ // History can load before this status sets a window, so its own recount never runs, even+ // with a checkpoint already selected (an API load). Null thread guard: no empty count.const hydrated = useChatRuntimeStore.getState();if (- !selectedCheckpoint &&hydrated.contextUsage == null &&hydrated.activeThreadId != null &&hydrated.loadedContextLength != null &&diff --git a/tests/studio/test_new_chat_context_recount.py b/tests/studio/test_new_chat_context_recount.pyindex faae947a495..cb80ba5d3ce 100644--- a/tests/studio/test_new_chat_context_recount.py+++ b/tests/studio/test_new_chat_context_recount.py@@ -135,6 +135,15 @@ def _store_reducers() -> str:)+def _status_poll_adoption_tail() -> str:+ """The status sync's setCheckpoint-plus-recount tail, verbatim (API / CLI loads hydrate here)."""+ return slice_between(+ read(RUNTIME),+ " setCheckpoint(checkpointId, statusRes.gguf_variant);",+ " }\n } else if (\n !chatActiveModel &&",+ )++def _resident_fast_path() -> str:"""The adoption tail of loadModel's already-resident branch, verbatim.@@ -557,6 +566,27 @@ __FAST_PATH__"""+HARNESS_STATUS_POLL = """++export async function adoptServerStatus(statusRes: any): Promise<void> {+ const selectedCheckpoint: string = state.params?.checkpoint ?? "";+ const checkpointId: string | null =+ statusRes.model_identifier ?? statusRes.active_model ?? null;+ const previousGgufVariant: string | null = state.activeGgufVariant ?? null;+ const { setCheckpoint } = useChatRuntimeStore.getState();+ const applyActiveModelStatusToStore = (status: any, _options: any): void => {+ set({+ loadedContextLength: status.is_gguf ? (status.context_length ?? null) : null,+ });+ };+ const syncModelCapabilities = (_id: string, _status: any): void => {};+ if (checkpointId) {+__STATUS_POLL_TAIL__+ }+}+"""++def _rendered_effects(effects: list[tuple[list[str], str]]) -> str:blocks = []for deps, body in effects:@@ -594,8 +624,17 @@ def _harness_source() -> str:"__RECOUNT_EFFECTS__", _rendered_effects(_thread_recount_effects()))resident = HARNESS_RESIDENT.replace("__FAST_PATH__", _resident_fast_path())+ status_poll = HARNESS_STATUS_POLL.replace("__STATUS_POLL_TAIL__", _status_poll_adoption_tail())history = HARNESS_HISTORY.replace("__RESTORE__", _history_usage_restore())- return prelude + _message_order_body() + _refresh_module_body() + render + resident + history+ return (+ prelude+ + _message_order_body()+ + _refresh_module_body()+ + render+ + resident+ + status_poll+ + history+ )def _run(script: str) -> dict:@@ -1738,6 +1777,50 @@ def test_adopting_the_resident_gguf_reprices_the_open_thread():assert (out["cached"] or {}).get("totalTokens") == 62+def test_status_poll_adoption_reprices_when_a_local_checkpoint_is_already_selected():+ """#10337: an API-loaded GGUF already selected in Studio left the bar blank until the next reply."""+ out = _run(+ textwrap.dedent(+ """+ // @ts-nocheck+ import { adoptServerStatus, seed, snapshot, world } from "./harness.ts";+ world.storedMessages["thread-a"] = [+ { id: "m1", role: "user", createdAt: 1, content: [{ type: "text", text: "hi" }], metadata: {} },+ { id: "m2", role: "assistant", createdAt: 2, content: [{ type: "text", text: "yo" }], metadata: {} },+ ];+ seed({+ params: { checkpoint: "unsloth/gguf-model", systemPrompt: "", systemVariables: "" },+ loadedContextLength: 8192,+ activeThreadId: "thread-a",+ contextUsage: null,+ contextUsageByThreadId: {},+ });++ await adoptServerStatus({+ active_model: "unsloth/gguf-model",+ gguf_variant: null,+ is_gguf: true,+ context_length: 8192,+ });+ await new Promise((resolve) => setTimeout(resolve, 30));++ const after = snapshot();+ console.log(JSON.stringify({+ counts: world.countedMessages.length,+ contextUsage: after.contextUsage,+ cached: after.contextUsageByThreadId["thread-a"] ?? null,+ }));+ """+ )+ )+ assert out["counts"] == 1+ assert (out["contextUsage"] or {}).get("totalTokens") == 62, (+ "adopting a resident GGUF through the status poll must reprice the open "+ "thread even when Studio already had that checkpoint selected"+ )+ assert (out["cached"] or {}).get("totalTokens") == 62++# Revisiting a thread that was NOT open when the model changed: setCheckpoint emptied# contextUsageByThreadId, and the thread is already mounted so its history loader never reruns.REVISIT_AFTER_A_MODEL_SWITCH = """