Skip to content

Follow the spec's time sync burst rules - #194

Merged
maximmaxim345 merged 4 commits into
mainfrom
fix/time-sync-lowest-error
Oct 22, 2026
Merged

maximmaxim345 merged 4 commits into
mainfrom
fix/time-sync-lowest-error

Conversation

@maximmaxim345

Copy link
Copy Markdown
Member

What does this implement/fix?

The client didn't follow the spec's rules for client/time bursts. It fed the time filter the median of the three fastest measurements instead of the one with the lowest max_error, and bursts always started slightly more than 10 seconds apart.

Now each burst only feeds its lowest max_error measurement to the filter, measurement and max_error are truncated to whole microseconds, and bursts are scheduled every 9 seconds so a late timer can't push them past the 10 second limit.

Bursts can still end up more than 10 seconds apart when the previous burst is still running at the next tick (round trips averaging over about 1.1 s), or when Chrome throttles timers in a tab that has been hidden and silent for a while. Servers must not close the connection over this.

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.

🟢 Approval recommended

Static review found no blocking issues; the remaining regression-test suggestion is optional.

1 open issue
What changed in this PR

Aligns the SDK’s time synchronization bursts with the protocol’s sample-selection and timing rules.

Changes:

  • Selects the lowest-RTT sample instead of the median of the three fastest samples.
  • Truncates offset and maximum error to whole microseconds.
  • Reduces the burst interval to 9 seconds and updates selection and scheduling tests.
File Description
tests/​unit/​time-sync-manager.test.ts Updates expectations for sample selection and burst timing.
src/​core/​time-sync-manager.ts Revises sample selection, microsecond truncation, and burst interval.

Review effort: Balanced

Comment thread tests/unit/time-sync-manager.test.ts Resolved
@maximmaxim345
maximmaxim345 merged commit 932df66 into main Oct 22, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/time-sync-lowest-error branch October 22, 2026 16:08
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