This is fundamentally an issue with the network being deleted either before the port was processed on the agent in that network or while the agent was offline.
We can adjust the logic to always try to delete the network associated with a deleted network's ID. However, that won't solve the case where bridges are left behind if a network is deleted while the agent is offline.
To address the offline case I think you will always need to run a manual cleanup script unless we change the agent to try to delete bridges it doesn't recognize, but that seems risky.
This is fundamentally an issue with the network being deleted either before the port was processed on the agent in that network or while the agent was offline.
We can adjust the logic to always try to delete the network associated with a deleted network's ID. However, that won't solve the case where bridges are left behind if a network is deleted while the agent is offline.
To address the offline case I think you will always need to run a manual cleanup script unless we change the agent to try to delete bridges it doesn't recognize, but that seems risky.