clockworklabs/SpacetimeDB · error
Invalid sequence: max_value must be greater than min_value
Error message
Invalid sequence: max_value must be greater than min_value
What it means
Second invariant in Sequence::new: max_value must be strictly greater than min_value, otherwise the sequence range is empty and the constructor panics. Triggered by sequence definitions where MAXVALUE <= MINVALUE, including the equal-bounds case. It is a schema validation failure surfaced as a panic during DDL application.
Source
Thrown at crates/datastore/src/locking_tx_datastore/sequence.rs:36
}
impl MemoryUsage for Sequence {
fn heap_usage(&self) -> usize {
// MEMUSE: intentionally ignoring schema
self.value.heap_usage()
}
}
impl Sequence {
pub(super) fn new(schema: SequenceSchema, previous_allocation: Option<i128>) -> Self {
if schema.start < schema.min_value || schema.start > schema.max_value {
panic!(
"Invalid sequence: start value {} is out of bounds for sequence with min_value {} and max_value {}",
schema.start, schema.min_value, schema.max_value
);
}
if schema.max_value <= schema.min_value {
panic!("Invalid sequence: max_value must be greater than min_value");
}
if schema.increment == 0 {
panic!("Invalid sequence: increment must be non-zero");
}
if schema.increment.unsigned_abs() >= (schema.max_value - schema.min_value) as u128 {
panic!(
"Invalid sequence: increment must be less than or equal to the range between min_value and max_value"
);
}
let start = if let Some(prev) = previous_allocation {
if prev < schema.min_value || prev > schema.max_value {
// Previous versions set allocated to 0 as a default,
// so we have this special case.
if prev == 0 {
schema.start
} else {
panic!(
"Invalid sequence: previous allocation value {prev} is out of bounds for sequence with min_value {} and max_value {}",View on GitHub (pinned to 6dee26c6ef)
Solutions
- Set MAXVALUE strictly greater than MINVALUE.
- Omit both clauses to accept the schema's default bounds when exact limits are not required.
- Add a lint in migration tooling that asserts max > min before applying DDL.
Example fix
-- before: empty range (max == min) CREATE SEQUENCE s MINVALUE 10 MAXVALUE 10; -- after: non-empty range CREATE SEQUENCE s MINVALUE 10 MAXVALUE 100;
Defensive patterns
Strategy: validation
Validate before calling
fn bounds_non_empty(s: &SequenceSchema) -> Result<(), String> {
(s.max_value > s.min_value)
.then_some(())
.ok_or_else(|| format!("max_value {} must be > min_value {}", s.max_value, s.min_value))
} Type guard
fn valid_sequence_schema(s: &SequenceSchema) -> bool {
s.min_value <= s.start && s.start <= s.max_value
&& s.max_value > s.min_value
&& s.increment != 0
&& s.increment.unsigned_abs() < (s.max_value - s.min_value) as u128
} Prevention
- Lint MINVALUE/MAXVALUE clause ordering and values in DDL review.
- Omit bounds clauses when defaults suffice.
- Assert max > min in programmatic schema builders before submission.
When it happens
Trigger: Creating a sequence with MAXVALUE equal to or less than MINVALUE, e.g. MINVALUE 10 MAXVALUE 10, or a negative MAXVALUE with a default zero MINVALUE.
Common situations: Copy-paste errors swapping MINVALUE/MAXVALUE clauses; programmatic schema builders that default both bounds to the same value; migrations that tighten bounds incorrectly.
Related errors
- Invalid sequence: start value {} is out of bounds for sequen
- Invalid sequence: increment must be non-zero
- Invalid sequence: increment must be less than or equal to th
- Index '${indexLabel}' on table '${tableLabel}' must define a
- Event tables cannot be used as the lookup table in subscript
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/59180b5c6dfb71ed.
Report an issue: GitHub.