From 68bb16ad67406ad59a9b7de86ea2a0e664ceafb2 Mon Sep 17 00:00:00 2001 From: Roman Sirokov Date: Wed, 14 Oct 2026 15:23:21 +0300 Subject: [PATCH 1/2] fix(lemonade): fall back to platform home dir when HOME is unset Windows never sets HOME, but Lemonade still caches downloaded GGUFs under %USERPROFILE%\.cache\huggingface\hub. hf_cache_roots_from only checked the HOME env var, so on Windows the lookup skipped that cache root entirely and ensure_hf_checkpoint_downloaded reported the file as missing even though the download had succeeded. Fall back to runtime_home_dir() (which resolves USERPROFILE on Windows) when HOME is unset, and name the directories that were searched in the "did not download" errors so a future mismatch is easier to diagnose. Signed-off-by: Roman Sirokov --- engines/lemonade/src/direct_llama.rs | 102 +++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 13 deletions(-) diff --git a/engines/lemonade/src/direct_llama.rs b/engines/lemonade/src/direct_llama.rs index 44bc6a482d..1f025e46ea 100644 --- a/engines/lemonade/src/direct_llama.rs +++ b/engines/lemonade/src/direct_llama.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT use anyhow::{Result, anyhow, bail}; -use rocm_core::AppPaths; +use rocm_core::{AppPaths, runtime_home_dir}; use std::fs; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -128,7 +128,11 @@ fn ensure_hf_checkpoint_downloaded( if direct_llama_model_path(&paths, &request.model_ref).is_some() { Ok(()) } else { - bail!("Lemonade did not download `{}`", request.model_ref) + bail!( + "Lemonade did not download `{}` (searched {})", + request.model_ref, + describe_hf_cache_roots(&paths) + ) } })(); let _ = terminate_pid(child.id(), true); @@ -178,8 +182,9 @@ pub(crate) fn ensure_direct_llama_model_available( Ok(()) } else { bail!( - "Lemonade did not download `{}` for direct ROCm serving", - request.model_ref + "Lemonade did not download `{}` for direct ROCm serving (searched {})", + request.model_ref, + describe_hf_cache_roots(&paths) ) } })(); @@ -338,12 +343,20 @@ pub(crate) fn direct_llama_model_path(paths: &AppPaths, model_ref: &str) -> Opti } fn hf_cache_roots(paths: &AppPaths) -> Vec { - hf_cache_roots_from(paths, |name| std::env::var_os(name).map(PathBuf::from)) + hf_cache_roots_from( + paths, + |name| std::env::var_os(name).map(PathBuf::from), + runtime_home_dir, + ) } -fn hf_cache_roots_from(paths: &AppPaths, mut env_path: F) -> Vec +/// `home_dir` is only consulted when `HOME` is unset, which is always true on Windows +/// (Lemonade still caches under `%USERPROFILE%\.cache\huggingface\hub`); it's injected +/// so the fallback can be exercised without depending on the host's actual platform. +fn hf_cache_roots_from(paths: &AppPaths, mut env_path: F, home_dir: H) -> Vec where F: FnMut(&str) -> Option, + H: FnOnce() -> Option, { let mut roots = Vec::new(); if let Some(hub_cache) = env_path("HUGGINGFACE_HUB_CACHE") { @@ -353,7 +366,7 @@ where push_hf_cache_root(&mut roots, hf_home.join("hub")); } push_hf_cache_root(&mut roots, paths.cache_dir.join("huggingface").join("hub")); - if let Some(home) = env_path("HOME") { + if let Some(home) = env_path("HOME").or_else(home_dir) { push_hf_cache_root( &mut roots, home.join(".cache").join("huggingface").join("hub"), @@ -362,6 +375,20 @@ where roots } +/// Render the cache directories `hf_cache_roots` searches, for use in an error message +/// when none of them held the expected file. +fn describe_hf_cache_roots(paths: &AppPaths) -> String { + let roots = hf_cache_roots(paths); + if roots.is_empty() { + return "no Hugging Face cache directories could be determined".to_owned(); + } + roots + .iter() + .map(|root| root.display().to_string()) + .collect::>() + .join(", ") +} + fn push_hf_cache_root(roots: &mut Vec, path: PathBuf) { if path.as_os_str().is_empty() || roots.iter().any(|existing| existing == &path) { return; @@ -741,12 +768,17 @@ mod tests { data_dir: PathBuf::from("data"), cache_dir: PathBuf::from("rocm-cache"), }; - let roots = hf_cache_roots_from(&paths, |name| match name { - "HUGGINGFACE_HUB_CACHE" => Some(PathBuf::from("hf-hub")), - "HF_HOME" => Some(PathBuf::from("hf-home")), - "HOME" => Some(PathBuf::from("home")), - _ => None, - }); + let roots = hf_cache_roots_from( + &paths, + |name| match name { + "HUGGINGFACE_HUB_CACHE" => Some(PathBuf::from("hf-hub")), + "HF_HOME" => Some(PathBuf::from("hf-home")), + "HOME" => Some(PathBuf::from("home")), + _ => None, + }, + // `HOME` is set above, so the fallback must never be consulted. + || panic!("home_dir fallback must not run when HOME is set"), + ); assert_eq!( roots, @@ -761,4 +793,48 @@ mod tests { ] ); } + + #[test] + fn hf_cache_roots_falls_back_to_platform_home_when_home_unset() { + // Windows never sets `HOME`, but Lemonade still caches under + // `%USERPROFILE%\.cache\huggingface\hub`; the lookup must fall back to the + // platform home directory (here standing in for `runtime_home_dir`, which + // itself resolves `USERPROFILE` on Windows) rather than skip the hub cache. + let paths = AppPaths { + config_dir: PathBuf::from("config"), + data_dir: PathBuf::from("data"), + cache_dir: PathBuf::from("rocm-cache"), + }; + let roots = hf_cache_roots_from( + &paths, + |_name| None, + || Some(PathBuf::from(r"C:\Users\dev")), + ); + + assert_eq!( + roots, + vec![ + PathBuf::from("rocm-cache").join("huggingface").join("hub"), + PathBuf::from(r"C:\Users\dev") + .join(".cache") + .join("huggingface") + .join("hub"), + ] + ); + } + + #[test] + fn hf_cache_roots_skips_home_fallback_when_platform_home_unavailable() { + let paths = AppPaths { + config_dir: PathBuf::from("config"), + data_dir: PathBuf::from("data"), + cache_dir: PathBuf::from("rocm-cache"), + }; + let roots = hf_cache_roots_from(&paths, |_name| None, || None); + + assert_eq!( + roots, + vec![PathBuf::from("rocm-cache").join("huggingface").join("hub")] + ); + } } From a8d3dc77ebb23fe8b123cb55ff4999c4457da149 Mon Sep 17 00:00:00 2001 From: Roman Sirokov Date: Wed, 14 Oct 2026 16:42:58 +0300 Subject: [PATCH 2/2] test(lemonade): assert the HF cache-root error text names every root The "did not download" errors now claim a specific set of searched directories, but nothing tied that claim to the lookup it describes. Split the rendering out of describe_hf_cache_roots so the text can be asserted against the roots hf_cache_roots_from actually returns, and cover both the populated case (including the Windows USERPROFILE fallback this change adds) and the no-roots-resolved case. Signed-off-by: Roman Sirokov --- engines/lemonade/src/direct_llama.rs | 47 +++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/engines/lemonade/src/direct_llama.rs b/engines/lemonade/src/direct_llama.rs index 1f025e46ea..c3187b465f 100644 --- a/engines/lemonade/src/direct_llama.rs +++ b/engines/lemonade/src/direct_llama.rs @@ -378,7 +378,13 @@ where /// Render the cache directories `hf_cache_roots` searches, for use in an error message /// when none of them held the expected file. fn describe_hf_cache_roots(paths: &AppPaths) -> String { - let roots = hf_cache_roots(paths); + render_hf_cache_roots(&hf_cache_roots(paths)) +} + +/// The rendering half of [`describe_hf_cache_roots`], split out so the error text can be +/// asserted against the same root list `hf_cache_roots_from` produces, without depending +/// on the host's real environment. +fn render_hf_cache_roots(roots: &[PathBuf]) -> String { if roots.is_empty() { return "no Hugging Face cache directories could be determined".to_owned(); } @@ -837,4 +843,43 @@ mod tests { vec![PathBuf::from("rocm-cache").join("huggingface").join("hub")] ); } + + /// The "did not download" errors claim they searched a specific set of directories. + /// Assert that claim against the roots `hf_cache_roots_from` actually returns, so the + /// message cannot drift from the lookup it describes — in particular, that the + /// Windows `USERPROFILE` fallback this fix adds is named in the text a user sees. + #[test] + fn hf_cache_root_description_names_every_searched_root() { + let paths = AppPaths { + config_dir: PathBuf::from("config"), + data_dir: PathBuf::from("data"), + cache_dir: PathBuf::from("rocm-cache"), + }; + let roots = hf_cache_roots_from( + &paths, + |_name| None, + || Some(PathBuf::from(r"C:\Users\dev")), + ); + let described = render_hf_cache_roots(&roots); + + for root in &roots { + assert!( + described.contains(&root.display().to_string()), + "error text {described:?} omits searched root {}", + root.display() + ); + } + assert!( + described.contains(&PathBuf::from(r"C:\Users\dev").display().to_string()), + "error text {described:?} must name the platform-home fallback root" + ); + } + + #[test] + fn hf_cache_root_description_reports_when_no_roots_resolve() { + assert_eq!( + render_hf_cache_roots(&[]), + "no Hugging Face cache directories could be determined" + ); + } }