Skip to content

Add multi-server support to the daemon CLI#205

Draft
maximmaxim345 wants to merge 4 commits intomainfrom
feat/multi-server-support
Draft

Add multi-server support to the daemon CLI#205
maximmaxim345 wants to merge 4 commits intomainfrom
feat/multi-server-support

Conversation

@maximmaxim345
Copy link
Copy Markdown
Member

Note

In draft, since this depends on Sendspin/aiosendspin#201 being released (held back due to some edge cases with the new player delay additions).
Currently includes changes from #202

Add multi-server support when running the sendspin daemon.
Servers are now allowed to discover the daemon, while only the last playing server is allowed to stay connected.

Fixes the reconnect loop mentioned in Sendspin/aiosendspin#201.

teancom and others added 4 commits March 26, 2026 07:12
When the server reconnects to the daemon (same client_id, new websocket),
the old code sent a goodbye message before handshaking the new connection.
This caused the server to remove the client from its group and stop
playback, requiring manual intervention to resume.

Reorder _handle_server_connection to handshake the new connection first,
then tear down the old one. The server's attach_connection() atomically
replaces the websocket for the same client_id, so the client never
leaves the group and playback continues uninterrupted.

Also drop the RuntimeError in _on_audio_chunk when the audio worker
isn't running — just log at debug level and drop the chunk, since this
is a benign race during connection transitions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On server-initiated reconnection, the old client's audio chunk
listeners were never unregistered. This left a brief window where
chunks from the old WebSocket could arrive and hit the audio handler
after the worker was stopped. Call detach_client() before
_handle_disconnect() to cleanly unsubscribe the old listeners first.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of logging every dropped chunk at debug level (which can be
extremely noisy during reconnection races), log only when entering
the dropping state and reset when chunks flow again.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Per the protocol spec, the daemon now decides which server to keep
when multiple servers connect, based on connection reason and a
persisted last-played server ID.
@maximmaxim345 maximmaxim345 added the new-feature Request or implement a new feature label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature Request or implement a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants