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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(downloads): der Fortschritt zaehlt den Ordner, in den wirklich geschrieben wird
purple0763319e8c1d
diff --git a/src-tauri/src/commands/install/pip.rs b/src-tauri/src/commands/install/pip.rsindex a8acd449..f178cc40 100644--- a/src-tauri/src/commands/install/pip.rs+++ b/src-tauri/src/commands/install/pip.rs@@ -197,7 +197,20 @@ pub(crate) fn process_read_bytes(pid: u32) -> Option<u64> {let mut counters = std::mem::zeroed::<IoCounters>();let ok = GetProcessIoCounters(handle, &mut counters);CloseHandle(handle);- (ok != 0).then_some(counters.read_bytes)+ // `other_bytes` and not just `read_bytes`. Windows books a socket read+ // as OtherTransferCount, because a socket is reached through+ // DeviceIoControl on AFD and not through ReadFile. pip downloads over+ // HTTPS, so on Windows ReadTransferCount barely moves while a wheel+ // comes down the line, and the header stood at "(0 B of 1.9 GB)" for+ // the whole 1990.6 MB of torch (T3 nebenfund, box, 11.09.2026). The+ // Linux arm reads `rchar`, which counts every read() including+ // sockets, which is why the same feature worked there and only there.+ //+ // The sum overstates a little: other I/O is not only the network. It+ // is measured against a baseline taken at the start of this run and+ // clamped to the announced total by the caller, so the bar can move+ // too fast but never past the end and never backwards.+ (ok != 0).then_some(counters.read_bytes.saturating_add(counters.other_bytes))}}@@ -816,6 +829,37 @@ mod tests {// ── Download-Anzeige am Rebuilding-Spinner (#162) ───────────────────+ /// Der Fortschrittsbalken der ComfyUI-Reparatur stand auf Windows still.+ ///+ /// T3 auf der Box, 11.09.2026: waehrend der ganzen 1990,6 MB des+ /// Torch-Downloads stand in der Kopfzeile "Rebuilding the ComfyUI+ /// environment... (0 B of 1.9 GB)". Die Gesamtzahl stimmte, der Zaehler+ /// bewegte sich nicht. Grund: Windows bucht einen Socket-Lesevorgang als+ /// OtherTransferCount und nicht als ReadTransferCount, weil ein Socket+ /// ueber DeviceIoControl auf AFD erreicht wird. Der Linux-Zweig liest+ /// `rchar`, das jeden read() einschliesslich Sockets zaehlt, und+ /// funktionierte deshalb.+ ///+ /// Auf dieser Maschine ist der Windows-Zweig nicht uebersetzt, also wird+ /// hier der Quelltext gelesen. Am laufenden Balken nachzumessen ist Sache+ /// eines Testers auf der Box.+ #[test]+ fn the_windows_byte_counter_includes_socket_traffic() {+ let src = include_str!("pip.rs");+ let win = src+ .split("#[cfg(target_os = \"windows\")]")+ .nth(1)+ .expect("der Windows-Zweig von process_read_bytes");+ let win = &win[..win.find("#[cfg(target_os = \"linux\")]").unwrap_or(win.len())];+ assert!(+ win.contains("counters.read_bytes.saturating_add(counters.other_bytes)"),+ "der Windows-Zaehler laesst den Netzverkehr wieder liegen"+ );+ // Gegenprobe: der Linux-Zweig bleibt bei rchar, das den Socket schon+ // mitzaehlt; dort waere eine Summe eine Doppelzaehlung.+ assert!(src.contains("strip_prefix(\"rchar:\")"));+ }+#[test]fn pip_download_size_parses_decimal_units() {assert_eq!(diff --git a/src-tauri/src/commands/mlx.rs b/src-tauri/src/commands/mlx.rsindex 282561a0..6bb7fff7 100644--- a/src-tauri/src/commands/mlx.rs+++ b/src-tauri/src/commands/mlx.rs@@ -266,7 +266,8 @@ fn install_mlx_steps(slot: &crate::install_state::InstallSlot) -> Result<(), Strlet mut prefetch_cmd = Command::new(venv_python());prefetch_cmd.args(["-c", prefetch])- .env("HF_HOME", mlx_root().join("cache"));+ .env("HF_HOME", mlx_root().join("cache"))+ .env("HF_XET_CACHE", hf_xet_cache_dir());apply_hf_token(&mut prefetch_cmd);let out = prefetch_cmd.output()@@ -534,6 +535,22 @@ fn image_model_cache_dir(repo: &str) -> PathBuf {.join(format!("models--{}", repo.replace('/', "--")))}+/// The Xet chunk cache inside our HF_HOME (`cache/xet`).+///+/// huggingface_hub 1.x downloads over Xet by default, and Xet does not fill+/// `<repo>/blobs/<sha>.incomplete` the way the plain HTTP path does: the bytes+/// land here first, in a folder that sits NEXT TO the repo folder rather than+/// inside it. The progress watcher therefore has to look at both, or it reads+/// near zero for minutes while the line is busy (bauer-m, Mac, 11.09.2026, N1:+/// "1.7 MB / 8.0 GB 0%" after four and a half minutes, with 2.1 MB sitting+/// right here). Shared by every repo, so only its growth counts.+///+/// Pinned through `HF_XET_CACHE` on every command that downloads, so this path+/// is what the library really uses and not what it happens to default to.+fn hf_xet_cache_dir() -> PathBuf {+ mlx_root().join("cache").join("xet")+}+/// The snapshot directories of one repo, the revision `refs/main` points at/// first. A cache can hold more than one revision; the one the hub currently/// serves is the one an install has just written.@@ -797,7 +814,7 @@ fn refetch_file(v = revision,);let mut cmd = Command::new(python);- cmd.args(["-c", &script]).env("HF_HOME", &cache);+ cmd.args(["-c", &script]).env("HF_HOME", &cache).env("HF_XET_CACHE", hf_xet_cache_dir());apply_hf_token(&mut cmd);crate::commands::video::run_streamed(slot, &mut cmd).map_err(|e| format!("re-fetching {}: {e}", repair.path))?;@@ -943,6 +960,7 @@ pub fn mlx_image_install_model(state: &AppState, args: &Value) -> CmdResult {crate::install_state::watch_dir_size(slot2.clone(),image_model_cache_dir(entry2.repo),+ Some(hf_xet_cache_dir()),total,);@@ -960,7 +978,8 @@ pub fn mlx_image_install_model(state: &AppState, args: &Value) -> CmdResult {);let mut cmd = Command::new(&python);cmd.args(["-c", &script])- .env("HF_HOME", mlx_root().join("cache"));+ .env("HF_HOME", mlx_root().join("cache"))+ .env("HF_XET_CACHE", hf_xet_cache_dir());apply_hf_token(&mut cmd);if let Err(e) = crate::commands::video::run_streamed(&slot2, &mut cmd) {slot2.fail(e);@@ -1196,6 +1215,7 @@ pub fn mlx_start(_state: &AppState, _args: &Value) -> CmdResult {.arg(&server).env("LU_MLX_PORT", MLX_PORT.to_string()).env("HF_HOME", mlx_root().join("cache"))+ .env("HF_XET_CACHE", hf_xet_cache_dir()).stdout(stdout).stderr(stderr);apply_hf_token(&mut server_cmd);diff --git a/src-tauri/src/commands/video.rs b/src-tauri/src/commands/video.rsindex 067e714c..e324a0dc 100644--- a/src-tauri/src/commands/video.rs+++ b/src-tauri/src/commands/video.rs@@ -461,9 +461,15 @@ pub fn video_install_model(state: &AppState, args: &Value) -> CmdResult {std::fs::create_dir_all(parent).map_err(|e| internal(os_error::english(&e)))?;}slot.start();+ // Kein geteilter Zwischenspeicher: dieser Weg laedt mit `local_dir`, und+ // huggingface_hub legt den Zwischenstand dann unter `<local_dir>/.cache`+ // ab, also INNERHALB des Ordners, der hier gemessen wird. Der Xet-Cache+ // liegt fuer diesen Weg trotzdem daneben (HF_HOME wird hier nicht gesetzt,+ // also im Standardordner des Nutzers); siehe Bericht bauer-t, Fund 3.crate::install_state::watch_dir_size(slot.clone(),model_dir(entry.id),+ None,(entry.size_gb as f64 * 1e9) as u64,);let slot2 = slot.clone();diff --git a/src-tauri/src/install_state.rs b/src-tauri/src/install_state.rsindex 19721242..80e5a38c 100644--- a/src-tauri/src/install_state.rs+++ b/src-tauri/src/install_state.rs@@ -84,6 +84,12 @@ impl InstallSlot {}}+/// What THIS run added to a shared cache. Never negative: a cache that is+/// pruned mid-download must not make the bar walk backwards.+fn downloaded_into_shared(shared: Option<&std::path::Path>, base: u64) -> u64 {+ shared.map(|p| dir_size(p).saturating_sub(base)).unwrap_or(0)+}+fn dir_size(path: &std::path::Path) -> u64 {let Ok(read) = std::fs::read_dir(path) else {return 0;@@ -102,11 +108,30 @@ fn dir_size(path: &std::path::Path) -> u64 {/// to `huggingface_hub.snapshot_download`, which reports nothing machine-/// readable on stdout; the growing target directory is the one progress/// signal that exists on every platform.-pub fn watch_dir_size(slot: InstallSlot, dir: std::path::PathBuf, total_bytes: u64) {+///+/// `shared` is a cache directory that the SAME download also writes into but+/// that other downloads share. Only its GROWTH during this run counts, because+/// whatever lay there when we started belongs to somebody else's model.+///+/// Why the second directory exists at all: since huggingface_hub 1.x the+/// default transport is Xet, and Xet does not stream into+/// `<repo>/blobs/<sha>.incomplete` the way the plain HTTP path does. It fills+/// its own chunk cache at `$HF_HOME/xet`, a SIBLING of the repo folder we+/// watch. So the watched folder stayed near empty while the line was busy, and+/// the downloads bar read "1.7 MB / 8.0 GB 0%" after four and a half minutes+/// of real traffic (bauer-m on the Mac, 11.09.2026, N1). The bytes were never+/// missing, they were being counted in the wrong place.+pub fn watch_dir_size(+ slot: InstallSlot,+ dir: std::path::PathBuf,+ shared: Option<std::path::PathBuf>,+ total_bytes: u64,+) {std::thread::spawn(move || {let mut last: Option<(std::time::Instant, u64)> = None;+ let shared_base = shared.as_deref().map(dir_size).unwrap_or(0);while slot.is_running() {- let size = dir_size(&dir);+ let size = dir_size(&dir) + downloaded_into_shared(shared.as_deref(), shared_base);let speed = match last {Some((t, prev)) if size > prev => {((size - prev) as f64 / t.elapsed().as_secs_f64().max(0.001)) as u64@@ -140,6 +165,38 @@ mod tests {assert_eq!(slot.snapshot().download_progress, 1500);}+ /// Der Stillstand der Anzeige, als Rechnung.+ ///+ /// bauer-m auf dem Mac, 11.09.2026 (N1): nach viereinhalb Minuten stand+ /// "1.7 MB / 8.0 GB 0%" in der Leiste, waehrend die Leitung arbeitete. Die+ /// Bytes lagen im Xet-Zwischenspeicher, einem GESCHWISTER des beobachteten+ /// Repo-Ordners, und wurden deshalb nicht gezaehlt.+ #[test]+ fn the_shared_cache_counts_what_this_run_added_to_it() {+ let root = std::env::temp_dir().join(format!("lu-shared-{}", std::process::id()));+ let xet = root.join("xet");+ std::fs::create_dir_all(&xet).unwrap();+ // Was beim Start schon dalag, gehoert einem anderen Modell.+ std::fs::write(xet.join("alt.bin"), vec![0u8; 2_000]).unwrap();+ let base = dir_size(&xet);+ assert_eq!(base, 2_000);+ assert_eq!(downloaded_into_shared(Some(&xet), base), 0, "fremde Bytes zaehlen nicht mit");++ // Und was dieser Lauf dazulegt, zaehlt sofort.+ std::fs::write(xet.join("neu.bin"), vec![0u8; 500]).unwrap();+ assert_eq!(downloaded_into_shared(Some(&xet), base), 500);++ // Ein geleerter Zwischenspeicher laesst den Balken nicht rueckwaerts laufen.+ std::fs::remove_file(xet.join("alt.bin")).unwrap();+ assert_eq!(downloaded_into_shared(Some(&xet), base), 0);++ // Gegenprobe: ohne zweiten Ordner bleibt es bei null, also genau beim+ // Verhalten von vorher.+ assert_eq!(downloaded_into_shared(None, 0), 0);+ assert_eq!(downloaded_into_shared(Some(&root.join("gibt-es-nicht")), 0), 0);+ let _ = std::fs::remove_dir_all(&root);+ }+#[test]fn dir_size_sums_nested_files() {let root = std::env::temp_dir().join(format!("lu-dirsize-{}", std::process::id()));