{"record":{"id":"2da8e1a350731efa","repo":"clockworklabs/SpacetimeDB","slug":"error-looking-up-name-for-truncated-table-table-i","errorCode":null,"errorMessage":"Error looking up name for truncated table {table_id:?}","messagePattern":"Error looking up name for truncated table (.+?)","errorType":"exception","errorClass":"ReplayError","httpStatus":null,"severity":"critical","filePath":"crates/datastore/src/locking_tx_datastore/replay.rs","lineNumber":362,"sourceCode":"        // and therefore has performance implications and must not be disabled.\n        DB_METRICS\n            .rdb_num_table_rows\n            .with_label_values(self.database_identity, &table_id.into(), &table_name)\n            .dec();\n\n        Ok(row)\n    }\n\n    fn visit_truncate(&mut self, table_id: TableId) -> std::result::Result<(), Self::Error> {\n        let table_name = match self.committed_state.schema_for_table(table_id) {\n            // TODO: avoid clone\n            Ok(schema) => schema.table_name.clone(),\n\n            Err(_) => match self.dropped_table_names.remove(&table_id) {\n                Some(name) => name,\n                _ => {\n                    return self\n                        .process_error(anyhow!(\"Error looking up name for truncated table {table_id:?}\").into());\n                }\n            },\n        };\n\n        if let Err(e) = self.committed_state.replay_truncate(table_id).with_context(|| {\n            format!(\n                \"Error truncating table {:?} during transaction {:?} playback\",\n                table_id, self.committed_state.next_tx_offset\n            )\n        }) {\n            self.process_error(e.into())?;\n        }\n\n        // NOTE: the `rdb_num_table_rows` metric is used by the query optimizer,\n        // and therefore has performance implications and must not be disabled.\n        DB_METRICS\n            .rdb_num_table_rows\n            .with_label_values(self.database_identity, &table_id.into(), &table_name)","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/datastore/src/locking_tx_datastore/replay.rs#L344-L380","documentation":"While replaying the commitlog at database open, visit_truncate hit a TRUNCATE entry for a table whose schema is absent from committed state and whose name was not recorded in dropped_table_names. Without the st_table row there is no way to identify the table, so replay, and therefore database open, fails.","triggerScenarios":"Replaying a commitlog in which the st_table row for a truncated table was dropped or never written in the order replay expects; a truncated or corrupted commitlog segment; a log produced by a spacetimedb version whose system-table write order differs.","commonSituations":"Reopening a data directory after a crash mid-schema-change (drop-then-truncate sequences); upgrading spacetimedb and replaying old logs; partially copied or restored database files.","solutions":["Restore the database from a clean snapshot/backup instead of replaying the damaged log","Reopen with the exact spacetimedb version that wrote the commitlog, then re-upgrade","If the data is disposable, recreate the database","Preserve the commitlog and report the issue — truncate replay should not lose the st_table row"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"Catch the error from RelationalDB::open / replay, classify it as commitlog corruption (look for the truncate-name-lookup message), then fall back to the most recent snapshot: restore it and replay only the post-snapshot segments. Surface a distinct 'database unrecoverable, snapshot restored' status to operators.","preventionTips":["Take periodic snapshots so replay never starts from a damaged baseline","Shut the database down gracefully before upgrades or disk moves","Test the upgrade path on a copy of production data before switching over","Keep writer and reader nodes on the same spacetimedb version"],"tags":["rust","spacetimedb","commitlog","replay","truncate","corruption"],"backgroundTag":"wal-replay-failure","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}