Skip to content

Resync the clock after reconnecting to the server - #201

Merged
maximmaxim345 merged 3 commits into
mainfrom
fix/reset-time-filter-on-reconnect
Oct 29, 2026
Merged

maximmaxim345 merged 3 commits into
mainfrom
fix/reset-time-filter-on-reconnect

Conversation

@maximmaxim345

@maximmaxim345 maximmaxim345 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

What does this implement/fix?

After a reconnect, the player kept the previous connection's clock offset and reported itself as synchronized. After a server restart, this scheduled playback against the old server clock until the time filter slowly caught up.

The time filter now resets whenever a new connection opens, and still persists across a re-handshake as the spec requires. Until the first clock sync on the new connection, the player reports itself as not available and skips sync correction.

Related issue or spec PR (if applicable):

Types of changes

  • Bugfix (non-breaking change which fixes an issue): bugfix
  • New feature (non-breaking change which adds functionality): new-feature
  • Enhancement to an existing feature: enhancement
  • Breaking change (changes the public API or the protocol in a way that is not backwards compatible): breaking-change
  • Refactor (no behavior change): refactor
  • Documentation only: documentation
  • Maintenance / chore: maintenance
  • CI / workflow change: ci
  • Dependencies bump: dependencies

After an auto-reconnect the client kept the previous connection's clock
offset and drift and reported itself synchronized, so playback after a
server restart was scheduled against a stale clock.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The recorrection monitor can interpret the unsynchronized filter’s reset offset as drift and interrupt buffered playback.

1 open issue
What changed in this PR

This PR resets the SDK’s clock synchronization when a new connection opens, preventing playback from using a stale server-clock offset after reconnecting.

Changes:

  • Reset the time filter on connection open while preserving it during a connection drop.
  • Add a regression test verifying the filter remains synchronized after a drop and resets when the replacement socket opens.
File Description
tests/​unit/​core.test.ts Tests time-filter preservation during a drop and reset on reconnect.
src/​core/​core.ts Resets the time filter before starting the new connection’s transport.

Review effort: Balanced

Comment thread src/core/core.ts Resolved
After a reconnect reset the filter, the recorrection check measured the
scheduled audio against an unsynchronized offset, saw a large drift and
cut the buffered audio while new audio could not be scheduled yet.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

No blocking defects were identified, but reconnect and playback validation remains pending in this draft PR.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

maximmaxim345 added a commit that referenced this pull request Oct 27, 2026
…205)

# What does this implement/fix?

The player reported `available: true` before its clock was synchronized,
so servers sent audio it couldn't schedule yet. A short clip like an
announcement that arrived before the first time sync was never played.

`client/state` now reports `available: false` until the first time sync
completes, then sends an update with `available: true`. I kept one rule
for every set of roles, so a controller only client also reports
`available: false` until then.

Servers that follow the spec keep a client that opens with `available:
false` in its group while it syncs. Music Assistant 2.10.0 to 2.10.6
moves it to its own group instead, which aiosendspin 10.0.0 fixed.

After a reconnect the clock filter stays synchronized from the previous
connection, so the player can still report available before the new
connection's first sync. #201 will fix that.

**Related issue or spec PR (if applicable):**

- Closes #182
- #181

## Types of changes

<!--
Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the
matching label, and the release notes use it to sort this change.
-->

- [x] Bugfix (non-breaking change which fixes an issue): `bugfix`
- [ ] New feature (non-breaking change which adds functionality):
`new-feature`
- [ ] Enhancement to an existing feature: `enhancement`
- [ ] Breaking change (changes the public API or the protocol in a way
that is not backwards compatible): `breaking-change`
- [ ] Refactor (no behavior change): `refactor`
- [ ] Documentation only: `documentation`
- [ ] Maintenance / chore: `maintenance`
- [ ] CI / workflow change: `ci`
- [ ] Dependencies bump: `dependencies`
@maximmaxim345
maximmaxim345 marked this pull request as ready for review October 29, 2026 11:11
@maximmaxim345
maximmaxim345 requested a balanced review from Copilot October 29, 2026 11:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The reconnect clock-synchronization changes have no active review issues.

No open issues 🎉

Review effort: Balanced

@maximmaxim345
maximmaxim345 merged commit 6d45947 into main Oct 29, 2026
5 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/reset-time-filter-on-reconnect branch October 29, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants