From 41be3070ec4fda9663ca63e0265f7cba07dc8158 Mon Sep 17 00:00:00 2001 From: Klaus Ma Date: Thu, 12 Feb 2026 21:12:01 +0800 Subject: [PATCH 1/2] fix: use UV_CACHE_DIR for dependency caching - Use uv pip install --target instead of non-existent uv pip download - Set UV_CACHE_DIR to ${FLAME_HOME}/data/cache/uv during installation - Add UV_CACHE_DIR env var to flmrun application - Expand env vars in executor_manager for environment settings Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- common/src/lib.rs | 3 ++ executor_manager/src/shims/host_shim.rs | 7 ++++- flmadm/src/managers/installation.rs | 40 +++++++++++++++++-------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index 04c1dd4c..47da80c1 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -191,6 +191,8 @@ pub fn default_applications() -> HashMap { // Use pre-built wheel from wheels directory to avoid rebuild on every run // The wheel is built during installation via "flmadm install" let flamepy_wheels_dir = "${FLAME_HOME}/wheels".to_string(); + // Use the same cache directory that was populated during installation + let uv_cache_dir = "${FLAME_HOME}/data/cache/uv".to_string(); HashMap::from([ ( @@ -239,6 +241,7 @@ pub fn default_applications() -> HashMap { "-m".to_string(), "flamepy.runner.runpy".to_string(), ], + environments: HashMap::from([("UV_CACHE_DIR".to_string(), uv_cache_dir)]), working_directory: None, ..ApplicationAttributes::default() }, diff --git a/executor_manager/src/shims/host_shim.rs b/executor_manager/src/shims/host_shim.rs index e18e6711..e21377db 100644 --- a/executor_manager/src/shims/host_shim.rs +++ b/executor_manager/src/shims/host_shim.rs @@ -229,7 +229,12 @@ impl HostShim { let log_level = env::var(RUST_LOG).unwrap_or(String::from(DEFAULT_SVC_LOG_LEVEL)); - let mut envs = app.environments.clone(); + // Expand environment variables in the application's environment settings + let mut envs: HashMap = app + .environments + .iter() + .map(|(k, v)| (k.clone(), Self::expand_env_vars(v))) + .collect(); envs.insert(RUST_LOG.to_string(), log_level.clone()); envs.insert(FLAME_LOG.to_string(), log_level); envs.insert(FLAME_INSTANCE_ENDPOINT.to_string(), endpoint.to_string()); diff --git a/flmadm/src/managers/installation.rs b/flmadm/src/managers/installation.rs index ef721fd9..d08b1986 100644 --- a/flmadm/src/managers/installation.rs +++ b/flmadm/src/managers/installation.rs @@ -236,28 +236,42 @@ impl InstallationManager { println!(" ✓ Built wheel to: {}", paths.wheels.display()); - // Pre-cache dependencies by downloading them to the wheels directory - // This way "uv run --find-links " can use cached packages - println!(" 📥 Downloading dependencies..."); + // Pre-cache dependencies using uv's cache + // Use FLAME_HOME/data/cache/uv as the cache directory so it's available at runtime + println!(" 📥 Caching dependencies..."); - let output = std::process::Command::new(&uv_path) + let uv_cache_dir = paths.cache.join("uv"); + + // Install flamepy and dependencies to populate the cache + // Using --target to a temp directory avoids needing a venv + let cache_target = paths.work.join(".flamepy-cache-target"); + fs::create_dir_all(&cache_target).ok(); + + let install_output = std::process::Command::new(&uv_path) .arg("pip") - .arg("download") - .arg("--dest") + .arg("install") + .arg("--target") + .arg(&cache_target) + .arg("--find-links") .arg(&paths.wheels) - .arg(&paths.sdk_python) + .arg("flamepy") + .arg("pip") // Also cache pip as it's used by flmrun + .env("UV_CACHE_DIR", &uv_cache_dir) .output() - .context("Failed to execute uv pip download")?; + .context("Failed to execute uv pip install")?; - if !output.status.success() { - let stderr = String::from_utf8_lossy(&output.stderr); - // Don't fail installation if download fails (might be offline) + // Clean up target directory (we only needed to populate the cache) + let _ = fs::remove_dir_all(&cache_target); + + if !install_output.status.success() { + let stderr = String::from_utf8_lossy(&install_output.stderr); + // Don't fail installation if caching fails (might be offline) println!( - " ⚠️ Failed to download dependencies (will fetch at runtime): {}", + " ⚠️ Failed to cache dependencies (will fetch at runtime): {}", stderr.lines().next().unwrap_or(&stderr) ); } else { - println!(" ✓ Downloaded dependencies to: {}", paths.wheels.display()); + println!(" ✓ Cached dependencies to: {}", uv_cache_dir.display()); } Ok(()) From b1d544960b67c29631cc0f0cde38c13baf8afe47 Mon Sep 17 00:00:00 2001 From: Klaus Ma Date: Thu, 12 Feb 2026 21:20:18 +0800 Subject: [PATCH 2/2] Update flmadm/src/managers/installation.rs Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- flmadm/src/managers/installation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flmadm/src/managers/installation.rs b/flmadm/src/managers/installation.rs index d08b1986..115dd9e1 100644 --- a/flmadm/src/managers/installation.rs +++ b/flmadm/src/managers/installation.rs @@ -245,7 +245,7 @@ impl InstallationManager { // Install flamepy and dependencies to populate the cache // Using --target to a temp directory avoids needing a venv let cache_target = paths.work.join(".flamepy-cache-target"); - fs::create_dir_all(&cache_target).ok(); + fs::create_dir_all(&cache_target).context("Failed to create temporary directory for caching")?; let install_output = std::process::Command::new(&uv_path) .arg("pip")