From f523093ea0f20e4878760fa75364ae20f172f54b Mon Sep 17 00:00:00 2001 From: uvtqt Date: Wed, 18 Nov 2026 11:10:15 +0100 Subject: [PATCH 1/3] devices: don't show a 1970/2019 'last data' date for a never-set strap RTC rec_ts_hw is guarded only against '> 0', and lastRecordAt only against null, so a strap whose RTC was never set (factory-epoch records) surfaced as a 1970/2019 'last data' date the records never supported. Apply the same kMinPlausibleUnix floor the ingest gate uses via a pure plausibleRecordInstant helper, so an implausible frontier reads as 'not reported' instead. Co-Authored-By: Claude Opus 4.8 --- lib/state/sync_controller.dart | 8 +++++--- lib/sync/sync_policy.dart | 11 +++++++++++ test/sync_policy_test.dart | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/state/sync_controller.dart b/lib/state/sync_controller.dart index a7e536250..bd8f921e1 100644 --- a/lib/state/sync_controller.dart +++ b/lib/state/sync_controller.dart @@ -23,6 +23,7 @@ import '../sync/sync_policy.dart' ReconnectSupervisorAction, ResumeLinkAction, kIosBackgroundPromptIntervalSeconds, + plausibleRecordInstant, resumeLinkAction, superviseReconnect; @@ -1264,9 +1265,10 @@ class SyncController { DateTime? get lastDataAt => engine.lastRxAt; - DateTime? get lastRecordAt => lastRecTs == null - ? null - : DateTime.fromMillisecondsSinceEpoch(lastRecTs! * 1000); + // A sub-floor frontier (a strap whose RTC was never set) must not surface as + // a 1970/2019 "last data" date; plausibleRecordInstant applies the same floor + // the ingest gate uses. + DateTime? get lastRecordAt => plausibleRecordInstant(lastRecTs); void markSyncActivity() { final now = DateTime.now().millisecondsSinceEpoch; diff --git a/lib/sync/sync_policy.dart b/lib/sync/sync_policy.dart index eef415135..a6d070269 100644 --- a/lib/sync/sync_policy.dart +++ b/lib/sync/sync_policy.dart @@ -383,6 +383,17 @@ bool isPlausibleUnix( return true; } +/// The record frontier (`rec_ts_hw`) as a wall-clock instant for display, or +/// null when it is missing or below the plausible floor. A strap whose RTC was +/// never set banks factory-epoch records; the frontier cursor and `lastRecordAt` +/// guard only `> 0` / `!= null`, so such a frontier reached the devices "last +/// data" line as a 1970/2019 date the records never supported. Applying the +/// same [kMinPlausibleUnix] floor the ingest gate uses keeps that honest. +DateTime? plausibleRecordInstant(int? tsSec) => + (tsSec == null || tsSec < kMinPlausibleUnix) + ? null + : DateTime.fromMillisecondsSinceEpoch(tsSec * 1000); + /// A stricter, single-purpose sanity check for a band-reported "newest /// record" timestamp (GET_DATA_RANGE's `range_newest`) that sits implausibly /// far in the future — the signature of a corrupt/never-set strap RTC. diff --git a/test/sync_policy_test.dart b/test/sync_policy_test.dart index dda11dc2c..3150380ac 100644 --- a/test/sync_policy_test.dart +++ b/test/sync_policy_test.dart @@ -9,6 +9,26 @@ import 'package:openstrap_edge/sync/sync_policy.dart'; void main() { const wall = 1750000000; // a plausible "now" (2025-06) + group('record frontier as a display instant', () { + // A strap whose RTC was never set banks factory-epoch records. The cursor + // and the "last data" getter guard only `> 0` / `!= null`, so that frontier + // reached the devices screen as a 1970/2019 date the data never supported. + test('a sub-floor or missing frontier is no instant', () { + expect(plausibleRecordInstant(null), isNull); + expect(plausibleRecordInstant(0), isNull); + expect(plausibleRecordInstant(1), isNull); // ~1970 + expect(plausibleRecordInstant(1577836800), isNull); // 2020-01, below floor + expect(plausibleRecordInstant(kMinPlausibleUnix - 1), isNull); + }); + test('a plausible frontier converts to its own second', () { + expect(plausibleRecordInstant(kMinPlausibleUnix), + DateTime.fromMillisecondsSinceEpoch(kMinPlausibleUnix * 1000)); + const t = 1750000000; // 2025-06 + expect(plausibleRecordInstant(t), + DateTime.fromMillisecondsSinceEpoch(t * 1000)); + }); + }); + group('plausibility gate', () { test('absolute floor + future ceiling', () { expect(isPlausibleUnix(kMinPlausibleUnix - 1, wall), isFalse); From 47cb1d9b5b4e0174b0b0d434ca0b142651c5e22d Mon Sep 17 00:00:00 2001 From: uvtqt Date: Wed, 18 Nov 2026 16:07:12 +0100 Subject: [PATCH 2/3] report: keep the raw record frontier for strap-clock diagnosis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lastRecordAt now drops a sub-floor frontier (a never-set strap RTC) so the UI no longer shows a 1970/2019 date — but the support report read only that getter, so support lost the very value that reveals the clock state (#758 review). Add a recordFrontierTs getter that keeps the raw rec_ts_hw and include it in the report; the display getter stays validated. Co-Authored-By: Claude Opus 4.8 --- lib/state/app_state.dart | 6 ++++++ lib/support/issue_report.dart | 3 +++ 2 files changed, 9 insertions(+) diff --git a/lib/state/app_state.dart b/lib/state/app_state.dart index e5863af01..09b21ffd6 100644 --- a/lib/state/app_state.dart +++ b/lib/state/app_state.dart @@ -6401,6 +6401,12 @@ class AppState extends ChangeNotifier { bool get syncingNow => _sync.syncingNow; DateTime? get lastRecordAt => _sync.lastRecordAt; + /// The raw record frontier (`rec_ts_hw`), including a sub-floor value from a + /// strap whose RTC was never set. [lastRecordAt] drops that for display; + /// diagnostics (the support report) keep it, since it is what tells support + /// the strap's clock state. + int? get recordFrontierTs => _sync.lastRecTs; + /// A derive job is running RIGHT NOW — the backlog just landed and the /// pipeline is computing what it means. Surfaced so a screen sitting on /// "nothing yet" can say it is being worked on rather than looking dead. diff --git a/lib/support/issue_report.dart b/lib/support/issue_report.dart index 2de999227..a9e653ab1 100644 --- a/lib/support/issue_report.dart +++ b/lib/support/issue_report.dart @@ -321,6 +321,9 @@ Future<({File zip, Map meta})> collectReport( 'busy': app.busy, 'lastDataAt': _iso(app.lastDataAt), 'lastRecordAt': _iso(app.lastRecordAt), + // Raw frontier too: _iso/lastRecordAt drop a sub-floor value (a never-set + // strap RTC), which is exactly the clock state support needs to see. + 'recordFrontierTs': app.recordFrontierTs, 'deriving': app.deriving, 'derivePending': app.derivePending, 'standardHrFallback': d.standardHrFallback, From 73bee7202fc82a5e1f9323e74518c13b52273058 Mon Sep 17 00:00:00 2001 From: uvtqt Date: Wed, 18 Nov 2026 16:17:12 +0100 Subject: [PATCH 3/3] devices/home: show 'time unknown' for banked data with a never-set strap RTC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to #758. A sub-floor frontier made lastRecordAt null, so the device row read 'Nothing banked yet' and Home 'No band data yet' — but records WERE banked, only with an unusable timestamp. New pure recordTimestampUntrusted predicate distinguishes a positive sub-floor frontier from a truly missing one; AppState.bandRecordTimeUnknown threads it to the device 'Last data' row ('Time unknown' + why) and Home's sync line ('Band data, clock not set'). Co-Authored-By: Claude Opus 4.8 --- lib/l10n/app_de.arb | 3 +++ lib/l10n/app_en.arb | 12 ++++++++++ lib/state/app_state.dart | 7 +++++- lib/sync/sync_policy.dart | 9 ++++++++ lib/ui2/profile/devices.dart | 37 +++++++++++++++++++++++------- lib/ui2/screens/home_screen.dart | 21 ++++++++++++++--- test/home_synced_through_test.dart | 3 +++ test/sync_policy_test.dart | 13 +++++++++++ 8 files changed, 93 insertions(+), 12 deletions(-) diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 387e2646b..25d0ecabe 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -239,6 +239,8 @@ "devicesWhatItDoes": "Was er beiträgt", "devicesLastData": "Letzte Daten", "devicesNothingBankedYet": "Noch keine Daten gespeichert", + "devicesTimeUnknown": "Zeit unbekannt", + "devicesClockNotSetSub": "Das Band hat Daten aufgezeichnet, aber seine Uhr ist nicht gestellt", "devicesSyncNow": "Jetzt synchronisieren", "devicesSyncNowSub": "Abrufen, was noch auf dem Gerät liegt", "devicesSyncNowSubListen": "Empfangen, was es gerade sendet", @@ -1639,6 +1641,7 @@ "homeNothingDerivedBody": "Es wurden noch keine Daten vom Band verarbeitet.", "homeSyncedThrough": "Synchronisiert bis {when}", "homeSyncedNever": "Noch keine Daten vom Band", + "homeSyncedTimeUnknown": "Banddaten, Uhr nicht gestellt", "homeSyncingTitle": "Synchronisierung mit deinem Band", "homeSyncingBody": "Daten werden geladen – bei vielen ausstehenden Daten kann das ein paar Minuten dauern.", "homeAnalyzingTitle": "Die letzte Nacht wird ausgewertet", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4e83d12d2..5f21de581 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1009,6 +1009,14 @@ "description": "Row title." }, "devicesNothingBankedYet": "Nothing banked yet", + "devicesTimeUnknown": "Time unknown", + "@devicesTimeUnknown": { + "description": "Last-data value when the strap banked records but its clock was never set, so the timestamp is unusable." + }, + "devicesClockNotSetSub": "The strap recorded data but its clock is not set", + "@devicesClockNotSetSub": { + "description": "Sub-label under 'Time unknown' explaining why the last-data time is missing." + }, "@devicesNothingBankedYet": { "description": "Row sub: no data yet." }, @@ -7790,6 +7798,10 @@ } }, "homeSyncedNever": "No band data yet", + "homeSyncedTimeUnknown": "Band data, clock not set", + "@homeSyncedTimeUnknown": { + "description": "Home sync line when the strap banked records but its clock is unset, so how far the data reaches is unknown." + }, "@homeSyncedNever": { "description": "Home header line when no record has ever been banked from a band." }, diff --git a/lib/state/app_state.dart b/lib/state/app_state.dart index 09b21ffd6..68452bdd3 100644 --- a/lib/state/app_state.dart +++ b/lib/state/app_state.dart @@ -139,7 +139,8 @@ import '../sync/paired_device.dart'; import '../sync/sync_policy.dart' show BandPromptPolicy, - BandPromptRequest; + BandPromptRequest, + recordTimestampUntrusted; import '../sync/update_service.dart'; import '../telemetry/telemetry_service.dart'; import '../telemetry/health_uploader.dart'; @@ -6407,6 +6408,10 @@ class AppState extends ChangeNotifier { /// the strap's clock state. int? get recordFrontierTs => _sync.lastRecTs; + /// Records were banked but their timestamp is unusable (a never-set strap + /// RTC), so "last data" is neither a date nor "nothing banked yet". + bool get bandRecordTimeUnknown => recordTimestampUntrusted(recordFrontierTs); + /// A derive job is running RIGHT NOW — the backlog just landed and the /// pipeline is computing what it means. Surfaced so a screen sitting on /// "nothing yet" can say it is being worked on rather than looking dead. diff --git a/lib/sync/sync_policy.dart b/lib/sync/sync_policy.dart index a6d070269..affe88326 100644 --- a/lib/sync/sync_policy.dart +++ b/lib/sync/sync_policy.dart @@ -394,6 +394,15 @@ DateTime? plausibleRecordInstant(int? tsSec) => ? null : DateTime.fromMillisecondsSinceEpoch(tsSec * 1000); +/// True when a record frontier exists but its time cannot be trusted: a +/// positive `rec_ts_hw` below the plausible floor, which is what a strap whose +/// RTC was never set banks (factory-epoch records). It means data WAS recorded — +/// so "nothing banked yet" is wrong — but its timestamp is unusable, which is +/// different again from a plausible frontier. [plausibleRecordInstant] returns +/// null for both this and a truly missing frontier; this tells them apart. +bool recordTimestampUntrusted(int? tsSec) => + tsSec != null && tsSec > 0 && tsSec < kMinPlausibleUnix; + /// A stricter, single-purpose sanity check for a band-reported "newest /// record" timestamp (GET_DATA_RANGE's `range_newest`) that sits implausibly /// far in the future — the signature of a corrupt/never-set strap RTC. diff --git a/lib/ui2/profile/devices.dart b/lib/ui2/profile/devices.dart index b4fe9ba2e..bfe9e6ef6 100644 --- a/lib/ui2/profile/devices.dart +++ b/lib/ui2/profile/devices.dart @@ -851,6 +851,9 @@ class HealthSource { /// sleep, recovery and temperature are all still abstaining. final bool isBand; + /// Band only: data was banked but its timestamp is untrusted (unset RTC). + final bool timeUnknown; + /// The `device` row this source is, for a paired sensor. Null for the /// primary band (whose row is `LocalDb.kPrimaryDeviceId`, `''`) and for the /// phone. It is the `device_id` every measurement this source wrote carries, @@ -889,6 +892,7 @@ class HealthSource { this.batteryPackPct, this.lastData, this.isBand = false, + this.timeUnknown = false, this.deviceId, this.family, this.flagOff = false, @@ -1030,6 +1034,7 @@ List liveSources(AppState app, batteryPackPct: app.device.batteryPackPct, lastData: app.lastRecordAt, isBand: true, + timeUnknown: app.bandRecordTimeUnknown, // The stored generation when no link has come up this launch, so a // disconnected band keeps its family-gated rows (Worn on, signals). family: app.device.generation ?? app.paired?.generation, @@ -2627,10 +2632,18 @@ class DeviceDetailView extends StatelessWidget { ], SetRow(LucideIcons.refreshCw, C.purple, l?.devicesLastData ?? 'Last data', - value: last == null ? '' : formatDayTime(last, l), - sub: last == null - ? (l?.devicesNothingBankedYet ?? 'Nothing banked yet') - : '', + value: last != null + ? formatDayTime(last, l) + : s.timeUnknown + ? (l?.devicesTimeUnknown ?? 'Time unknown') + : '', + sub: last != null + ? '' + : s.timeUnknown + ? (l?.devicesClockNotSetSub ?? + 'The strap recorded data but its clock is not set') + : (l?.devicesNothingBankedYet ?? + 'Nothing banked yet'), chevron: false), // A wearable with a column in the metric x device // table: what we measure from it, and its own values. @@ -2767,10 +2780,18 @@ class DeviceDetailView extends StatelessWidget { ], SetRow(LucideIcons.refreshCw, C.purple, l?.devicesLastData ?? 'Last data', - value: last == null ? '' : formatDayTime(last, l), - sub: last == null - ? (l?.devicesNothingBankedYet ?? 'Nothing banked yet') - : '', + value: last != null + ? formatDayTime(last, l) + : s.timeUnknown + ? (l?.devicesTimeUnknown ?? 'Time unknown') + : '', + sub: last != null + ? '' + : s.timeUnknown + ? (l?.devicesClockNotSetSub ?? + 'The strap recorded data but its clock is not set') + : (l?.devicesNothingBankedYet ?? + 'Nothing banked yet'), chevron: false), if (calibration != null) ...[ Divider(color: p.line, height: 1), diff --git a/lib/ui2/screens/home_screen.dart b/lib/ui2/screens/home_screen.dart index c458117ce..f60a3354e 100644 --- a/lib/ui2/screens/home_screen.dart +++ b/lib/ui2/screens/home_screen.dart @@ -231,6 +231,16 @@ DateTime? lastDataAtOf(BuildContext c) { } } +/// Records banked but their time untrusted (a never-set strap RTC) — distinct +/// from no data at all. Drives the "clock not set" variant of the sync line. +bool bandRecordTimeUnknownOf(BuildContext c) { + try { + return c.select((a) => a.bandRecordTimeUnknown); + } catch (_) { + return false; + } +} + /// "Synced through 11:06" — the one line that answers "how far are we?". /// /// It reads the BAND's clock, so it says how far the DATA reaches. That is a @@ -250,8 +260,12 @@ DateTime? lastDataAtOf(BuildContext c) { /// otherwise — a lone "07:12" against a strap not worn since Friday is the /// most misleading thing this line could say. String syncedThroughLabel(DateTime? at, String? todayId, - [AppLocalizations? l]) { - if (at == null) return l?.homeSyncedNever ?? 'No band data yet'; + [AppLocalizations? l, bool timeUnknown = false]) { + if (at == null) { + return timeUnknown + ? (l?.homeSyncedTimeUnknown ?? 'Band data, clock not set') + : (l?.homeSyncedNever ?? 'No band data yet'); + } final today = todayId == null ? null : DateTime.tryParse(todayId); final isToday = today != null && at.year == today.year && @@ -314,7 +328,8 @@ Widget? batteryLine(BuildContext c) { Widget syncedThroughLine(BuildContext c, String? todayId, [AppLocalizations? l]) { return Text( - syncedThroughLabel(lastDataAtOf(c), todayId, l), + syncedThroughLabel( + lastDataAtOf(c), todayId, l, bandRecordTimeUnknownOf(c)), style: F.cap.copyWith(color: P.of(c).ink3), ); } diff --git a/test/home_synced_through_test.dart b/test/home_synced_through_test.dart index 302081648..c140aa8f6 100644 --- a/test/home_synced_through_test.dart +++ b/test/home_synced_through_test.dart @@ -59,5 +59,8 @@ void main() { test('nothing banked says so plainly', () { expect(syncedThroughLabel(null, today), 'No band data yet'); + // Records banked but the strap's clock was never set: not "no data". + expect(syncedThroughLabel(null, today, null, true), + 'Band data, clock not set'); }); } diff --git a/test/sync_policy_test.dart b/test/sync_policy_test.dart index 3150380ac..c087f5b74 100644 --- a/test/sync_policy_test.dart +++ b/test/sync_policy_test.dart @@ -9,6 +9,19 @@ import 'package:openstrap_edge/sync/sync_policy.dart'; void main() { const wall = 1750000000; // a plausible "now" (2025-06) + group('untrusted record frontier', () { + // A strap with a never-set RTC banks factory-epoch records: the frontier is + // positive but below the floor, so data exists yet its time is unusable. + test('a positive sub-floor frontier is untrusted, not absent', () { + expect(recordTimestampUntrusted(null), isFalse); + expect(recordTimestampUntrusted(0), isFalse); + expect(recordTimestampUntrusted(1), isTrue); // ~1970 + expect(recordTimestampUntrusted(kMinPlausibleUnix - 1), isTrue); + expect(recordTimestampUntrusted(kMinPlausibleUnix), isFalse); + expect(recordTimestampUntrusted(1750000000), isFalse); // plausible + }); + }); + group('record frontier as a display instant', () { // A strap whose RTC was never set banks factory-epoch records. The cursor // and the "last data" getter guard only `> 0` / `!= null`, so that frontier