Skip to content

Use the time filter parameters from the spec - #227

Merged
maximmaxim345 merged 3 commits into
mainfrom
fix/time-filter-spec-parameters
Nov 2, 2026
Merged

maximmaxim345 merged 3 commits into
mainfrom
fix/time-filter-spec-parameters

Conversation

@maximmaxim345

@maximmaxim345 maximmaxim345 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

What does this implement/fix?

Tested with Brave, Firefox and Safari on macOS and Chrome and Firefox on Android, including a 24 minute session with 100 ms latency, 50 ms jitter and a one-way latency spike. Sync matched main on every device, and the clock stayed within 2 ms through the spike.

The clock sync filter used its own tuning instead of the parameter values the spec now defines. It now uses the spec values, drops samples with a max_error of zero or less, and rounds converted times with halves away from zero, as the spec says.

For the first 100 sync rounds (about 15 minutes), the clock estimate stays the same as before. The reported sync error halves, since the spec scales max_error by 0.5. After 100 rounds, the filter reacts to outliers less often but more strongly. The exported SendspinTimeFilter also defaults to the spec values now.

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.

🔵 Needs a closer look

The clock-filter tuning still needs real-browser validation under jitter and network stalls to verify convergence and playback stability beyond 100 sync rounds, when adaptive forgetting activates.

No open issues 🎉

What changed in this PR

Aligns the SDK’s clock synchronization filter with the Sendspin specification, replacing custom tuning with shared defaults.

Changes:

  • Updates filter defaults, adaptive forgetting thresholds, and measurement-error scaling.
  • Rejects non-positive max_error samples and uses half-away-from-zero rounding for time conversions.
  • Updates unit tests to cover the revised defaults, rounding, and skipped-sample behavior.
File Description
tests/​unit/​time-filter.test.ts Updates expected values and adds rounding and invalid-sample tests.
src/​core/​time-filter.ts Implements revised filter parameters, sample validation, and rounding.
src/​core/​core.ts Uses the time filter’s defaults instead of explicit custom parameters.

Review effort: Balanced

@maximmaxim345
maximmaxim345 marked this pull request as ready for review November 2, 2026 12:42
@maximmaxim345
maximmaxim345 merged commit 415b6df into main Nov 2, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/time-filter-spec-parameters branch November 2, 2026 12:42
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.

Align ADAPTIVE_FORGETTING_CUTOFF with the C++ implementation

2 participants