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
fix(studio): honor llama.cpp update dismissal and snooze (#12934)
Wasim Yousef Saidb155de531427
diff --git a/studio/frontend/src/features/settings/tabs/general-tab.tsx b/studio/frontend/src/features/settings/tabs/general-tab.tsxindex a9c20927aa5..bb928737bde 100644--- a/studio/frontend/src/features/settings/tabs/general-tab.tsx+++ b/studio/frontend/src/features/settings/tabs/general-tab.tsx@@ -163,6 +163,7 @@ const PREFS_KEYS: string[] = [// Update notifications"unsloth_show_llama_update_banner","unsloth_show_whisper_update_banner",+ "unsloth_llama_update_offer_suppression","unsloth_monitor_overlay",LOADED_MODELS_PREFERENCE_KEYS.show,LOADED_MODELS_PREFERENCE_KEYS.collapsed,diff --git a/studio/frontend/src/hooks/use-llama-update-check.ts b/studio/frontend/src/hooks/use-llama-update-check.tsindex 8ebe06c52f8..559c828bb6c 100644--- a/studio/frontend/src/hooks/use-llama-update-check.ts+++ b/studio/frontend/src/hooks/use-llama-update-check.ts@@ -169,6 +169,100 @@ function parseStatus(value: unknown): LlamaUpdateStatus | null {// resynced -- would otherwise replay the same completed job forever. Persist the handled marker// outside React state so it survives both, and is shared across tabs in this browser.const HANDLED_RELOAD_STORAGE_KEY = "unsloth_llama_update_reload_handled_at";+const OFFER_SUPPRESSION_STORAGE_KEY = "unsloth_llama_update_offer_suppression";+const OFFER_SUPPRESSION_EVENT = "unsloth:llama-update-offer-suppression";++type OfferSuppression =+ | { kind: "dismissed"; offerKey: string }+ | { kind: "snoozed"; offerKey: string; until: number };++let retainedSuppression: {+ value: OfferSuppression | null;+ persisted: boolean;+} = { value: null, persisted: true };++function offerKey(status: LlamaUpdateStatus): string {+ return JSON.stringify({+ llama: status.llama.update_available+ ? [status.llama.installed_tag, status.llama.latest_tag]+ : null,+ whisper: status.whisper?.update_available+ ? [status.whisper.installed_tag, status.whisper.latest_tag]+ : null,+ migration: status.backend_migration_available+ ? [+ status.llama.installed_tag,+ status.llama.latest_tag,+ status.from_backend,+ status.to_backend,+ ]+ : null,+ });+}++function parseOfferSuppression(raw: string | null): OfferSuppression | null {+ if (!raw) return null;+ try {+ const value: unknown = JSON.parse(raw);+ if (!value || typeof value !== "object") return null;+ const record = value as Record<string, unknown>;+ if (record.version !== 1 || typeof record.offerKey !== "string") {+ return null;+ }+ if (record.kind === "dismissed") {+ return { kind: "dismissed", offerKey: record.offerKey };+ }+ if (+ record.kind === "snoozed" &&+ typeof record.until === "number" &&+ Number.isFinite(record.until)+ ) {+ return {+ kind: "snoozed",+ offerKey: record.offerKey,+ until: record.until,+ };+ }+ } catch {+ return null;+ }+ return null;+}++function getOfferSuppression(): OfferSuppression | null {+ if (!retainedSuppression.persisted) return retainedSuppression.value;+ try {+ const value = parseOfferSuppression(+ localStorage.getItem(OFFER_SUPPRESSION_STORAGE_KEY),+ );+ retainedSuppression = { value, persisted: true };+ return value;+ } catch {+ return retainedSuppression.value;+ }+}++function publishOfferSuppression(suppression: OfferSuppression | null): void {+ retainedSuppression = { value: suppression, persisted: false };+ try {+ if (suppression) {+ localStorage.setItem(+ OFFER_SUPPRESSION_STORAGE_KEY,+ JSON.stringify({ version: 1, ...suppression }),+ );+ } else {+ localStorage.removeItem(OFFER_SUPPRESSION_STORAGE_KEY);+ }+ retainedSuppression.persisted = true;+ } catch {+ // Storage can be unavailable in restricted browser contexts.+ }+ window.dispatchEvent(+ new CustomEvent<OfferSuppression | null>(OFFER_SUPPRESSION_EVENT, {+ detail: suppression,+ }),+ );+}function getHandledReloadAt(): string | null {try {@@ -202,9 +296,6 @@ async function fetchStatus(}}-// Manual checks bypass the 24h release cache; job polls read local state.-const recheckStatus = () => fetchStatus(true);-interface UseLlamaUpdateCheckOptions {enabled?: boolean;/**@@ -237,6 +328,80 @@ export function useLlamaUpdateCheck({const [applying, setApplying] = useState(false);const pollTimer = useRef<ReturnType<typeof setInterval> | null>(null);const snoozeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);+ const suppressionRef = useRef<OfferSuppression | null>(getOfferSuppression());+ const statusRef = useRef<LlamaUpdateStatus | null>(null);+ const activeRef = useRef(enabled);+ const surfaceRef = useRef<(next: LlamaUpdateStatus | null) => void>(() => {});+ const statusReadRef = useRef({ issued: 0, accepted: 0 });++ const readStatus = useCallback(async (forceRefresh = false) => {+ const sequence = ++statusReadRef.current.issued;+ const suppressionAtRequest = suppressionRef.current;+ const next = await fetchStatus(forceRefresh);+ if (!next || sequence < statusReadRef.current.accepted) return null;+ if (+ next.job.state === "running" &&+ next.job.operation !== "switch" &&+ suppressionRef.current !== null &&+ suppressionRef.current !== suppressionAtRequest+ ) {+ return null;+ }+ statusReadRef.current.accepted = sequence;+ return next;+ }, []);++ const armSnoozeTimer = useCallback(() => {+ if (snoozeTimer.current) clearTimeout(snoozeTimer.current);+ snoozeTimer.current = null;+ const suppression = suppressionRef.current;+ if (!activeRef.current || suppression?.kind !== "snoozed") return;+ const remaining = suppression.until - Date.now();+ if (remaining <= 0) return;+ snoozeTimer.current = setTimeout(() => {+ snoozeTimer.current = null;+ readStatus(true).then((next) => {+ if (activeRef.current) surfaceRef.current(next);+ });+ }, remaining);+ }, [readStatus]);++ const clearSuppression = useCallback(() => {+ if (!suppressionRef.current) return;+ suppressionRef.current = null;+ publishOfferSuppression(null);+ armSnoozeTimer();+ }, [armSnoozeTimer]);++ const presentStatus = useCallback(+ (next: LlamaUpdateStatus) => {+ const presentation = llamaUpdatePresentation(+ llamaUpdateOffered(next),+ next.job,+ );+ const suppression = suppressionRef.current;+ const suppressed =+ suppression?.offerKey === offerKey(next) &&+ (suppression.kind === "dismissed" || suppression.until > Date.now());+ setApplying(presentation.applying);+ setVisible(presentation.visible && (presentation.running || !suppressed));+ armSnoozeTimer();+ return presentation;+ },+ [armSnoozeTimer],+ );++ const commitStatus = useCallback(+ (next: LlamaUpdateStatus) => {+ statusRef.current = next;+ setStatus(next);+ const presentation = presentStatus(next);+ if (presentation.applying) clearSuppression();+ return presentation;+ },+ [presentStatus, clearSuppression],+ );+// Read through a ref so startJobPoll stays stable (apply/surfaceIfAvailable// depend on it) while still calling the latest callback.const onReloadRequiredRef = useRef(onReloadRequired);@@ -284,14 +449,11 @@ export function useLlamaUpdateCheck({(onDone?: (result: LlamaApplyResult) => void) => {clearPollTimer();const timer = setInterval(async () => {- const s = await fetchStatus();+ const s = await readStatus();// Polls overlap: a "running" answer landing after a later poll saw the job// finish would re-set applying with no timer left to clear it.if (!s || pollTimer.current !== timer) return;- setStatus(s);- const presentation = llamaUpdatePresentation(llamaUpdateOffered(s), s.job);- setApplying(presentation.applying);- setVisible(presentation.visible);+ const presentation = commitStatus(s);if (presentation.running) return;clearPollTimer();if (s.job.state === "success") {@@ -318,19 +480,13 @@ export function useLlamaUpdateCheck({}, JOB_POLL_INTERVAL_MS);pollTimer.current = timer;},- [clearPollTimer, notifyReloadIfNeeded],+ [clearPollTimer, readStatus, commitStatus, notifyReloadIfNeeded],);const surfaceIfAvailable = useCallback((next: LlamaUpdateStatus | null) => {if (!next) return;- setStatus(next);- const presentation = llamaUpdatePresentation(- llamaUpdateOffered(next),- next.job,- );- setApplying(presentation.applying);- setVisible(presentation.visible);+ const presentation = commitStatus(next);if (presentation.running) {if (!pollTimer.current) startJobPoll();return;@@ -340,30 +496,37 @@ export function useLlamaUpdateCheck({// just-finished moments) still needs to resync here, not just from the poll path above.notifyReloadIfNeeded(next.job);},- [startJobPoll, notifyReloadIfNeeded],+ [commitStatus, startJobPoll, notifyReloadIfNeeded],);+ useEffect(() => {+ surfaceRef.current = surfaceIfAvailable;+ }, [surfaceIfAvailable]);useEffect(() => {+ activeRef.current = enabled;if (!enabled) {// Re-enabling will rediscover any still-running job.return;}let canceled = false;+ if (statusRef.current) presentStatus(statusRef.current);+ else armSnoozeTimer();const firstTimer = setTimeout(() => {- recheckStatus().then((s) => {+ readStatus(true).then((s) => {if (!canceled) surfaceIfAvailable(s);});}, FIRST_CHECK_DELAY_MS);const reminder = setInterval(() => {- recheckStatus().then((s) => {+ readStatus(true).then((s) => {if (!canceled) surfaceIfAvailable(s);});}, REMINDER_INTERVAL_MS);return () => {canceled = true;+ activeRef.current = false;clearTimeout(firstTimer);clearInterval(reminder);clearPollTimer();@@ -372,49 +535,89 @@ export function useLlamaUpdateCheck({snoozeTimer.current = null;}};- }, [enabled, surfaceIfAvailable, clearPollTimer]);+ }, [+ enabled,+ readStatus,+ surfaceIfAvailable,+ clearPollTimer,+ armSnoozeTimer,+ presentStatus,+ ]);// Cross-tab nudge: a tab that only checks hourly would otherwise stay pointed at a// server-unloaded model for up to an hour after a DIFFERENT open tab applies an update. The// storage event only fires in other tabs (never the one that wrote it), so this recheck fires// promptly there without this tab redundantly re-triggering itself.useEffect(() => {- if (!enabled) return;+ const acceptSuppression = (suppression: OfferSuppression | null) => {+ if (suppressionRef.current === suppression) return;+ suppressionRef.current = suppression;+ if (statusRef.current) presentStatus(statusRef.current);+ else armSnoozeTimer();+ };+ const onSuppression = (event: Event) => {+ acceptSuppression((event as CustomEvent<OfferSuppression | null>).detail);+ };const onStorage = (event: StorageEvent) => {+ if (event.key === OFFER_SUPPRESSION_STORAGE_KEY) {+ const value = parseOfferSuppression(event.newValue);+ retainedSuppression = { value, persisted: true };+ acceptSuppression(value);+ return;+ }if (+ enabled &&event.key === HANDLED_RELOAD_STORAGE_KEY &&event.newValue &&event.newValue !== reloadNotifiedForRef.current) {- recheckStatus().then(surfaceIfAvailable);+ readStatus(true).then(surfaceIfAvailable);}};+ window.addEventListener(OFFER_SUPPRESSION_EVENT, onSuppression);window.addEventListener("storage", onStorage);- return () => window.removeEventListener("storage", onStorage);- }, [enabled, surfaceIfAvailable]);+ acceptSuppression(getOfferSuppression());+ return () => {+ window.removeEventListener(OFFER_SUPPRESSION_EVENT, onSuppression);+ window.removeEventListener("storage", onStorage);+ };+ }, [enabled, readStatus, surfaceIfAvailable, presentStatus, armSnoozeTimer]);useEffect(() => {if (!enabled) return;return subscribeToLlamaJobStarted(() => {- fetchStatus().then(surfaceIfAvailable);+ readStatus().then(surfaceIfAvailable);});- }, [enabled, surfaceIfAvailable]);+ }, [enabled, readStatus, surfaceIfAvailable]);const dismiss = useCallback(() => {- setVisible(false);- }, []);+ const current = statusRef.current;+ if (!current) return;+ const suppression: OfferSuppression = {+ kind: "dismissed",+ offerKey: offerKey(current),+ };+ suppressionRef.current = suppression;+ publishOfferSuppression(suppression);+ presentStatus(current);+ }, [presentStatus]);const snooze = useCallback(() => {- setVisible(false);- if (snoozeTimer.current) clearTimeout(snoozeTimer.current);- snoozeTimer.current = setTimeout(() => {- snoozeTimer.current = null;- recheckStatus().then(surfaceIfAvailable);- }, SNOOZE_DELAY_MS);- }, [surfaceIfAvailable]);+ const current = statusRef.current;+ if (!current) return;+ const suppression: OfferSuppression = {+ kind: "snoozed",+ offerKey: offerKey(current),+ until: Date.now() + SNOOZE_DELAY_MS,+ };+ suppressionRef.current = suppression;+ publishOfferSuppression(suppression);+ presentStatus(current);+ }, [presentStatus]);const apply = useCallback(async (): Promise<LlamaApplyResult> => {if (applying) return { ok: false, error: "already running" };+ const suppressionAtRequest = suppressionRef.current;setApplying(true);setVisible(true);let action: {@@ -465,10 +668,18 @@ export function useLlamaUpdateCheck({};}+ if (+ actionJob.operation !== "switch" &&+ (action?.started === true || actionJob.state === "running") &&+ (suppressionRef.current === null ||+ suppressionRef.current === suppressionAtRequest)+ ) {+ clearSuppression();+ }return await new Promise<LlamaApplyResult>((resolve) =>startJobPoll(resolve),);- }, [applying, startJobPoll, notifyReloadIfNeeded]);+ }, [applying, startJobPoll, notifyReloadIfNeeded, clearSuppression]);return {status: enabled ? status : null,