Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(models): a download speed limit in Settings

purplefa2fb2d5daac
diff --git a/src-tauri/src/commands/download.rs b/src-tauri/src/commands/download.rs
index b0abe7a3..8fd12638 100644
--- a/src-tauri/src/commands/download.rs
+++ b/src-tauri/src/commands/download.rs
@@ -3,7 +3,8 @@ use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
-use std::time::Instant;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::time::{Duration, Instant};
use futures_util::StreamExt;
use sha2::{Digest, Sha256};
@@ -1003,6 +1004,46 @@ fn resumed_bytes(resume_offset: u64, status: u16) -> u64 {
if resume_offset > 0 && status == 206 { resume_offset } else { 0 }
}
+// ── Download speed limit (Discord, boromirofgeo 2026-09-23) ─────────────
+//
+// "is there a way to limit download speed that this app does whenever it
+// downloads anything?" Every model file LU fetches itself runs through
+// do_download, so the limit sits there, shared by all downloads at once:
+// two downloads under a 10 MB/s limit get 10 MB/s together, not 20. Ollama
+// pulls and package installs run in other programs and are not limited.
+
+/// Bytes per second, 0 for no limit. Set from Settings at boot and on change.
+static DOWNLOAD_LIMIT_BPS: AtomicU64 = AtomicU64::new(0);
+/// When the shared line is free again, across all running downloads.
+static DOWNLOAD_NEXT_SLOT: Mutex<Option<Instant>> = Mutex::new(None);
+
+/// How long the download that just received `bytes` waits before it reads
+/// on, so that everything together stays at `limit_bps`. A line that has been
+/// idle starts from now, so a pause never turns into a burst afterwards.
+fn throttle_wait(slot: &mut Option<Instant>, limit_bps: u64, bytes: u64, now: Instant) -> Duration {
+ if limit_bps == 0 {
+ *slot = None;
+ return Duration::ZERO;
+ }
+ let start = match *slot {
+ Some(t) if t > now => t,
+ _ => now,
+ };
+ let done = start + Duration::from_secs_f64(bytes as f64 / limit_bps as f64);
+ *slot = Some(done);
+ done.saturating_duration_since(now)
+}
+
+/// Settings, Model Storage: megabytes per second, 0 for no limit.
+#[tauri::command]
+pub fn set_download_limit(mb_per_sec: f64) -> Result<(), String> {
+ if !mb_per_sec.is_finite() || mb_per_sec < 0.0 {
+ return Err("The download limit has to be 0 or a positive number of MB/s.".to_string());
+ }
+ DOWNLOAD_LIMIT_BPS.store((mb_per_sec * 1_000_000.0).round() as u64, Ordering::Relaxed);
+ Ok(())
+}
+
/// True when the body stopped before Content-Length was reached. `total == 0`
/// means the server declared no length — there is nothing to check against.
fn ended_early(total: u64, downloaded: u64) -> bool {
@@ -1550,6 +1591,19 @@ async fn do_download(
if let Some(h) = hasher.as_mut() { h.update(&bytes); }
downloaded += bytes.len() as u64;
+ let wait = {
+ let mut slot = DOWNLOAD_NEXT_SLOT.lock().unwrap_or_else(|p| p.into_inner());
+ throttle_wait(&mut slot, DOWNLOAD_LIMIT_BPS.load(Ordering::Relaxed), bytes.len() as u64, Instant::now())
+ };
+ if !wait.is_zero() {
+ // Pause and Cancel still answer at once: the
+ // outer select sees the token on the next turn.
+ tokio::select! {
+ _ = token.cancelled() => {}
+ _ = tokio::time::sleep(wait) => {}
+ }
+ }
+
// Update progress every 500ms
if last_update.elapsed().as_millis() > 500 {
last_update = Instant::now();
@@ -2542,6 +2596,25 @@ pub async fn check_model_sizes(
#[cfg(test)]
mod tests {
+
+ #[test]
+ fn the_download_limit_is_shared_and_off_at_zero() {
+ let now = Instant::now();
+ let mut slot = None;
+ // 1 MB at 1 MB/s takes a second.
+ assert_eq!(throttle_wait(&mut slot, 1_000_000, 1_000_000, now), Duration::from_secs(1));
+ // A second download in the same instant queues behind the first.
+ assert_eq!(throttle_wait(&mut slot, 1_000_000, 500_000, now), Duration::from_millis(1500));
+ // After an idle stretch the line starts from now, without a burst.
+ let later = now + Duration::from_secs(10);
+ assert_eq!(throttle_wait(&mut slot, 1_000_000, 250_000, later), Duration::from_millis(250));
+ // 0 means no limit and clears the queue.
+ assert_eq!(throttle_wait(&mut slot, 0, 1_000_000, later), Duration::ZERO);
+ assert_eq!(slot, None);
+ assert!(set_download_limit(-1.0).is_err());
+ assert!(set_download_limit(f64::NAN).is_err());
+ }
+
use super::*;
/// Der Rueckfall, den dieser Test verhindert, ist im Zusammenschluss des
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 70ff90c1..f1a24699 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -562,6 +562,7 @@ fn main() {
commands::download::find_orphan_downloads,
commands::download::delete_orphan_download,
commands::download::resume_download,
+ commands::download::set_download_limit,
commands::download::detect_model_path,
commands::download::lmstudio_model_dir,
commands::download::check_model_sizes,
diff --git a/src/App.tsx b/src/App.tsx
index 3b63660c..f3993f7b 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -36,6 +36,10 @@ function App() {
const { useSettingsStore: store } = await import('./stores/settingsStore')
await syncCustomModelDir(store.getState().settings.hfDownloadPathOverride)
})()
+
+ // The download speed limit sits in Rust and starts at none on every
+ // launch (lib/download-limit.ts).
+ void import('./lib/download-limit').then(({ startDownloadLimitSync }) => startDownloadLimitSync())
}
// Probe local Whisper (STT) once at boot and push the result into the voice
diff --git a/src/components/settings/DownloadLimitSetting.tsx b/src/components/settings/DownloadLimitSetting.tsx
new file mode 100644
index 00000000..45bcbe50
--- /dev/null
+++ b/src/components/settings/DownloadLimitSetting.tsx
@@ -0,0 +1,44 @@
+// Discord, boromirofgeo 2026-09-23: "is there a way to limit download speed
+// that this app does whenever it downloads anything?" One number, under the
+// folder the downloads go to. App.tsx hands it to the downloader.
+import { useState } from 'react'
+import { useSettingsStore } from '../../stores/settingsStore'
+import { parseDownloadLimit } from '../../lib/download-limit'
+
+export function DownloadLimitSetting() {
+ const limit = useSettingsStore((s) => s.settings.downloadLimitMBps)
+ const updateSettings = useSettingsStore((s) => s.updateSettings)
+ const [draft, setDraft] = useState<string | null>(null)
+ const apply = () => {
+ if (draft === null) return
+ updateSettings({ downloadLimitMBps: parseDownloadLimit(draft) })
+ setDraft(null)
+ }
+
+ return (
+ <div className="space-y-1 py-1">
+ <div className="flex items-center justify-between">
+ <span className="t-micro font-semibold text-gray-700 dark:text-gray-300">Download speed limit</span>
+ <div className="flex items-center gap-1.5">
+ <input
+ aria-label="Download speed limit in MB/s"
+ type="number"
+ min={0}
+ step={0.5}
+ value={draft ?? String(limit)}
+ onChange={(e) => setDraft(e.target.value)}
+ onBlur={apply}
+ onKeyDown={(e) => { if (e.key === 'Enter') apply() }}
+ className="w-20 px-1.5 py-0.5 rounded bg-transparent border border-white/8 t-mono text-right text-gray-300 focus:outline-none focus:border-white/20"
+ />
+ <span className="t-micro text-gray-500">MB/s</span>
+ </div>
+ </div>
+ <div className="t-micro text-gray-500 leading-relaxed">
+ {limit > 0
+ ? `Model downloads share ${limit} MB/s between them. 0 removes the limit.`
+ : '0 = no limit. Applies to the model files LU downloads itself, all of them together. Ollama pulls and installs are not limited.'}
+ </div>
+ </div>
+ )
+}
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index e4bcf362..6b56d315 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -37,6 +37,7 @@ import { LocalApiSettings } from './LocalApiSettings'
import { RemoteAccessSettings } from './RemoteAccessSettings'
import { RemoteAccessDocs } from './RemoteAccessDocs'
import { HardwareSettings } from './HardwareSettings'
+import { DownloadLimitSetting } from './DownloadLimitSetting'
import { ChatbotImporter } from '../import/ChatbotImporter'
import { ProviderSettings } from './ProviderConfig'
import { BuiltinEngineSettings } from './BuiltinEngineSettings'
@@ -2145,6 +2146,7 @@ export function SettingsPage() {
<Section title="Model Storage">
<HfDownloadPathSetting />
+ <DownloadLimitSetting />
<LmStudioFolderSetting />
<ImportLocalModels />
</Section>
diff --git a/src/lib/__tests__/the-download-speed-can-be-limited.test.tsx b/src/lib/__tests__/the-download-speed-can-be-limited.test.tsx
new file mode 100644
index 00000000..2e8855ea
--- /dev/null
+++ b/src/lib/__tests__/the-download-speed-can-be-limited.test.tsx
@@ -0,0 +1,67 @@
+// @vitest-environment jsdom
+/**
+ * Discord, boromirofgeo 2026-09-23: "is there a way to limit download speed
+ * that this app does whenever it downloads anything?" Settings, Model Storage
+ * now holds a limit in MB/s, and the downloader in Rust gets it at boot and on
+ * every change (the shared throttle itself is tested in download.rs).
+ *
+ * Run: npx vitest run src/lib/__tests__/the-download-speed-can-be-limited.test.tsx
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+const backendCall = vi.fn(async () => null)
+vi.mock('../../api/backend', async (o) => ({
+ ...(await o<typeof import('../../api/backend')>()),
+ isTauri: () => true,
+ backendCall: (...a: unknown[]) => backendCall(...(a as [])),
+}))
+
+import { parseDownloadLimit, startDownloadLimitSync } from '../download-limit'
+import { DownloadLimitSetting } from '../../components/settings/DownloadLimitSetting'
+import { useSettingsStore } from '../../stores/settingsStore'
+import { DEFAULT_SETTINGS } from '../constants'
+
+const limitCalls = () => backendCall.mock.calls.filter((c) => (c as unknown[])[0] === 'set_download_limit').map((c) => (c as unknown[])[1])
+
+beforeEach(() => {
+ cleanup()
+ backendCall.mockClear()
+ useSettingsStore.getState().updateSettings({ downloadLimitMBps: 0 })
+})
+
+describe('the download speed limit', () => {
+ it('is off by default', () => {
+ expect(DEFAULT_SETTINGS.downloadLimitMBps).toBe(0)
+ })
+
+ it('reads what people type, and anything unusable means no limit', () => {
+ expect(parseDownloadLimit('10')).toBe(10)
+ expect(parseDownloadLimit('2,5')).toBe(2.5)
+ expect(parseDownloadLimit('')).toBe(0)
+ expect(parseDownloadLimit('-3')).toBe(0)
+ expect(parseDownloadLimit('fast')).toBe(0)
+ })
+
+ it('typed in Settings, it reaches the downloader at boot and on every change', async () => {
+ useSettingsStore.getState().updateSettings({ downloadLimitMBps: 4 })
+ await startDownloadLimitSync()
+ expect(limitCalls()).toEqual([{ mbPerSec: 4 }])
+
+ render(<DownloadLimitSetting />)
+ const box = screen.getByLabelText('Download speed limit in MB/s')
+ fireEvent.change(box, { target: { value: '12.5' } })
+ fireEvent.blur(box)
+ expect(useSettingsStore.getState().settings.downloadLimitMBps).toBe(12.5)
+ await vi.waitFor(() => expect(limitCalls()).toContainEqual({ mbPerSec: 12.5 }))
+ expect(screen.getByText('Model downloads share 12.5 MB/s between them. 0 removes the limit.')).toBeTruthy()
+ })
+
+ // Negative control: a store write that leaves the limit alone sends nothing.
+ it('other settings changes do not touch the downloader', async () => {
+ await startDownloadLimitSync()
+ backendCall.mockClear()
+ useSettingsStore.getState().updateSettings({ loopMaxPasses: 3 })
+ expect(limitCalls()).toEqual([])
+ })
+})
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index f381a0a6..300b9229 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -54,6 +54,7 @@ export const DEFAULT_SETTINGS: Settings = {
// Unlimited by design — see the note on the type.
loopMaxPasses: 0,
hfDownloadPathOverride: '',
+ downloadLimitMBps: 0,
// Generation timeouts (Bug P v2.4.7)
imageGenTimeoutMinutes: 20,
videoGenTimeoutMinutes: 60,
diff --git a/src/lib/download-limit.ts b/src/lib/download-limit.ts
new file mode 100644
index 00000000..9c7267db
--- /dev/null
+++ b/src/lib/download-limit.ts
@@ -0,0 +1,32 @@
+// The download speed limit lives in Rust, next to the one loop every model
+// file LU fetches runs through (commands/download.rs, do_download). Settings
+// holds the number; this hands it over at boot and whenever it changes.
+import { backendCall, isTauri } from '../api/backend'
+import { log } from './logger'
+import { useSettingsStore } from '../stores/settingsStore'
+
+/** A typed value as the setting stores it: a number of MB/s, 0 for none. */
+export function parseDownloadLimit(raw: string): number {
+ const n = Number.parseFloat(raw.replace(',', '.'))
+ return Number.isFinite(n) && n > 0 ? Math.round(n * 10) / 10 : 0
+}
+
+export async function syncDownloadLimit(mbPerSec: number): Promise<void> {
+ if (!isTauri()) return
+ try {
+ await backendCall('set_download_limit', { mbPerSec: Math.max(0, mbPerSec || 0) })
+ } catch (err) {
+ log.warn('download_limit.sync_failed', { err })
+ }
+}
+
+/** At boot: the Rust side starts at no limit on every launch, so it gets the
+ * stored number now and again on every change, including a Reset. */
+export function startDownloadLimitSync(): Promise<void> {
+ useSettingsStore.subscribe((s, prev) => {
+ if (s.settings.downloadLimitMBps !== prev.settings.downloadLimitMBps) {
+ void syncDownloadLimit(s.settings.downloadLimitMBps)
+ }
+ })
+ return syncDownloadLimit(useSettingsStore.getState().settings.downloadLimitMBps)
+}
diff --git a/src/lib/settings-reset.ts b/src/lib/settings-reset.ts
index 72a01ab5..58507cfa 100644
--- a/src/lib/settings-reset.ts
+++ b/src/lib/settings-reset.ts
@@ -20,7 +20,7 @@ export const SETTINGS_TAB_RESET_KEYS: Record<SettingsTab, (keyof Settings)[]> =
'gpuVendor', 'gpuIndices',
'imageGenTimeoutMinutes', 'videoGenTimeoutMinutes',
],
- backends: ['apiEndpoint', 'hfDownloadPathOverride', 'exclusiveVramMode', 'builtinEngine'],
+ backends: ['apiEndpoint', 'hfDownloadPathOverride', 'downloadLimitMBps', 'exclusiveVramMode', 'builtinEngine'],
agent: [
'personasEnabled', 'defaultWorkspace',
'agentMaxToolCalls', 'agentMaxIterations',
diff --git a/src/types/settings.ts b/src/types/settings.ts
index e60d7dd5..a1d73247 100644
--- a/src/types/settings.ts
+++ b/src/types/settings.ts
@@ -141,6 +141,9 @@ export interface Settings {
loopMaxPasses: number
/** Override for the HuggingFace GGUF download directory. Empty = auto-detect from active openai-compat provider (e.g. LM Studio models folder). */
hfDownloadPathOverride: string
+ /** Cap for the model files LU downloads itself, in MB/s, shared by all
+ * downloads at once. 0 = no limit (Discord, boromirofgeo 2026-09-23). */
+ downloadLimitMBps: number
// Generation timeouts (Bug P v2.4.7 — ake0n_official Discord 2026-05-19,
// Intel UHD CPU-only setup hit the 20-min cap at sampling 9/25 on a 1024px
// Juggernaut-XL gen).