From f523093ea0f20e4878760fa75364ae20f172f54b Mon Sep 17 00:00:00 2001 From: uvtqt Date: Wed, 18 Nov 2026 11:10:15 +0100 Subject: [PATCH 1/2] 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/2] 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,