mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-11-09 05:24:49 +09:00
When an agent reconnected, register_agent overwrote the in-memory ConnectedAgent for the server but never disconnected the old socket or drained its pending commands. Callers blocked in send_command() on the old agent's result_queue were never signalled — they waited out the full per-command timeout and returned a misleading "Command timeout" even though the agent was back online (the late result would resolve against the new agent and be unreachable). The agent was also briefly left holding two live sockets. On replacement, register_agent now (after releasing the lock to avoid deadlocking with the disconnect handler): - puts an AGENT_RECONNECTED error on each orphaned pending command's result_queue so blocked callers return immediately, and - disconnects the old WS socket (guarded: only for ws transport, only when the socket id actually changed, only when socketio is initialized). The old socket id is already removed from _socket_to_server before the disconnect, so the resulting disconnect handler is a no-op for the freshly registered agent. Adds two regression tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>