{"record":{"id":"df876d6f3fb35b6d","repo":"astrid-runtime/astrid","slug":"failed-to-create-wasmtime-engine-for-hooks","errorCode":null,"errorMessage":"failed to create wasmtime engine for hooks","messagePattern":"failed to create wasmtime engine for hooks","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/astrid-hooks/src/handler/wasm.rs","lineNumber":78,"sourceCode":"        http.default_timeout_secs,\n        http.stream_connect_timeout_secs,\n        http.stream_read_timeout_secs,\n        http.header_deadline_secs,\n        http.max_redirects,\n        http.max_concurrent_streams,\n        http.max_response_bytes,\n    )\n}\n\n/// Build the hook engine with Astrid's explicit guest-feature boundary.\nfn build_hook_engine() -> wasmtime::Engine {\n    let mut wt_config = wasmtime::Config::new();\n    wt_config\n        .wasm_component_model(true)\n        .wasm_gc(false)\n        .wasm_exceptions(false)\n        .epoch_interruption(true);\n    wasmtime::Engine::new(&wt_config).expect(\"failed to create wasmtime engine for hooks\")\n}\n\n/// Handler for WASM components.\n///\n/// Lazily compiles the WASM component on first invocation and caches the\n/// compiled [`Component`] (immutable, thread-safe) for subsequent calls.\n/// A fresh [`Store`] is created for each invocation.\npub(crate) struct WasmHandler {\n    /// Cached wasmtime engine (shared across all components).\n    engine: wasmtime::Engine,\n    /// Cached compiled components (lazy-loaded, keyed by module path).\n    cached_components: Mutex<HashMap<String, Arc<Component>>>,\n    /// Configuration for WASM execution.\n    config: WasmConfig,\n    /// KV store for hook state (scoped to `hook:wasm`).\n    kv: Option<ScopedKvStore>,\n    /// Workspace root for file operations.\n    workspace_root: PathBuf,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-hooks/src/handler/wasm.rs#L60-L96","documentation":"`build_hook_engine` constructs the shared `wasmtime::Engine` for WASM hooks with the component model enabled, GC/exceptions disabled, and epoch interruption on. It panics if wasmtime cannot create the engine — an unrecoverable misconfiguration, since every hook handler depends on this engine.","triggerScenarios":"Calling `wasmtime::Engine::new(&wt_config)` with `wasm_component_model(true)` when the linked wasmtime build lacks component-model support (feature flags off), or when conflicting config options are set (e.g. GC disabled incompatibly with the component model on some wasmtime versions).","commonSituations":"Mismatches between Cargo feature flags and runtime config after a wasmtime version upgrade, a wasmtime build compiled without the `component-model` feature, or mutually exclusive config options introduced by a new wasmtime release.","solutions":["Enable the required wasmtime Cargo features (e.g. `component-model`) so `wasm_component_model(true)` is supported.","Check wasmtime release notes for config-option conflicts; remove options the new version rejects.","Downgrade/upgrade the wasmtime crate to a version compatible with this configuration.","Replace the expect with a `Result` return so host startup reports the underlying wasmtime error message."],"exampleFix":"// before\nwasmtime::Engine::new(&wt_config).expect(\"failed to create wasmtime engine for hooks\")\n// after\nwasmtime::Engine::new(&wt_config)\n    .map_err(|e| HookError::EngineInit(format!(\"wasmtime engine init failed: {e}\")))?","handlingStrategy":"try-catch","validationCode":"// Rust (build check): ensure the component-model feature is enabled\ncargo tree -e features | grep -q component-model || echo \"wasmtime component-model feature missing\"","typeGuard":null,"tryCatchPattern":"// Rust: propagate engine init failure to callers\nlet engine = wasmtime::Engine::new(&wt_config)\n    .map_err(|e| HookError::EngineInit(e.to_string()))?;","preventionTips":["Pin wasmtime features in Cargo.toml and verify them in CI builds.","Re-check Config options after every wasmtime upgrade against release notes.","Add a smoke test that builds the engine at startup, not on first hook invocation.","Prefer Result-returning constructors over expect for engine creation."],"tags":["rust","wasm","wasmtime","initialization","config"],"backgroundTag":"module-init-failed","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}