Skip to content

Reject non-monotonic timestamps in the time filter - #119

Merged
maximmaxim345 merged 1 commit into
mainfrom
fix/time-filter-monotonic-guard
Jun 3, 2026
Merged

maximmaxim345 merged 1 commit into
mainfrom
fix/time-filter-monotonic-guard

Conversation

@maximmaxim345

@maximmaxim345 maximmaxim345 commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

The filter only skipped timestamps equal to the last update, so a backward timestamp produced a negative dt that corrupts the Kalman predict step. update() now rejects any non-increasing timestamp, and reset() clears the stale _last_update. Matches the C++ implementation.

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.

Pull request overview

Updates the time synchronization Kalman filter to ignore non-monotonic measurement timestamps, aligning behavior with the C++ implementation and preventing invalid dt values from affecting drift/prediction calculations.

Changes:

  • Ignore measurements whose time_added is not strictly increasing (<= _last_update) to avoid divide-by-zero and invalid predict steps.
  • Reset _last_update in reset() so a reset fully clears time-tracking state.

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

@maximmaxim345
maximmaxim345 merged commit 2834068 into main Jun 3, 2026
4 checks passed
@maximmaxim345
maximmaxim345 deleted the fix/time-filter-monotonic-guard branch June 3, 2026 15:12
maximmaxim345 added a commit that referenced this pull request Jun 4, 2026
- Backward time_added in the Kalman filter must be rejected (#119 guard).
- StateManager.reset() must preserve streamGeneration so late chunks from
  a previous stream can never match after a reconnect.
- Reconnect timer fires at the configured base delay, not a hard-coded 5s.
maximmaxim345 added a commit that referenced this pull request Jun 4, 2026
…st a real aiosendspin server. (#93)

Adds a vitest test suite covering the SDK and an end-to-end run against
a real aiosendspin server. No changes to `src/`.

## Unit tests (13 files, `tests/unit/`)

clock-source, codec-support, core, decoder, decoder-codecs,
output-latency-tracker, protocol-handler, recorrection-monitor,
scheduler, state-manager, time-filter, time-sync-manager,
websocket-manager.

## E2E (1 file, `tests/e2e/`)

`sendspin-core.e2e.test.ts` drives a real aiosendspin Python server
through a line-based stdin/stdout control protocol implemented by
`tests/helpers/sendspin-server.py`. The Node side spawns and controls
the subprocess via `tests/helpers/aiosendspin-server.ts`.

## Stats

234 tests across 14 files. `yarn test` ~32s locally.

## Bugs already caught and fixed

Added a couple more tests which were able to flag bugs in this library.
Each of them was already fixed in a separate PR before this one so all
tests pass:

- #116
- #117
- #118
- #119
- #121
- #122

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Maxim Raznatovski <[email protected]>
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