Skip to content

feat: accept the ndt7 server timestamp on measurements - #355

Open
Victor1Ja wants to merge 1 commit into
stagingfrom
feat/measurement-server-timestamp
Open

feat: accept the ndt7 server timestamp on measurements#355
Victor1Ja wants to merge 1 commit into
stagingfrom
feat/measurement-server-timestamp

Conversation

@Victor1Ja

@Victor1Ja Victor1Ja commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Stores M-Lab's own clock alongside the device clock on each measurement.
Client side: unicef/project-connect-daily-check-app#85.

Why

  • Every measurement is stamped with Date.now() in the app, so measurements.timestamp is only as trustworthy as the clock of the machine running the test — and on these devices it is frequently off by hours or days.
  • From app v2.0.4 the ndt7 client also reports M-Lab's clock, read from the Date header of the locate service response.
  • This is a second, independent reference point next to timestamp, not a replacement. Nothing that reads timestamp today changes behaviour.

What changed

  • Schema: server_timestamp DateTime? @db.Timestamptz(6) on measurements. Not on measurements_failed, matching how scheduled_at / scheduled_slot were handled.
  • Migration: 20260824130000_add_server_timestamp_to_measurements — one nullable ADD COLUMN, no default. Additive only; no existing migration touched.
  • DTO: optional server_timestamp?: Date with an @ApiProperty description.
  • Service: mapped in toModel() and in the DTO mapping (?? null), same pattern as scheduled_at.
  • Mocks: field added to the three measurement mocks.

Compatibility

Caveat worth knowing

The value is M-Lab's clock at server discovery, a few seconds before the test starts, at 1-second resolution. Good enough to detect a device clock that is badly off; not a precise start-of-test timestamp. The ndt7 protocol carries no wall clock of its own — see the client PR for why this is the only reachable source.

Testing

  • npx jest446 passed, 63 suites (444 on staging before this), no regressions.
  • 2 new tests: value persisted when sent, stored as null when omitted.
  • npx tsc --noEmit and npx prisma generate clean.

The app stamps every measurement with Date.now(), so `timestamp` is only
as trustworthy as the clock of the machine running the test, which on
these devices is frequently wrong.

From v2.0.4 the ndt7 client also reports M-Lab's own clock, read from the
Date header of the locate service response, and sends it as
server_timestamp. This stores it as a second, independent reference point
next to `timestamp` rather than replacing it.

Additive and optional throughout: a new migration that only adds the
column, nullable with no default, and clients that do not send the field
keep working unchanged - which is every release before v2.0.4.

App counterpart: unicef/project-connect-daily-check-app#85

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants