Skip to content

Background scanning and restoration#44

Merged
itsniper merged 4 commits into
masterfrom
38-background-scanning
Jul 18, 2026
Merged

Background scanning and restoration#44
itsniper merged 4 commits into
masterfrom
38-background-scanning

Conversation

@itsniper

Copy link
Copy Markdown
Member

Plan: docs/plans/background-scanning-state-restoration-2026-07-13.md

Closes #38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements CoreBluetooth state restoration scaffolding (restore identifier plumbing + willRestoreState handling) and documents background scanning requirements so ReliaBLE can continue discovery/rehydrate scan + connection state across app termination, aligning with Issue #38 (FR-8.3).

Changes:

  • Adds ReliaBLEConfig.restoreIdentifier and threads it through ReliaBLEManagerBluetoothActor to create the central with CBCentralManagerOptionRestoreIdentifierKey.
  • Implements delegate/event plumbing and restoration handling (willRestoreState) to rehydrate peripherals, seed connection state, and resume restored scans (with deferral until powered on).
  • Adds DocC guidance + demo app configuration for bluetooth-central background mode; expands test coverage around restoration behavior.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Tests/ReliaBLETests/ReliaBLEManagerTests.swift Adds unit tests for restore-identifier behavior and restoration rehydration/broadcasting.
Sources/ReliaBLE/ReliaBLEManager.swift Passes restore identifier into actor initialization.
Sources/ReliaBLE/ReliaBLEConfig.swift Introduces restoreIdentifier config surface with documentation.
Sources/ReliaBLE/BluetoothActor.swift Adds restoration event plumbing + rehydration logic + restored scan resumption.
Sources/ReliaBLE/Documentation.docc/Topics/Background.md New DocC topic describing background scanning + restoration setup and behavior.
Sources/ReliaBLE/Documentation.docc/GettingStarted.md Links to the new Background topic.
Sources/ReliaBLE/Documentation.docc/Documentation.md Adds Background topic to the docs navigation structure.
docs/plans/background-scanning-state-restoration-2026-07-13.md Captures implementation plan and decisions for FR-8.3.
docs/reviews/background-scanning-state-restoration-plan-critique-2026-07-13.md Plan critique notes and implementation risks/seams.
Demo/ReliaBLE Demo/ReliaBLE-Demo-Info.plist Enables bluetooth-central background mode and updates usage description.
Demo/ReliaBLE Demo/ReliaBLE Demo/ReliaBLE_DemoApp.swift Sets a stable restore identifier in the demo configuration.
Demo/ReliaBLE Demo/ReliaBLE Demo/Central/CentralViewModel.swift Defaults scan services input to a non-empty UUID for background-compatible scans.
Demo/ReliaBLE Demo/ReliaBLE Demo/Central/CentralView.swift Updates UI copy and displays connection state to support restoration demo flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/ReliaBLE/BluetoothActor.swift
Comment thread Sources/ReliaBLE/BluetoothActor.swift Outdated
@itsniper
itsniper force-pushed the 38-background-scanning branch from 8e95480 to 146cd79 Compare July 15, 2026 16:34
itsniper and others added 4 commits July 16, 2026 02:13
- Persist per-connect autoReconnect intent to UserDefaults (namespaced by
  restore identifier) so willRestoreState only re-arms Tier-1 reconnect for
  peripherals connected with autoReconnect: true; connections made with
  autoReconnect: false are restored without re-arming the library ladder
- Stop emitting restored peripherals on the peripheralDiscoveries feed —
  restoration carries no advertisement or RSSI, so restored devices surface
  via discoveredPeripherals and connectionStateChanges only
- Ignore (and warn on) an empty restored scan service filter instead of
  re-issuing a background-useless scan
- Warn when a later ensureInitialized supplies a different restoreIdentifier
  than the one captured at first initialization
- Extract centralManagerCreationOptions() and assert restore-key wiring at
  the unit level (end-to-end factory option fidelity deferred to #42)
- Clear the persisted intent mirror in invalidatePeripherals so
  restore → unauthorized also drops cross-launch reconnect intent
- Docs: eager-creation note cross-referenced in Concurrency.md; Background.md
  updated for persisted intent, discovery-feed behavior, and the deferred
  GATT delegate re-wire on restore
- Tests: persisted-intent restore coverage (armed / not armed), empty
  restored scan filter, invalidatePeripherals clearing restored state

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The willRestoreRepopulatesMapsSeedsConnectionStateAndBroadcasts test could
hang forever in Xcode/CI (30-min timeout) while passing on CLI. The
connectionStateChanges stream does not replay, and its continuation is
registered asynchronously via a detached @BluetoothActor hop. The test's
single actor hop was not enough slack to guarantee the subscription landed
before the synchronous restore broadcast, so the .connected event was
dropped and connectionChanges.next() blocked indefinitely.

Add testConnectionStateSubscriberCount()/testPeripheralsSubscriberCount()
accessors and poll until both subscriptions have registered before invoking
restore. The event is then buffered and next() returns deterministically;
the test now passes fast or fails fast within 3s instead of hanging CI.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@itsniper
itsniper force-pushed the 38-background-scanning branch from 274f52a to fd45619 Compare July 16, 2026 02:13
@itsniper
itsniper merged commit 9ccb5be into master Jul 18, 2026
3 checks passed
@itsniper
itsniper deleted the 38-background-scanning branch July 18, 2026 22:47
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.

FR-8.3: Background scanning support

2 participants