{"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":"WasmError","httpStatus":null,"severity":"error","filePath":"crates/core/src/host/wasmtime/wasm_instance_env.rs","lineNumber":1785,"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":1767,"sourceCodeEnd":1803,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/core/src/host/wasmtime/wasm_instance_env.rs#L1767-L1803","documentation":"While refreshing a materialized view inside a procedure, the host looks up the view instance's arguments (its sender) via tx.view_instance_args(view_call). A None return means no stored instance/args row exists for this view call in the transaction's view of the state — the subscription or instance this refresh was triggered for is gone from the catalog.","triggerScenarios":"A materialized view instance (subscription) is dropped concurrently while a procedure triggers view refreshes, so its args row disappears mid-flight; or the view-instance catalog is missing rows the module expects after an inconsistent publish or a bookkeeping race.","commonSituations":"Clients unsubscribing from materialized views while writers and procedures run against those views; races between subscription lifecycle and procedure execution under heavy traffic; state left inconsistent after a failed update.","solutions":["Retry the procedure — if the instance was legitimately removed the refresh may no longer apply, or the race has passed.","Quiesce materialized-view subscriptions (stop writers) before teardown or maintenance procedures that refresh them.","Republish to rebuild view-instance state if the catalog is suspected inconsistent.","If it persists with stable subscriptions, report it with reproduction steps — it can indicate a host bookkeeping race."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// A missing view-instance row during refresh is usually a lifecycle race — retry once\nmatch result {\n    Err(e) if e.to_string().contains(\"materialized view args\") => {\n        retry_procedure_once().await\n    }\n    other => other,\n}","preventionTips":["Quiesce materialized-view subscriptions before heavy write bursts or maintenance procedures.","Avoid unsubscribing views while procedures that refresh them are in flight.","Republish to rebuild view-instance state after a suspected inconsistent publish."],"tags":["materialized-views","procedures","subscription-lifecycle","race-condition"],"backgroundTag":"view-not-found","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}