When a client connects, an event_dispatcher is created for the session. At that point, there's one thread created to send heartbeats by producing an outgoing message in the event_dispatcher. If the client submits a tool call request, the response for that request is also sent back by producing an outgoing message in the event_dispatcher. If those two happen before the thread waiting to consume the outgoing message (wait_event), then one of them gets overwritten.
I think the correct fix is to use a std::queue<> in event_dispatcher. You can use std::move and be as efficient as you are now and remove any possibility of losing messages.
When a client connects, an event_dispatcher is created for the session. At that point, there's one thread created to send heartbeats by producing an outgoing message in the event_dispatcher. If the client submits a tool call request, the response for that request is also sent back by producing an outgoing message in the event_dispatcher. If those two happen before the thread waiting to consume the outgoing message (wait_event), then one of them gets overwritten.
I think the correct fix is to use a std::queue<> in event_dispatcher. You can use std::move and be as efficient as you are now and remove any possibility of losing messages.