{"record":{"id":"79fef556f32ee6f0","repo":"clockworklabs/SpacetimeDB","slug":"module-exceeds-publish-size-limit","errorCode":null,"errorMessage":"Module exceeds publish size limit","messagePattern":"Module exceeds publish size limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/schema_extract.rs","lineNumber":51,"sourceCode":"\nfn inspect_blocking(extractor: PathBuf, bytes: Vec<u8>, host_type: String) -> anyhow::Result<ModuleDef> {\n    std::thread::spawn(move || {\n        tokio::runtime::Builder::new_current_thread()\n            .enable_all()\n            .build()?\n            .block_on(inspect_with(extractor, bytes, host_type, INSPECT_TIMEOUT))\n    })\n    .join()\n    .map_err(|_| anyhow::anyhow!(\"Local module inspection thread failed\"))?\n}\n\npub(crate) fn read_program(path: &std::path::Path) -> anyhow::Result<Vec<u8>> {\n    use std::io::Read;\n    let mut bytes = Vec::new();\n    std::fs::File::open(path)?\n        .take(spacetimedb_client_api_messages::publish::MAX_MODULE_BYTES as u64 + 1)\n        .read_to_end(&mut bytes)?;\n    ensure!(\n        bytes.len() <= spacetimedb_client_api_messages::publish::MAX_MODULE_BYTES,\n        \"Module exceeds publish size limit\"\n    );\n    Ok(bytes)\n}\n\nconst MAX_SCHEMA_BYTES: u64 = 16 * 1024 * 1024;\nconst INSPECT_TIMEOUT: Duration = Duration::from_secs(60);\n\n/// Inspect exactly the artifact bytes that will be uploaded. The private copy\n/// prevents path replacement between inspection and upload, including --bin-path.\n/// This invokes only local extraction, never a server or a saved CLI context.\npub(crate) async fn inspect(program: &[u8], host_type: &str) -> anyhow::Result<ModuleDef> {\n    let extractor = extractor_path()?;\n    inspect_with(extractor, program.to_vec(), host_type.to_owned(), INSPECT_TIMEOUT).await\n}\n\npub(crate) async fn inspect_with(","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/schema_extract.rs#L33-L69","documentation":"The CLI's schema extraction reads a module file from disk and enforces the same publish size limit (`MAX_MODULE_BYTES`) that servers enforce, reading at most limit+1 bytes to detect overflow. It throws when the module binary on disk is larger than the maximum allowed publish size. This gives early, local feedback before any server interaction.","triggerScenarios":"Calling `read_program(path)` (via `SchemaExtract::from_path`) on a module `.wasm` whose file size exceeds `spacetimedb_client_api_messages::publish::MAX_MODULE_BYTES`.","commonSituations":"Building the module with debug symbols / unstripped wasm, accidentally bundling large assets into the wasm binary, or pointing the extractor at the wrong (larger) artifact file.","solutions":["Build the module in release mode and strip debug info (e.g. `wasm-snip`, `wasm-opt -Oz`, or `strip`) to shrink the wasm below the limit.","Check the file size first (`ls -lh target/wasm32-unknown-unknown/release/*.wasm`) and confirm you are extracting from the intended artifact.","Remove or externalize large embedded data (assets, static strings) from the module.","If the module genuinely needs more space, check whether the deployment's `MAX_MODULE_BYTES` permits it — the CLI enforces the same constant, so the module must shrink."],"exampleFix":"// before: building with debug info\nwasm32-unknown-unknown/debug/my_module.wasm  (> MAX_MODULE_BYTES)\n// after\ncargo build --release --target wasm32-unknown-unknown\nwasm-opt -Oz --strip-debug my_module.wasm -o my_module.wasm  # now <= MAX_MODULE_BYTES","handlingStrategy":"validation","validationCode":"use spacetimedb_client_api_messages::publish::MAX_MODULE_BYTES;\nlet size = std::fs::metadata(path)?.len();\nif size > MAX_MODULE_BYTES as u64 {\n    return Err(anyhow!(\"module {} is {} bytes, limit is {}\", path.display(), size, MAX_MODULE_BYTES));\n}","typeGuard":null,"tryCatchPattern":"match read_program(&path) {\n    Ok(bytes) => proceed(bytes),\n    Err(e) if e.to_string().contains(\"publish size limit\") => shrink_module_and_retry(),\n    Err(e) => return Err(e),\n}","preventionTips":["Build modules in release mode and strip debug info","Check wasm artifact size in CI before publishing/extracting","Avoid embedding large assets in wasm binaries"],"tags":["rust","cli","file-size","wasm"],"backgroundTag":"payload-too-large","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}