{"record":{"id":"37e3938edecbd93f","repo":"clockworklabs/SpacetimeDB","slug":"invalid-sequence-type","errorCode":null,"errorMessage":"invalid sequence type","messagePattern":"invalid sequence type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/server/runtime.ts","lineNumber":1119,"sourceCode":"    switch (colType.tag) {\n      case 'U8':\n      case 'I8':\n      case 'U16':\n      case 'I16':\n      case 'U32':\n      case 'I32':\n        sequenceTrigger = 0;\n        break;\n      case 'U64':\n      case 'I64':\n      case 'U128':\n      case 'I128':\n      case 'U256':\n      case 'I256':\n        sequenceTrigger = 0n;\n        break;\n      default:\n        throw new TypeError('invalid sequence type');\n    }\n    return {\n      colName: col.name!,\n      sequenceTrigger,\n      deserialize: AlgebraicType.makeDeserializer(colType, typespace),\n    };\n  });\n  const hasAutoIncrement = sequences.length > 0;\n\n  const iter = () =>\n    tableIterator(sys.datastore_table_scan_bsatn(table_id), deserializeRow);\n\n  const integrateGeneratedColumns = hasAutoIncrement\n    ? (row: RowType<any>, ret_buf: DataView) => {\n        BINARY_READER.reset(ret_buf);\n        for (const { colName, deserialize, sequenceTrigger } of sequences) {\n          if (row[colName] === sequenceTrigger) {\n            row[colName] = deserialize(BINARY_READER);","sourceCodeStart":1101,"sourceCodeEnd":1137,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/bindings-typescript/src/server/runtime.ts#L1101-L1137","documentation":"When the runtime builds a table view (`makeTableView` in runtime.ts), it inspects every auto-increment sequence on the table and picks the 'sentinel' value a caller passes to trigger sequence generation: `0` for integer types that fit a JS number (U8..I32) and `0n` for wide integers (U64..I256). If the sequence column's algebraic type is anything else, the switch falls through to `invalid sequence type`. This is a schema-definition error surfaced at module build/first table access, not a data error.","triggerScenarios":"Applying `.autoInc()` to a column whose type is not an integer SATS primitive (string, bool, float, identity, timestamp...); building a table dynamically (plain objects instead of `t.*` builders) so the type-level protections are bypassed; hand-constructing table/sequence metadata where `seq.column` points at a non-integer column.","commonSituations":"Trying to auto-increment a `t.string()` primary key; migrating a schema where an autoInc flag ends up on a changed column type; using dynamic/`any`-typed row builders that defeat the compile-time `autoInc()` restrictions.","solutions":["Find the auto-increment column in the failing table and change its builder to an integer type, e.g. `t.u32()` or `t.u64()`, before `.autoInc()`.","If you need a non-integer generated key, drop `.autoInc()` and generate the value in the reducer (e.g. a UUID).","If the table is built dynamically, validate each column before publishing: only U8/I8/U16/I16/U32/I32/U64/I64/U128/I128/U256/I256 may carry autoInc.","Re-run `spacetime build`/`publish` after fixing; the error names the table via the build log context."],"exampleFix":"// before\nconst users = table({}, {\n  id: t.string().primaryKey().autoInc(), // string cannot be a sequence\n});\n\n// after\nconst users = table({}, {\n  id: t.u64().primaryKey().autoInc(),\n});","handlingStrategy":"type-guard","validationCode":"// For dynamically built tables: only integer columns may carry autoInc.\nconst INTEGER_TAGS = new Set(['U8','I8','U16','I16','U32','I32','U64','I64','U128','I128','U256','I256']);\nfunction assertAutoIncColumns(row: Record<string, any>) {\n  for (const [name, col] of Object.entries(row)) {\n    if (col?.builderMeta?.autoInc && !INTEGER_TAGS.has(col?.algebraicType?.tag)) {\n      throw new Error(`column ${name}: autoInc requires an integer type`);\n    }\n  }\n}","typeGuard":"type IsIntegerColumn<C> = C extends { algebraicType: { tag: ('U8'|'I8'|'U16'|'I16'|'U32'|'I32'|'U64'|'I64'|'U128'|'I128'|'U256'|'I256') } } ? true : false;","tryCatchPattern":null,"preventionTips":["Prefer the typed `t.u32()/t.u64()` builders so `.autoInc()` is only offered on integer columns.","When rows are built from plain objects, validate autoInc columns before `table()` registration.","Keep a unit test that constructs every table in the schema to catch this at test time, not publish time."],"tags":["schema","autoincrement","spacetimedb","typescript","build-time"],"backgroundTag":"invalid-column-type","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}