{"record":{"id":"88fa797debb9bdc9","repo":"clockworklabs/SpacetimeDB","slug":"module-definition-is-unavailable-while-committing","errorCode":null,"errorMessage":"module definition is unavailable while committing a procedure transaction","messagePattern":"module definition is unavailable while committing a procedure transaction","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/core/src/host/wasmtime/wasm_instance_env.rs","lineNumber":1759,"sourceCode":"                    .commit_procedure_tx(tx)\n                    .map_err(WasmError::from)?;\n                Ok(0u16.into())\n            })();\n            res.or_else(|err| Self::convert_wasm_result(AbiCall::ProcedureCommitMutTransaction, err))\n        })\n    }\n\n    /// Refresh all views made stale by a procedure `tx`.\n    ///\n    /// This runs each pending view call in the same mutable transaction and writes the refreshed rows\n    /// into the corresponding backing view tables. If any step fails (missing metadata, view execution,\n    /// row decoding, SQL execution, or materialization), this method rolls back `tx` and returns an error.\n    ///\n    /// On success, it returns the same transaction handle so the caller can commit it.\n    fn refresh_views<'a>(caller: &mut Caller<'a, Self>, tx: MutTxId) -> Result<MutTxId, WasmError> {\n        let Some(module_def) = caller.data().module_def.clone() else {\n            caller.data_mut().instance_env.rollback_procedure_tx(tx);\n            return Err(WasmError::Wasm(anyhow!(\n                \"module definition is unavailable while committing a procedure transaction\"\n            )));\n        };\n\n        let views_for_refresh = tx.views_for_refresh().cloned().collect::<Vec<_>>();\n        let mut tx = Some(tx);\n        let mut tx_slot = caller.data().instance_env.tx.clone();\n\n        for view_call in views_for_refresh {\n            let res: anyhow::Result<()> = (|| {\n                let resolved = crate::host::module_host::resolve_view_for_refresh(\n                    tx.as_ref().expect(\"procedure tx missing during view refresh\"),\n                    &module_def,\n                    &view_call,\n                )?;\n\n                let table_id = resolved.table_id;\n                let view_def = resolved.view_def;","sourceCodeStart":1741,"sourceCodeEnd":1777,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/core/src/host/wasmtime/wasm_instance_env.rs#L1741-L1777","documentation":"During WasmInstanceEnv::refresh_views, which runs while committing a procedure (reducer) transaction, caller.data().module_def was None. The instance env must hold the module definition to resolve views for refresh; its absence means instance state was cleared (e.g. during module update or teardown) while a procedure transaction was still committing. The transaction is rolled back and the error returned.","triggerScenarios":"A module update or instance teardown racing with an in-flight reducer commit on the wasmtime instance: the module def is swapped out before commit_procedure_tx finishes.","commonSituations":"Publishing a new module version while reducers are executing under load; node restarts during hot-swap; lifecycle bugs in the host.","solutions":["Retry the reducer call once the module update completes - the transaction was rolled back safely, so no partial state was written","Drain or quiesce reducer traffic before publishing module updates","If it recurs outside update windows, capture server logs and report it - module_def should never be missing mid-commit"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match commit_result {\n    Err(e) if e.to_string().contains(\"module definition is unavailable\") => {\n        // Tx was rolled back safely: wait for the module update to settle, then retry the reducer once\n    }\n    other => other,\n}","preventionTips":["Drain or pause reducer traffic while publishing module updates","Make reducers idempotent so a post-update retry is safe","Alert on this error outside maintenance windows - it signals a lifecycle race"],"tags":["spacetimedb","wasmtime","module-lifecycle","transaction-rollback"],"backgroundTag":"module-state-inconsistency","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}