{"record":{"id":"2bbaea1aa3cd8225","repo":"zeroclaw-labs/zeroclaw","slug":"wasm-module-is-mb-exceeds-50-mb-safety-lim","errorCode":null,"errorMessage":"WASM module {} is {} MB — exceeds 50 MB safety limit","messagePattern":"WASM module (.+?) is (.+?) MB — exceeds 50 MB safety limit","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-runtime/src/platform/wasm.rs","lineNumber":148,"sourceCode":"        // Resolve module path\n        let tools_path = self.tools_dir(workspace_dir);\n        let module_path = tools_path.join(format!(\"{module_name}.wasm\"));\n\n        if !module_path.exists() {\n            bail!(\n                \"WASM module not found: {} (looked in {})\",\n                module_name,\n                tools_path.display()\n            );\n        }\n\n        // Read module bytes\n        let wasm_bytes = std::fs::read(&module_path)\n            .with_context(|| format!(\"Failed to read WASM module: {}\", module_path.display().to_string()))?;\n\n        // Validate module size (sanity check)\n        if wasm_bytes.len() > 50 * 1024 * 1024 {\n            bail!(\n                \"WASM module {} is {} MB — exceeds 50 MB safety limit\",\n                module_name,\n                wasm_bytes.len() / (1024 * 1024)\n            );\n        }\n\n        // Configure engine with fuel metering\n        let mut engine_config = wasmi::Config::default();\n        engine_config.consume_fuel(true);\n        let engine = Engine::new(&engine_config);\n\n        // Parse and validate module\n        let module = Module::new(&engine, &wasm_bytes[..])\n            .with_context(|| format!(\"Failed to parse WASM module: {module_name}\"))?;\n\n        // Create store with fuel budget\n        let mut store = Store::new(&engine, ());\n        let fuel = self.effective_fuel(caps);","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-runtime/src/platform/wasm.rs#L130-L166","documentation":"After reading the module bytes, execute_module enforces a 50 MB sanity limit on the file size before compiling. Modules anywhere near this size are almost always the wrong artifact — a debug build with DWARF, a bundle with embedded assets, or a non-WASM binary dropped in the tools dir — and compiling them wastes the memory budget guarded by memory_limit_mb.","triggerScenarios":"Placing an unstripped debug wasm build (with debug info) in the tools dir; embedding large assets (models, datasets) into the module at build time; accidentally pointing module_name at a large native binary or source map; compressed vs uncompressed mixups doubling size.","commonSituations":"Teams shipping dev builds to production; asset-heavy tools that inline data at compile time; CI artifacts that include debug sections by default.","solutions":["Strip and optimize: wasm-opt -Oz module.wasm -o module.wasm and/or wasm-strip module.wasm","Move large embedded assets out of the module and load them at runtime from the workspace","Verify the file is actually a WASM module (file module.wasm, or wasm-objdump -h) — not a native ELF or a .map file","If a legitimate module truly exceeds 50 MB, split it into smaller modules; the limit is a hard safety cap"],"exampleFix":"# before: 80 MB debug build\ncp target/wasm32-*/debug/tool.wasm tools/wasm/tool.wasm\n\n# after: ~2 MB release build, stripped\ncp target/wasm32-*/release/tool.wasm tools/wasm/tool.wasm\nwasm-opt -Oz tools/wasm/tool.wasm -o tools/wasm/tool.wasm\nwasm-strip tools/wasm/tool.wasm","handlingStrategy":"validation","validationCode":"const MAX_MODULE_BYTES: u64 = 50 * 1024 * 1024;\nlet meta = std::fs::metadata(&module_path)?;\nif meta.len() > MAX_MODULE_BYTES {\n    // reject early: likely wrong artifact (debug build / non-wasm file)\n}","typeGuard":null,"tryCatchPattern":"Err(e) if e.to_string().contains(\"exceeds 50 MB safety limit\") => {\n    // fix the artifact: wasm-opt -Oz + wasm-strip, or remove embedded assets; do not raise the limit\n}","preventionTips":["Ship only optimized, stripped release wasm builds; make stripping a CI step","Check the wasm magic bytes (\\0asm) and size in a pre-deploy lint","Keep assets outside modules and load at runtime"],"tags":["rust","zeroclaw","wasm","file-size","limits","build-artifacts"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}