E295 The CBio live surface can never be fresh: it is judged by a sensor clock the protocol does not carry · Issue #174 · shroominic/OpenGlucose · GitHub
[go: up one dir, main page]

Skip to content

The CBio live surface can never be fresh: it is judged by a sensor clock the protocol does not carry #174

Open

Description

@shroominic

What breaks

openhealth/lib/src/live_activity_payload.dart decides whether a live surface is
stale from the reading's own clock:

final displayRecordedAt = clampedDisplayRecordedAt(reading?.recordedAt, now: effectiveNow);
final isStale =
    displayRecordedAt == null ||
    effectiveNow.difference(displayRecordedAt) > const Duration(minutes: 10);

The CBio/GS1 session publishes recordedAt: null on every record by design:
the protocol's per-record field is the sensor's minute counter, not an epoch
(issue #146, PR #171). So displayRecordedAt == null and the surface is stale
forever, however recently bytes actually arrived.

The gap is compounded one branch earlier: a cbio reading is released as
CgmRecordSource.raw + isDisplayProvisional, so the payload builder returns
the provisional branch, which hard-codes isStale: true. Both paths need the
same honest clock; neither can get one from the sensor.

Evidence

Tree Command Result
fix/cbio-live-freshness @ 17db5b4 (base) flutter test test/cbio_live_freshness_test.dart exit 1, +3 -1
same, full flutter test on the base exit 0, +484 (defect is unobserved, not absent)

The RED assertion is exact:

Expected: false
  Actual: <true>
  a batch accepted 30 s ago is a fresh surface
test/cbio_live_freshness_test.dart 60:5

A GS1 batch ingested 30 s ago and a session that has ingested nothing produce
the same isStale. The surface cannot distinguish an idle link from a live one.

Why it matters

The staleness flag is what tells a user whether the number on the lock screen is
current. For this sensor it is a constant, so the one control that exists to
catch a dead link reports "stale" on a healthy link and reports nothing useful at
all. It also means any later lane that starts publishing cbio to the lock screen
inherits a permanently-stale contract.

Next step

Derive cbio freshness from the receipt clock — CgmHistorySyncState.lastSyncAt,
which the session already advances on accepted ingest and resets per session —
and keep it strictly separate from the sensor timestamps published in
recordedAtIso8601. Receipt time must never be presented as a sensor time.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0