Skip to content

Fix the next track's title showing early after connecting - #238

Merged
maximmaxim345 merged 3 commits into
mainfrom
fix/hold-metadata-until-clock-sync
Nov 6, 2026
Merged

maximmaxim345 merged 3 commits into
mainfrom
fix/hold-metadata-until-clock-sync

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

What does this implement/fix?

When a client connected while the server already had the next track's metadata scheduled, the next title showed right away instead of at the track change, up to 20 seconds early. The server sends that scheduled update on join, before the first time sync reply, and metadata without a clock estimate applied at once.

Metadata that arrives before the first time sync is now held and replayed in arrival order once the clock syncs, so the current track shows first and the next one switches in on time. If time sync never completes, metadata now stays hidden instead of showing unsynced.

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

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

Replayed updates can continue after an onStateChange callback disconnects, allowing stale metadata from the disconnected session to reappear because cleanup does not invalidate the local replay batch.

1 open issue
What changed in this PR

This PR fixes premature next-track titles when joining an active stream by holding metadata until clock synchronization completes.

Changes:

  • Hold unsynchronized metadata and replay it in arrival order once the clock syncs.
  • Calculate playback-aligned delays for replayed metadata.
  • Add a regression test for current-to-next title timing and reuse a time-sync test helper.
File Description
tests/​unit/​protocol-handler.test.ts Tests deferred metadata replay and scheduled title changes.
src/​core/​state-manager.ts Queues held metadata, replays it, and clears it during cleanup.
src/​core/​protocol-handler.ts Defers metadata until synchronization and triggers replay afterward.

Review effort: Balanced

Comment thread src/core/state-manager.ts Resolved

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

No active review issues are identified for the metadata synchronization and replay changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@maximmaxim345
maximmaxim345 merged commit 687825b into main Nov 6, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/hold-metadata-until-clock-sync branch November 6, 2026 11:01
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