{"record":{"id":"601ac44cd569c1b9","repo":"cjpais/Handy","slug":"failed-to-create-vad-e","errorCode":null,"errorMessage":"Failed to create VAD: {e}","messagePattern":"Failed to create VAD: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/audio_toolkit/vad/silero.rs","lineNumber":26,"sourceCode":"\nconst SILERO_FRAME_MS: u32 = 30;\nconst SILERO_FRAME_SAMPLES: usize =\n    (constants::WHISPER_SAMPLE_RATE * SILERO_FRAME_MS / 1000) as usize;\n\npub struct SileroVad {\n    engine: Vad,\n    threshold: f32,\n}\n\nimpl SileroVad {\n    pub fn new<P: AsRef<Path>>(model_path: P, threshold: f32) -> Result<Self> {\n        if !(0.0..=1.0).contains(&threshold) {\n            anyhow::bail!(\"threshold must be between 0.0 and 1.0\");\n        }\n\n        Ok(Self {\n            engine: Vad::new(&model_path, constants::WHISPER_SAMPLE_RATE as usize)\n                .map_err(|e| anyhow::anyhow!(\"Failed to create VAD: {e}\"))?,\n            threshold,\n        })\n    }\n}\n\nimpl VoiceActivityDetector for SileroVad {\n    fn push_frame<'a>(&'a mut self, frame: &'a [f32]) -> Result<VadFrame<'a>> {\n        if frame.len() != SILERO_FRAME_SAMPLES {\n            anyhow::bail!(\n                \"expected {SILERO_FRAME_SAMPLES} samples, got {}\",\n                frame.len()\n            );\n        }\n\n        let result = self\n            .engine\n            .compute(frame)\n            .map_err(|e| anyhow::anyhow!(\"Silero VAD error: {e}\"))?;","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/cjpais/Handy/blob/98a4d80cce8ad41efec2a419b59d9e81229a35d7/src-tauri/src/audio_toolkit/vad/silero.rs#L8-L44","documentation":"Wraps Vad::new from the vad-rs crate, which creates an ONNX Runtime inference session for the Silero VAD model at the given path at 16 kHz (constants::WHISPER_SAMPLE_RATE). It fails when the model file is missing or unreadable, is not a valid ONNX file, or the ONNX Runtime backend cannot start (missing/incompatible native libraries).","triggerScenarios":"resources/models/silero_vad_v4.onnx absent because the dev setup step (curl per AGENTS.md/BUILD.md) was skipped; the file is truncated or corrupt; the resolved path points at the wrong location; the onnxruntime dynamic library fails to load (glibc/ABI mismatch on Linux, missing dylib on macOS).","commonSituations":"Fresh clone without downloading the VAD model; resource not listed in the bundle so production builds lack the file; OS/toolchain upgrade breaking the onnxruntime native lib; file copied with wrong permissions.","solutions":["Verify the model file exists and is non-trivial (ls -l src-tauri/resources/models/silero_vad_v4.onnx)","Re-download it: curl -o src-tauri/resources/models/silero_vad_v4.onnx https://blob.handy.computer/silero_vad_v4.onnx","Confirm the resource is bundled (resources entry in tauri.conf.json) so resolve() finds it in packaged builds","If the file is fine, check the ONNX Runtime native libs (ldd / otool -L on the onnxruntime artifact)"],"exampleFix":"// before\nlet silero = SileroVad::new(vad_path, threshold)?; // opaque failure\n\n// after — fail with an actionable message before touching ONNX\nlet meta = std::fs::metadata(&vad_path)\n    .map_err(|e| anyhow::anyhow!(\"VAD model missing at {vad_path:?}: {e}\"))?;\nif meta.len() < 1024 {\n    anyhow::bail!(\"VAD model at {vad_path:?} looks truncated ({} bytes)\", meta.len());\n}\nlet silero = SileroVad::new(&vad_path, threshold)?;","handlingStrategy":"validation","validationCode":"// cheap pre-flight before creating the engine\nlet meta = std::fs::metadata(&vad_path)\n    .map_err(|e| anyhow::anyhow!(\"VAD model not found at {vad_path:?}: {e}\"))?;\nif meta.len() < 1_000 {\n    anyhow::bail!(\"VAD model at {vad_path:?} is only {} bytes — re-download it\", meta.len());\n}","typeGuard":null,"tryCatchPattern":"let silero = match SileroVad::new(&vad_path, threshold) {\n    Ok(v) => v,\n    Err(e) => {\n        // {e} already wraps the inner Vad::new cause; surface it with the path\n        anyhow::bail!(\"cannot start VAD from {vad_path:?}: {e:#}\");\n    }\n};","preventionTips":["Download silero_vad_v4.onnx as part of the dev setup script, not manually","Assert the resource exists during app setup (preload_vad) so failure surfaces at startup, not mid-recording","Verify bundle resources include the model before shipping release builds"],"tags":["rust","vad","onnx","model-file-missing","runtime-init"],"backgroundTag":"onnx-model-load-failed","analyzedSha":"98a4d80cce8ad41efec2a419b59d9e81229a35d7","analyzedAt":"2026-08-16T20:58:09.966Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}