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.

Report missing MLX snapshot components

David2d2d4e956345
diff --git a/e2e/mac-create-mlx.spec.ts b/e2e/mac-create-mlx.spec.ts
index a571205c..ef654a07 100644
--- a/e2e/mac-create-mlx.spec.ts
+++ b/e2e/mac-create-mlx.spec.ts
@@ -24,6 +24,27 @@ const MAC_OPTS: TauriMockOptions = {
platform: 'mac',
}
+test('mac model install reports the missing snapshot component without claiming success', async ({ page }) => {
+ const error = 'Model installation did not finish: unet/ has no readable, non-empty .safetensors or .bin weights file. Retry the download to repair the missing files.'
+ await page.addInitScript(tauriMockInit, {
+ ...MAC_OPTS,
+ mlx: { engineInstalled: true, installedImages: [], imageInstallError: error },
+ })
+ await seedOnboardingDone(page)
+ await routeCloud(page, { license: 'active', access: true, mediaLive: true })
+ await page.goto('/')
+ await expect(cloudSwitch(page)).toBeVisible({ timeout: 20_000 })
+ await page.getByRole('button', { name: /^Settings$/ }).click()
+ await page.getByRole('button', { name: /AI Backends/i }).click()
+ await page.getByRole('button', { name: /Local Media \(Apple MLX\)/i }).click()
+ const row = page.locator('div.items-start.justify-between').filter({ has: page.getByText('SD Turbo', { exact: true }) })
+ await row.getByRole('button', { name: /^Install$/ }).click()
+ await expect(page.getByText(error, { exact: true }).first()).toBeVisible({ timeout: 20_000 })
+ await expect(row.getByRole('button', { name: /^Install$/ })).toBeEnabled()
+ await expect(row.getByRole('button', { name: /Remove/i })).toHaveCount(0)
+ expect((await mlxCalls(page)).some(call => call.cmd === 'mlx_image_install_model' && call.id === 'sd-turbo')).toBe(true)
+})
+
async function bootLocalCreate(page: Page, opts: TauriMockOptions) {
await page.addInitScript(tauriMockInit, opts)
await seedOnboardingDone(page)
diff --git a/e2e/support/tauri-mock.ts b/e2e/support/tauri-mock.ts
index d68e1be9..980b41d4 100644
--- a/e2e/support/tauri-mock.ts
+++ b/e2e/support/tauri-mock.ts
@@ -27,6 +27,7 @@ export interface TauriMockOptions {
videoEngineInstalled?: boolean
installedImages?: string[]
installedVideos?: string[]
+ imageInstallError?: string
}
/**
* Which OS the app should believe it is on. `isMacOS()` reads
@@ -404,7 +405,9 @@ export function tauriMockInit(opts: TauriMockOptions) {
record('__E2E_MLX_CALLS__', { cmd, id: m?.id })
return Promise.resolve({ ok: true, status: 'installing', id: m?.id })
case 'mlx_image_install_status': {
- const s = installStatus('image')
+ const s = installStatus('image', opts.mlx?.imageInstallError && slot.image !== null
+ ? { status: 'error', error: opts.mlx.imageInstallError, logs: [opts.mlx.imageInstallError] }
+ : undefined)
if (s.status === 'complete' && pendingImageId) {
mlx.images.add(pendingImageId)
pendingImageId = null
diff --git a/src-tauri/src/commands/mlx.rs b/src-tauri/src/commands/mlx.rs
index 0f4b5819..3c1a8890 100644
--- a/src-tauri/src/commands/mlx.rs
+++ b/src-tauri/src/commands/mlx.rs
@@ -546,17 +546,21 @@ fn image_model_is_installed(entry: &ImageCatalogEntry) -> bool {
/// at least one non-empty weights file. Scheduler/tokenizer entries are
/// config-only and skipped.
fn snapshot_is_complete(snap: &std::path::Path) -> bool {
+ snapshot_problem(snap).is_none()
+}
+
+fn snapshot_problem(snap: &std::path::Path) -> Option<String> {
let index = snap.join("model_index.json");
let Ok(raw) = std::fs::read_to_string(&index) else {
- return false;
+ return Some("model_index.json is missing or unreadable".into());
};
let Ok(json) = serde_json::from_str::<Value>(&raw) else {
- return false;
+ return Some("model_index.json contains invalid JSON".into());
};
let Some(map) = json.as_object() else {
- return false;
+ return Some("model_index.json must contain an object".into());
};
- map.iter()
+ for (component, _) in map.iter()
.filter(|(k, _)| !k.starts_with('_'))
// Only real component references count: a ["lib", "Class"] pair.
// Manifests also carry scalars (requires_safety_checker: true) and
@@ -570,18 +574,46 @@ fn snapshot_is_complete(snap: &std::path::Path) -> bool {
|| class.contains("Processor")
|| class.contains("FeatureExtractor"))
})
- .all(|(component, _)| {
- let dir = snap.join(component);
- let Ok(read) = std::fs::read_dir(&dir) else {
- return false;
- };
- read.flatten().any(|f| {
- let p = f.path();
- let ext = p.extension().and_then(|e| e.to_str()).unwrap_or("");
- (ext == "safetensors" || ext == "bin")
- && f.metadata().map(|m| m.len() > 0).unwrap_or(false)
- })
- })
+ {
+ // Reject traversal, platform separators, control characters and alternate streams.
+ if component.is_empty()
+ || !component.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-')
+ {
+ return Some("model_index.json contains an invalid component path".into());
+ }
+ let dir = snap.join(component);
+ let Ok(read) = std::fs::read_dir(&dir) else {
+ return Some(format!("{component}/ is missing or unreadable"));
+ };
+ let has_weights = read.flatten().any(|f| {
+ let p = f.path();
+ let ext = p.extension().and_then(|e| e.to_str()).unwrap_or("");
+ (ext == "safetensors" || ext == "bin")
+ && f.metadata().map(|m| m.is_file() && m.len() > 0).unwrap_or(false)
+ });
+ if !has_weights {
+ return Some(format!("{component}/ has no readable, non-empty .safetensors or .bin weights file"));
+ }
+ }
+ None
+}
+
+fn image_model_incomplete_message(entry: &ImageCatalogEntry) -> String {
+ snapshot_cache_incomplete_message(&image_model_cache_dir(entry.repo).join("snapshots"))
+}
+
+fn snapshot_cache_incomplete_message(snapshots: &std::path::Path) -> String {
+ let mut paths: Vec<_> = std::fs::read_dir(snapshots)
+ .into_iter()
+ .flatten()
+ .flatten()
+ .map(|entry| entry.path())
+ .filter(|path| path.is_dir())
+ .collect();
+ paths.sort();
+ let detail = paths.iter().find_map(|path| snapshot_problem(path))
+ .unwrap_or_else(|| "no readable model snapshot was found".into());
+ format!("Model installation did not finish: {detail}. Retry the download to repair the missing files.")
}
pub fn mlx_image_models(_state: &AppState, _args: &Value) -> CmdResult {
@@ -679,7 +711,7 @@ pub fn mlx_image_install_model(state: &AppState, args: &Value) -> CmdResult {
if let Err(e) = crate::commands::video::run_streamed(&slot2, &mut cmd) {
slot2.fail(e);
} else if !image_model_is_installed(&entry2) {
- slot2.fail("download finished but the model snapshot is incomplete");
+ slot2.fail(image_model_incomplete_message(&entry2));
} else {
slot2.complete(format!("{} installed", entry2.id));
}
@@ -1016,6 +1048,49 @@ mod tests {
let _ = std::fs::remove_dir_all(&snap);
}
+ #[test]
+ fn snapshot_diagnostic_names_manifest_and_missing_component() {
+ let temp = tempfile::tempdir().unwrap();
+ let snap = temp.path();
+ assert_eq!(snapshot_problem(snap).as_deref(), Some("model_index.json is missing or unreadable"));
+ std::fs::write(snap.join("model_index.json"), "{").unwrap();
+ assert_eq!(snapshot_problem(snap).as_deref(), Some("model_index.json contains invalid JSON"));
+ std::fs::write(snap.join("model_index.json"), "[]").unwrap();
+ assert_eq!(snapshot_problem(snap).as_deref(), Some("model_index.json must contain an object"));
+ std::fs::write(snap.join("model_index.json"), r#"{"unet":["diffusers","UNet2DConditionModel"]}"#).unwrap();
+ assert_eq!(snapshot_problem(snap).as_deref(), Some("unet/ is missing or unreadable"));
+ std::fs::create_dir(snap.join("unet")).unwrap();
+ std::fs::create_dir(snap.join("unet/fake.safetensors")).unwrap();
+ assert_eq!(snapshot_problem(snap).as_deref(), Some("unet/ has no readable, non-empty .safetensors or .bin weights file"));
+ std::fs::write(snap.join("unet/model.safetensors"), b"").unwrap();
+ assert!(snapshot_problem(snap).is_some());
+ std::fs::write(snap.join("unet/model.safetensors"), b"fixture").unwrap();
+ assert_eq!(snapshot_problem(snap), None);
+ }
+
+ #[test]
+ fn snapshot_diagnostic_rejects_manifest_path_traversal_without_echoing_it() {
+ let temp = tempfile::tempdir().unwrap();
+ for component in ["../outside", "..\\outside", "/outside", "a/b", "a\\b", "line\nbreak", "a:stream", ".. "] {
+ let manifest = json!({component: ["diffusers", "UNet2DConditionModel"]});
+ std::fs::write(temp.path().join("model_index.json"), manifest.to_string()).unwrap();
+ assert_eq!(snapshot_problem(temp.path()).as_deref(), Some("model_index.json contains an invalid component path"));
+ assert!(!snapshot_is_complete(temp.path()));
+ }
+ }
+
+ #[test]
+ fn snapshot_cache_diagnostic_reaches_the_install_error_without_private_paths() {
+ let temp = tempfile::tempdir().unwrap();
+ assert_eq!(snapshot_cache_incomplete_message(temp.path()),
+ "Model installation did not finish: no readable model snapshot was found. Retry the download to repair the missing files.");
+ std::fs::create_dir(temp.path().join("revision")).unwrap();
+ let message = snapshot_cache_incomplete_message(temp.path());
+ assert_eq!(message,
+ "Model installation did not finish: model_index.json is missing or unreadable. Retry the download to repair the missing files.");
+ assert!(!message.contains(temp.path().to_str().unwrap()));
+ }
+
#[test]
fn mlx_root_lives_under_data_dir() {
let r = mlx_root();