Skip to content

Fix server command listener lost after daemon reconnect#250

Merged
balloob merged 1 commit into
mainfrom
copilot/fix-volume-controller-reconnection
May 11, 2026
Merged

Fix server command listener lost after daemon reconnect#250
balloob merged 1 commit into
mainfrom
copilot/fix-volume-controller-reconnection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

In client-initiated mode, _handle_disconnect was unsubscribing the server command listener on every reconnect cycle, but the connection loop never re-registered it. This caused volume/mute commands from the server to stop working after the first reconnect.

The listener is scoped to the client's lifetime (which persists across reconnects), not the connection's. Refactored the daemon to use _attach_client/_detach_client pairs (matching the TUI's existing pattern) so the lifecycle is explicit:

  • _attach_client — registers listeners, attaches audio handler, starts MPRIS
  • _detach_client — the inverse, called on server switch and full teardown
  • _handle_disconnect — just resets audio state, called on every disconnect
  • Reconnect loop only calls _handle_disconnect, so listeners survive

Copilot AI linked an issue May 11, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix hook-based volume controller on reconnection Restore daemon volume command handling after client-initiated reconnects May 11, 2026
Copilot AI requested a review from balloob May 11, 2026 14:17
@balloob balloob force-pushed the copilot/fix-volume-controller-reconnection branch 3 times, most recently from dec0976 to c32ccb3 Compare May 11, 2026 14:56
In client-initiated mode, _handle_disconnect was unsubscribing the
server command listener on every reconnect cycle, but the connection
loop never re-registered it. This caused volume/mute commands from the
server to stop working after the first reconnect.

The listener is scoped to the client's lifetime (which persists across
reconnects), not the connection's, so it should only be torn down on
full teardown — matching the TUI's existing behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@balloob balloob force-pushed the copilot/fix-volume-controller-reconnection branch from c32ccb3 to 1679ce1 Compare May 11, 2026 14:58
@balloob balloob marked this pull request as ready for review May 11, 2026 15:00
Copilot AI review requested due to automatic review settings May 11, 2026 15:00
@balloob balloob changed the title Restore daemon volume command handling after client-initiated reconnects Fix server command listener lost after daemon reconnect May 11, 2026
@balloob balloob merged commit 2bc1d67 into main May 11, 2026
2 checks passed
@balloob balloob deleted the copilot/fix-volume-controller-reconnection branch May 11, 2026 15:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to restore daemon-side volume/mute command handling across client-initiated reconnects by refactoring how the daemon attaches/detaches a SendspinClient and its listeners, ensuring connection-scoped cleanup is handled consistently.

Changes:

  • Refactors daemon client wiring into _attach_client() / _detach_client() helpers (audio handler, listeners, MPRIS).
  • Updates server-initiated connection handling to use the new attach/detach helpers and ensure cleanup in finally.
  • Adjusts client-initiated reconnect handling to only reset audio state on disconnect (instead of tearing down broader client-scoped state).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sendspin/daemon/daemon.py
Comment on lines 379 to 385

# Connection dropped
logger.info("Disconnected from server")
# Keep MPRIS alive across reconnects in client-initiated mode.
await self._handle_disconnect(stop_mpris=False)
await self._handle_disconnect()

logger.info("Reconnecting to %s", url)

Comment thread sendspin/daemon/daemon.py
Comment on lines 379 to 385

# Connection dropped
logger.info("Disconnected from server")
# Keep MPRIS alive across reconnects in client-initiated mode.
await self._handle_disconnect(stop_mpris=False)
await self._handle_disconnect()

logger.info("Reconnecting to %s", url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook-based volume controller not reinitiated on reconnection

3 participants