CIDs and WIDs live in the same global namespace, which is just an incriminating unique resource number, also used by several other resources (unknown). That's why they become large so quickly.

The value that $cid returns is inherited by all aliases, etc, called within an event.

I would presume, without testing, that the $cid returned by a modeless dialog event will be whichever $cid happens to be active. I would further presume that the $cid will represent the dialog's "parent" at the time of the dialog event in question, if the dialog had been assigned a parent (-a switch?), but this is all worth testing for yourself.

Rather than looking up a connection's CID, you can simply request the value via $scon(N).cid on demand.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!