{"record":{"id":"25aaf95b635f866c","repo":"clockworklabs/SpacetimeDB","slug":"invalid-sequence-increment-must-be-non-zero","errorCode":null,"errorMessage":"Invalid sequence: increment must be non-zero","messagePattern":"Invalid sequence: increment must be non-zero","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/datastore/src/locking_tx_datastore/sequence.rs","lineNumber":39,"sourceCode":"    fn heap_usage(&self) -> usize {\n        // MEMUSE: intentionally ignoring schema\n        self.value.heap_usage()\n    }\n}\n\nimpl Sequence {\n    pub(super) fn new(schema: SequenceSchema, previous_allocation: Option<i128>) -> Self {\n        if schema.start < schema.min_value || schema.start > schema.max_value {\n            panic!(\n                \"Invalid sequence: start value {} is out of bounds for sequence with min_value {} and max_value {}\",\n                schema.start, schema.min_value, schema.max_value\n            );\n        }\n        if schema.max_value <= schema.min_value {\n            panic!(\"Invalid sequence: max_value must be greater than min_value\");\n        }\n        if schema.increment == 0 {\n            panic!(\"Invalid sequence: increment must be non-zero\");\n        }\n        if schema.increment.unsigned_abs() >= (schema.max_value - schema.min_value) as u128 {\n            panic!(\n                \"Invalid sequence: increment must be less than or equal to the range between min_value and max_value\"\n            );\n        }\n        let start = if let Some(prev) = previous_allocation {\n            if prev < schema.min_value || prev > schema.max_value {\n                // Previous versions set allocated to 0 as a default,\n                // so we have this special case.\n                if prev == 0 {\n                    schema.start\n                } else {\n                    panic!(\n                        \"Invalid sequence: previous allocation value {prev} is out of bounds for sequence with min_value {} and max_value {}\",\n                        schema.min_value, schema.max_value\n                    );\n                }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/datastore/src/locking_tx_datastore/sequence.rs#L21-L57","documentation":"Third invariant in Sequence::new: increment must be non-zero. A zero step would never advance the sequence, so the constructor panics immediately rather than producing a stuck sequence. Hit when sequence DDL sets INCREMENT BY 0 or a programmatic schema leaves a zero default.","triggerScenarios":"Creating a sequence with INCREMENT BY 0, or building a SequenceSchema programmatically where increment defaults to 0 before DDL application.","commonSituations":"Schema code that constructs SequenceSchema with zeroed fields; hand-edited DDL; migration tooling that copies increment from an uninitialized variable.","solutions":["Set INCREMENT BY to a non-zero value (1 for typical auto-increment).","Omit the INCREMENT clause to use the default step of 1.","In programmatic schemas, assert increment != 0 before submission."],"exampleFix":"-- before: zero step is rejected\nCREATE SEQUENCE s MINVALUE 0 MAXVALUE 100 INCREMENT BY 0;\n\n-- after: valid step\nCREATE SEQUENCE s MINVALUE 0 MAXVALUE 100 INCREMENT BY 1;","handlingStrategy":"validation","validationCode":"fn increment_valid(s: &SequenceSchema) -> Result<(), String> {\n    if s.increment == 0 {\n        return Err(\"increment must be non-zero\".into());\n    }\n    Ok(())\n}","typeGuard":"fn valid_sequence_schema(s: &SequenceSchema) -> bool {\n    s.min_value <= s.start && s.start <= s.max_value\n        && s.max_value > s.min_value\n        && s.increment != 0\n        && s.increment.unsigned_abs() < (s.max_value - s.min_value) as u128\n}","tryCatchPattern":null,"preventionTips":["Default INCREMENT to 1 in schema templates.","Reject zeroed SequenceSchema structs in code review of programmatic schemas.","Add a DDL lint for INCREMENT BY 0."],"tags":["sql","sequence","ddl","schema-validation","spacetimedb"],"backgroundTag":"sequence-definition-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"}