Meh, just now I noticed this wasn't a bug report but actually a pull request - could have saved me some work. In my patch I just avoided assigning tab number which is probably better because the number can get wrong when some plugins add/remove new tabs to/from the sidebar.