It looks like the envelope API adds some sort of "virtual point" at the AI boundaries when they are connected to the underlying envelope. This confuses SWS.
Parsing the envelope chunk seems to be the only solution since the API is lying about the true envelope contents... Here's a test build that should address this:
https://cfillion.ca/files/sws/fix-br...-connected-ai/. (Comments in the existing code suggests this way is slower, but I haven't measured. EDIT: It's indeed a slower, but should be negligible for real-life sized envelopes, < 250k points.)