clockworklabs/SpacetimeDB · error · TypeError

invalid sequence type

Error message

invalid sequence type

What it means

When the runtime builds table accessors, it computes a placeholder 'trigger' value for every auto-increment (sequence) column: numeric 0 for integer types that fit a JS number (U8/I8/U16/I16/U32/I32) and 0n for 64-256-bit integers (U64/I64/U128/I128/U256/I256). Any other column type has no valid trigger, so table setup throws TypeError('invalid sequence type') at module start.

Source

Thrown at crates/bindings-typescript/src/server/runtime.ts:1114

    switch (colType.tag) {
      case 'U8':
      case 'I8':
      case 'U16':
      case 'I16':
      case 'U32':
      case 'I32':
        sequenceTrigger = 0;
        break;
      case 'U64':
      case 'I64':
      case 'U128':
      case 'I128':
      case 'U256':
      case 'I256':
        sequenceTrigger = 0n;
        break;
      default:
        throw new TypeError('invalid sequence type');
    }
    return {
      colName: col.name!,
      sequenceTrigger,
      deserialize: AlgebraicType.makeDeserializer(colType, typespace),
    };
  });
  const hasAutoIncrement = sequences.length > 0;

  const iter = () =>
    tableIterator(sys.datastore_table_scan_bsatn(table_id), deserializeRow);

  const integrateGeneratedColumns = hasAutoIncrement
    ? (row: RowType<any>, ret_buf: DataView) => {
        BINARY_READER.reset(ret_buf);
        for (const { colName, deserialize, sequenceTrigger } of sequences) {
          if (row[colName] === sequenceTrigger) {
            row[colName] = deserialize(BINARY_READER);

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Change the auto-increment column to a supported integer type (I32/U32 for small ranges, U64 for large ones)
  2. Remove the auto-increment/sequence attribute from the non-integer column
  3. Regenerate module code from the schema instead of hand-editing type definitions

Example fix

// before: auto-inc sequence declared on a non-integer column
// table Users { name: string /* marked auto-inc */ }

// after: integer auto-inc column
// table Users { id: u64 /* auto-inc */ }
// insert 0 (small ints) or 0n (64+ bit ints) to request the generated value
Defensive patterns

Strategy: validation

Validate before calling

const SEQUENCE_SUPPORTED = new Set([
  'U8', 'I8', 'U16', 'I16', 'U32', 'I32', 'U64', 'I64', 'U128', 'I128', 'U256', 'I256',
]);
function assertSequenceColumnOk(typeTag: string, colName: string): void {
  if (!SEQUENCE_SUPPORTED.has(typeTag)) {
    throw new Error(`auto-inc column '${colName}' must be an integer type, got ${typeTag}`);
  }
}

Type guard

const isSequenceSupportedType = (tag: string): tag is
  'U8' | 'I8' | 'U16' | 'I16' | 'U32' | 'I32' | 'U64' | 'I64' | 'U128' | 'I128' | 'U256' | 'I256' =>
  SEQUENCE_SUPPORTED.has(tag);

Prevention

When it happens

Trigger: A sequence/auto-increment column whose algebraic type is not one of the eight supported integer types: a string, bool, identity, or product/sum type column marked auto-increment; hand-edited or stale codegen emitting sequence metadata with a non-integer column type.

Common situations: Porting SQL schemas with AUTO_INCREMENT assumptions; manually editing generated schema/type definitions; codegen version mismatch that emits sequence metadata the runtime rejects.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/37e3938edecbd93f. Report an issue: GitHub.