{"record":{"id":"bd8692b2449d430f","repo":"clockworklabs/SpacetimeDB","slug":"sequence-id-must-be-sequenceid-sentinel-in","errorCode":null,"errorMessage":"`sequence_id` must be `SequenceId::SENTINEL` in `{:#?}`","messagePattern":"`sequence_id` must be `SequenceId::SENTINEL` in `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/datastore/src/locking_tx_datastore/mut_tx.rs","lineNumber":2154,"sourceCode":"    /// Create a sequence.\n    /// Requires:\n    /// - `seq.sequence_id == SequenceId::SENTINEL`\n    /// - `seq.table_id != TableId::SENTINEL`\n    /// - `seq.sequence_name` must not be used for any other database entity.\n    ///\n    /// Ensures:\n    /// - The sequence metadata is inserted into the system tables (and other data structures reflecting them).\n    /// - The returned ID is unique and not `SequenceId::SENTINEL`.\n    pub fn create_sequence(&mut self, seq: SequenceSchema) -> Result<SequenceId> {\n        if seq.table_id == TableId::SENTINEL {\n            return Err(anyhow::anyhow!(\"`table_id` must not be `TableId::SENTINEL` in `{seq:#?}`\").into());\n        }\n\n        let table_id = seq.table_id;\n        let matching_system_table_schema = system_tables().iter().find(|s| s.table_id == table_id).cloned();\n\n        if seq.sequence_id != SequenceId::SENTINEL && matching_system_table_schema.is_none() {\n            return Err(anyhow::anyhow!(\"`sequence_id` must be `SequenceId::SENTINEL` in `{:#?}`\", seq).into());\n        }\n\n        let sequence_id = seq.sequence_id;\n\n        log::trace!(\n            \"SEQUENCE CREATING: {} for table: {} and col: {}\",\n            seq.sequence_name,\n            table_id,\n            seq.col_pos\n        );\n\n        // Insert the sequence row into st_sequences\n        // NOTE: Because st_sequences has a unique index on sequence_name, this will\n        // fail if the table already exists.\n        let mut sequence_row = StSequenceRow {\n            sequence_id,\n            sequence_name: seq.sequence_name,\n            table_id,","sourceCodeStart":2136,"sourceCodeEnd":2172,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/9e0d92412ff2248f401a8ad12d535f2b5ac30912/crates/datastore/src/locking_tx_datastore/mut_tx.rs#L2136-L2172","documentation":"MutTxId::create_sequence requires sequence_id to be SequenceId::SENTINEL for user tables so the datastore can allocate a fresh unique id. Pre-assigned ids are only tolerated when the sequence targets a system table (matched against system_tables()). Passing a concrete sequence_id for a user sequence violates the API contract and is rejected.","triggerScenarios":"Re-inserting a sequence with a previously allocated sequence_id on a user table; restoring schema objects by replaying old schema dumps; building SequenceSchema with a hardcoded id.","commonSituations":"Backup/restore tooling that replays captured schema rows; migrations that copy ids from another database; tests reusing fixture schemas.","solutions":["Reset seq.sequence_id to SequenceId::SENTINEL and let create_sequence allocate a new id","When replaying/restoring schema, drop the old ids for user objects and remap references after creation"],"exampleFix":"// before: replaying a captured schema with its old id\nlet seq = SequenceSchema { sequence_id: old_sequence_id, .. };\nlet new_id = tx.create_sequence(seq)?; // -> sequence_id must be SENTINEL\n\n// after: let the datastore assign the id\nlet seq = SequenceSchema { sequence_id: SequenceId::SENTINEL, .. };\nlet new_id = tx.create_sequence(seq)?;","handlingStrategy":"type-guard","validationCode":"// When creating user sequences, always let the datastore assign the id\nlet seq = SequenceSchema { sequence_id: SequenceId::SENTINEL, .. };","typeGuard":"fn sequence_id_is_unset(seq: &SequenceSchema) -> bool {\n    seq.sequence_id == SequenceId::SENTINEL || targets_system_table(seq.table_id)\n}","tryCatchPattern":"match tx.create_sequence(seq) {\n    Err(e) if e.to_string().contains(\"sequence_id` must be `SequenceId::SENTINEL``\") => {\n        // Reset sequence_id to the sentinel and retry; remap the returned id afterwards\n    }\n    other => other,\n}","preventionTips":["Never copy sequence ids across databases or replays","In restore tooling, strip ids from user schema objects and remap after creation"],"tags":["spacetimedb","datastore","sequence","schema","sentinel"],"backgroundTag":"sentinel-id-misuse","analyzedSha":"9e0d92412ff2248f401a8ad12d535f2b5ac30912","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}