{"record":{"id":"0753349c95b44155","repo":"clockworklabs/SpacetimeDB","slug":"precheck-failed-added-sequence-sequence-name-ha-075334","errorCode":null,"errorMessage":"Precheck failed: added sequence {sequence_name} has invalid max value","messagePattern":"Precheck failed: added sequence (.+?) has invalid max value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/engine/src/update.rs","lineNumber":248,"sourceCode":"                    .ok_or_else(|| {\n                        anyhow::anyhow!(\"Precheck failed: added sequence {sequence_name} refers to unknown column\")\n                    })?\n                    .ty\n                    .clone();\n\n                // Convert `SequenceDef` min/max to `AlgebraicValue`s of the correct type.\n                let min = ty\n                    .saturating_value_from_i128(sequence_def.min_value.unwrap_or(1))\n                    .ok_or_else(|| {\n                        anyhow::anyhow!(\"Precheck failed: added sequence {sequence_name} has invalid min value\")\n                    })?;\n\n                let max = match sequence_def.max_value {\n                    Some(max) => ty.saturating_value_from_i128(max),\n                    None => ty.saturating_value_from_i128(i128::MAX),\n                }\n                .ok_or_else(|| {\n                    anyhow::anyhow!(\"Precheck failed: added sequence {sequence_name} has invalid max value\")\n                })?;\n\n                let range = min..=max;\n                if stdb\n                    .iter_by_col_range_mut(tx, table_id, sequence_def.column, range)?\n                    .next()\n                    .is_some()\n                {\n                    anyhow::bail!(\"Precheck failed: added sequence {sequence_name} already has values in range\",);\n                }\n            }\n        }\n    }\n\n    log::info!(\"Running database update steps: {}\", stdb.database_identity());\n    let mut res = UpdateResult::Success;\n\n    for step in plan.steps {","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/engine/src/update.rs#L230-L266","documentation":"Auto-migrate precheck: converting the sequence's max value (explicit sequence_def.max_value, or i128::MAX when unset) into the sequenced column's type via saturating_value_from_i128 returned None, so the max is not representable in the column's algebraic type — practically a non-integer or incompatible sequenced column.","triggerScenarios":"Declaring max_value outside what the sequenced column's type can represent where saturation does not apply; adding a sequence on a column whose type cannot hold any i128-derived bound; narrowing the sequenced column in the same publish that adds the sequence.","commonSituations":"Custom max_value on a small or non-integer column; module defs edited by hand without type-checking the sequence bounds; schema crate version skew.","solutions":["Choose a max_value representable by the column type, or drop the explicit max","Ensure the sequenced column is an integer type (u64/i64 recommended)","Validate sequence bounds against the column type in the module before publishing"],"exampleFix":"// before: max not representable for the column type\n#[sequence(column = \"id\", max = ...)] // id: u8\n\n// after: widen the column or drop the custom max\n#[sequence(column = \"id\")] // id: u64","handlingStrategy":"validation","validationCode":"// Check the declared max is representable for the column type\nfn sequence_max_ok(col_ty: &AlgebraicType, max: Option<i128>) -> bool {\n    col_ty.saturating_value_from_i128(max.unwrap_or(i128::MAX)).is_some()\n}","typeGuard":"fn is_integer_col(ty: &AlgebraicType) -> bool {\n    matches!(t, AlgebraicType::U8 | AlgebraicType::U16 | AlgebraicType::U32\n        | AlgebraicType::U64 | AlgebraicType::U128 | AlgebraicType::I8\n        | AlgebraicType::I16 | AlgebraicType::I32 | AlgebraicType::I64 | AlgebraicType::I128)\n}","tryCatchPattern":"match auto_migrate_database(&stdb, &mut tx, auth, &plan, &logger) {\n    Err(e) if e.to_string().contains(\"invalid max value\") => {\n        anyhow::bail!(\"module error: {e:#}; widen the column or drop the custom max\");\n    }\n    r => r,\n}","preventionTips":["Prefer leaving max unset on wide integer columns","Cross-check custom bounds against the column type in CI module validation","Avoid narrowing sequenced columns in publishes that also change sequences"],"tags":["rust","spacetimedb","migration","sequence","type-mismatch"],"backgroundTag":"migration-plan-invalid","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"}