{"record":{"id":"0daba6b599f50245","repo":"zeroclaw-labs/zeroclaw","slug":"wasm-execution-error-in-module-name-e","errorCode":null,"errorMessage":"WASM execution error in '{module_name}': {e}","messagePattern":"WASM execution error in '(.+?)': (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-runtime/src/platform/wasm.rs","lineNumber":209,"sourceCode":"\n        // Execute with fuel accounting\n        let fuel_before = store.get_fuel().unwrap_or(0);\n        let exit_code = match run_fn.call(&mut store, ()) {\n            Ok(code) => code,\n            Err(e) => {\n                // Check if we ran out of fuel (infinite loop protection)\n                let fuel_after = store.get_fuel().unwrap_or(0);\n                if fuel_after == 0 && fuel > 0 {\n                    return Ok(WasmExecutionResult {\n                        stdout: String::new(),\n                        stderr: format!(\n                            \"WASM module '{module_name}' exceeded fuel limit ({fuel} ticks) — likely an infinite loop\"\n                        ),\n                        exit_code: -1,\n                        fuel_consumed: fuel,\n                    });\n                }\n                bail!(\"WASM execution error in '{module_name}': {e}\");\n            }\n        };\n        let fuel_after = store.get_fuel().unwrap_or(0);\n        let fuel_consumed = fuel_before.saturating_sub(fuel_after);\n\n        Ok(WasmExecutionResult {\n            stdout: String::new(),  // No WASI stdout yet — pure computation\n            stderr: String::new(),\n            exit_code,\n            fuel_consumed,\n        })\n    }\n\n    /// Stub for when the `runtime-wasm` feature is not enabled.\n    #[cfg(not(feature = \"runtime-wasm\"))]\n    pub fn execute_module(\n        &self,\n        module_name: &str,","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-runtime/src/platform/wasm.rs#L191-L227","documentation":"execute_module wraps instantiation and execution of the compiled module; when Wasmer returns a runtime error that is not fuel exhaustion (fuel exhaustion is detected separately and reported with its own message), it bails wrapping the underlying Wasmer error text. Typical underlying causes: unreachable trap (panic/abort in the module), out-of-bounds memory access, failed instantiation (missing or mismatched host imports), or memory growth beyond memory_limit_mb trapping.","triggerScenarios":"A bug in the wasm tool causing a Rust panic (unreachable) or OOB access; host-function import ABI mismatch after upgrading the tool or the host; module trying to grow memory past memory_limit_mb; division by zero or failed start function during instantiation.","commonSituations":"Tool compiled against a different zeroclaw host-API version than the runtime running it; untested edge-case inputs reaching a panic path; memory-heavy modules hitting the configured cap; wasm32-unknown-unknown builds panicking without unwinding (abort → trap).","solutions":["Read the wrapped Wasmer error {e}: it names the concrete trap (out of bounds memory access, unreachable, etc.)","Reproduce outside ZeroClaw: wasmer run tools/wasm/module.wasm with the same inputs, or add a host-shim test harness","If imports fail at instantiation, rebuild the module against the host API version matching this runtime","If it is memory growth trapping, raise runtime.wasm.memory_limit_mb (within the 4096 cap) or reduce the module's allocation","For panics in the tool, build with panic strategy and overflow checks appropriate for production and fix the panic path"],"exampleFix":"// before: raw anyhow error surfacing\nlet result = platform.execute_module(\"tool\", &ws, &caps).await?;\n\n// after: capture context, log fuel, degrade gracefully\nmatch platform.execute_module(\"tool\", &ws, &caps) {\n    Ok(r) => { tracing::info!(\"fuel used: {}\", r.fuel_consumed); }\n    Err(e) => { tracing::error!(\"tool failed: {e}\"); /* mark tool unhealthy, skip */ }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match platform.execute_module(module_name, &ws, &caps) {\n    Ok(res) => { tracing::debug!(\"fuel: {}\", res.fuel_consumed); res }\n    Err(e) => {\n        let msg = e.to_string();\n        if msg.contains(\"exceeded fuel limit\") {\n            // infinite loop in the module: fix the module or lower fuel; do not blind-retry\n        } else if msg.contains(\"WASM execution error\") {\n            // trap: log the wrapped Wasmer cause, mark the tool unhealthy, degrade gracefully\n        }\n        return Err(e);\n    }\n}","preventionTips":["Test wasm tools against the same host-API version they will run under (import ABI drift traps at instantiation)","Run new modules once in a sandbox harness (wasmer CLI) before registering them as tools","Keep fuel limits on so runaway loops surface as the dedicated fuel error instead of hangs","Log fuel_consumed on success to baseline normal tool cost"],"tags":["rust","zeroclaw","wasm","wasmer","trap","runtime-crash"],"backgroundTag":"wasm-runtime-trap","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}