aaif-goose/goose · critical

Failed to init llama backend: {}

Error message

Failed to init llama backend: {}

What it means

llama_cpp_2's LlamaBackend::init() failed with an error other than BackendAlreadyInitialized (which the surrounding runtime mutex makes unreachable here). In practice this means the llama.cpp backend library itself failed to initialize/load - missing or corrupt shared library, ABI/glibc mismatch, loader error - and the underlying LlamaCppError is appended. Local llama.cpp inference cannot start when this fires.

Source

Thrown at crates/goose-local-inference/src/llamacpp/mod.rs:361

pub(super) struct LlamaCppBackend {
    backend: LlamaBackend,
}

impl LlamaCppBackend {
    pub(super) fn new() -> Result<Self> {
        check_cpu_supports_local_inference()?;

        let backend = match LlamaBackend::init() {
            Ok(backend) => backend,
            Err(llama_cpp_2::LlamaCppError::BackendAlreadyInitialized) => {
                unreachable!(
                    "LlamaBackend already initialized but Weak was dead; \
                     the runtime mutex prevents concurrent re-init"
                )
            }
            Err(e) => {
                tracing::error!(error = %e, "failed to initialize local inference runtime");
                return Err(anyhow::anyhow!("Failed to init llama backend: {}", e));
            }
        };

        llama_cpp_2::send_logs_to_tracing(LogOptions::default());
        log_inference_backend_devices();

        Ok(Self { backend })
    }

    pub(super) fn llama_backend(&self) -> &LlamaBackend {
        &self.backend
    }

    fn init_mtmd_context(
        model: &LlamaModel,
        mmproj_path: &Option<PathBuf>,
        settings: &crate::local_model_registry::ModelSettings,
    ) -> Option<llama_cpp_2::mtmd::MtmdContext> {

View on GitHub (pinned to 3810898a74)

Solutions

  1. Reinstall goose to restore the bundled llama.cpp library
  2. Clear LD_LIBRARY_PATH / DYLD_INSERT_LIBRARIES interference and retry
  3. Read the appended LlamaCppError text: loader messages name the exact file or symbol that failed
  4. Fall back to a non-local provider while gathering the full error for a bug report
Defensive patterns

Strategy: fallback

Try / catch

match LlamaCppBackend::new() {
    Err(e) if e.to_string().starts_with("Failed to init llama backend") => {
        // capture the appended LlamaCppError, prompt a reinstall,
        // and switch the session to a non-local provider in the meantime
    }
    other => other,
}

Prevention

When it happens

Trigger: LlamaCppBackend::new() at first local-model use: corrupted install artifacts, an incompatible system loader forcing the wrong libllama, or LD_LIBRARY_PATH/DYLD_* injection breaking the bundled library load.

Common situations: Interrupted updates leaving a half-written library; mismatched glibc on older Linux distros; environment variables pointing at a different llama.cpp build; antivirus quarantining the .so/.dylib.

Related errors


AI-assisted analysis of aaif-goose/goose@3810898a74 (2026-08-16). Data as JSON: /api/errors/667ca71fe4d07c0f. Report an issue: GitHub.