{"record":{"id":"c72d4f7bf4eb5058","repo":"clockworklabs/SpacetimeDB","slug":"failed-to-look-up-materialized-view-args-for-view","errorCode":null,"errorMessage":"failed to look up materialized view args for view {}","messagePattern":"failed to look up materialized view args for view (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/core/src/host/wasmtime/wasm_instance_env.rs","lineNumber":1827,"sourceCode":"\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;\n                let view_name = &resolved.view_name;\n                let fn_ptr = resolved.global_fn_ptr;\n                let sender = tx\n                    .as_ref()\n                    .expect(\"procedure tx missing while looking up refreshed view args\")\n                    .view_instance_args(&view_call)\n                    .ok_or_else(|| {\n                        anyhow!(\n                            \"failed to look up materialized view args for view {}\",\n                            view_call.view_id\n                        )\n                    })?\n                    .sender();\n\n                let current_tx = tx.take().expect(\"procedure tx missing during view refresh\");\n                let (next_tx, call_result) = tx_slot.set(current_tx, || {\n                    Self::call_view(caller, &view_call, view_name, fn_ptr, sender)\n                });\n                tx = Some(next_tx);\n                let return_data = call_result?;\n\n                let typespace = resolved.owning_def.typespace();\n                let row_product_type = typespace\n                    .resolve(view_def.product_type_ref)\n                    .resolve_refs()?\n                    .into_product()","sourceCodeStart":1809,"sourceCodeEnd":1845,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/core/src/host/wasmtime/wasm_instance_env.rs#L1809-L1845","documentation":"While refreshing views during a procedure commit, the transaction's views_for_refresh queue lists a view instance, but tx.view_instance_args returns None - the st_view-instance row storing the materialized view's arguments (the sender identity) is missing. The refresh loop cannot reconstruct the view call, so the whole procedure transaction is rolled back.","triggerScenarios":"A materialized-view subscription being deleted (unsubscribe or client-disconnect cleanup) concurrently with a reducer commit that queued the same view for refresh; or missing/corrupted view instance metadata.","commonSituations":"Clients unsubscribing or disconnecting while reducers write to subscribed tables; partial metadata left by interrupted publishes.","solutions":["Retry the mutating call once - transient races resolve after subscription state settles","If persistent, let subscriptions quiesce (clients finish unsubscribing) before running reducers that touch the affected views","Republish the module to rebuild view instance metadata and report the race with logs"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match commit_result {\n    Err(e) if e.to_string().contains(\"failed to look up materialized view args\") => {\n        // Subscription state changed mid-commit; retry the mutation after a short delay\n    }\n    other => other,\n}","preventionTips":["Complete subscribe/unsubscribe operations before running reducers that touch the same views","Keep reducers idempotent to make retries safe","Report persistent occurrences - the args row should exist for every queued refresh"],"tags":["spacetimedb","views","materialized-views","race-condition"],"backgroundTag":"materialized-view-metadata-missing","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}