8000 fix(ble): complete nearby-sensor scans at a registry-owned deadline by shroominic · Pull Request #130 · shroominic/OpenGlucose · GitHub
[go: up one dir, main page]

Skip to content

fix(ble): complete nearby-sensor scans at a registry-owned deadline - #130

Closed
shroominic wants to merge 1 commit into
feature/libre-protocol-capturefrom
fix/nearby-sensor-scan-surfacing
Closed

shroominic wants to merge 1 commit into
feature/libre-protocol-capturefrom
fix/nearby-sensor-scan-surfacing

Conversation

@shroominic
Copy link
Copy Markdown
Owner

Fixes #129.

Root cause

AppController.scan() drives a StreamIterator loop over the registry's discovery stream. FlutterBluePlusTransport.scan builds its stream from flutter_blue_plus' scanResults and only closes it on the isScanning == false transition. On the Pixel 6, flutter_blue_plus stopped the physical scan without emitting that transition, so the transport stream never closed, the discovery loop never returned, and the Connect-a-sensor panel spun forever.

Device evidence: one LOW_LATENCY scan ran the full 6006 ms requested timeout and delivered scan results while the UI stayed in the scanning state with no candidates shown. The panel's waiting branch renders the empty state, but it is only reachable once scanning is false, so a scan that never completes hides every discovered sensor behind the spinner.

Fix

  • The registry now owns the scan deadline (_activeScanTimeout + _completeScanAtDeadline): a scan that reaches its requested timeout ends even when the transport stream stays open, so every consumer observes completion.
  • Transport cancellation is bounded by _scanCancellationTimeout, so a transport that cannot confirm its own cancellation cannot hold the scan lifecycle (and the UI) open. Confirmed cancellations still fail closed and stay latched.
  • A deadline reached during vendor discovery setup still ends the scan and cannot be resurrected when that setup later resolves.
  • Scan transitions are reported through an assert-gated, identity-free _debugScanStep helper for debug builds only.

RED to GREEN tests

  • test/cgm_driver_registry_test.dart
    • a scan completes at its timeout when the transport never closes
    • a deadline reached during discovery setup still ends the scan
    • a transport that never confirms cancellation stays bounded and the next scan still reaches the transport
  • test/app_controller_persistence_test.dart
    • a wedged physical scan cannot leave the controller scanning

Verification

  • Focused suites: All tests passed! (exit 0).
  • flutter analyze: No issues found!
  • Pixel 6 (adb -s 100.127.252.5:5555) with this build installed: tapping Connect a sensor now ends the spinner and the panel renders "No Bluetooth sensors found / Keep the sensor close and try again." with a retry control and "Can't find your sensor?".

Remaining gap (out of scope, not claimed fixed)

This change makes scans complete; it does not claim discovery yield. A separate measurement in the same window showed filtered scans yielding 0 candidates while an unfiltered plugin scan saw 69 advertisements including the FF30 sensor. Discovery yield under withServices filtering is still open and is tracked separately.

FlutterBluePlusTransport.scan's stream can stay open when flutter_blue_plus stops the physical scan without emitting isScanning == false, so the discovery loop never returned and the Connect-a-sensor panel kept scanning forever.

The registry now owns the scan deadline (_activeScanTimeout + _completeScanAtDeadline) so an overrun scan still ends for every consumer, bounds transport cancellation so a wedged cancel cannot hold the lifecycle open, and keeps an assert-gated, identity-free scan diagnostic for debug builds.
@shroominic
Copy link
Copy Markdown
Owner Author

Carried by the GS1 consolidation in PR #209 (branch feature/cbio-gs1, head 3eca4f4).

This PR is contained in the consolidated line; the merge that carries it is c85f827.

Closing as subsumed by the consolidation - not as won't fix. The per-defect evidence stays in this thread, and the carrying commit above is where the change now lives.

@shroominic shroominic closed this Sep 18, 2026
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.

1 participant

0