Do orderIDs come from TWS or does ibc generate them?

Today when I had an internet outage, my exploration continued sending orders to TWS, and each order was receiving an orderID that was the next one in the sequence. Some orders went into Error status because no security definition was found (even though the security was defined correctly), and others were PreSubmitted, which I thought was strange.

Anyway, when the internet outage was resolved and TWS reconnected to IB's servers, the order sequence reverted back to where it was before the outage, causing orderIDs to be recycled. I've never seen this before, so I have this question:

Do orderIDs come from TWS or does ibc generate them?

Actually it is both. IBController asks for "next valid ID" from TWS, using nextValidID here:

and in subsequent orders it auto-increments it in this line src/BrokerIBDlg.cpp · master · AmiBroker / IBController · GitLab

Auto-incrementing is done so because nextValidID is slow and asynchronous and would prevent sending orders quickly.

This is great, thanks so much for pointing me to the appropriate lines.