Background scanning and restoration#44
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.restoreIdentifierand threads it throughReliaBLEManager→BluetoothActorto create the central withCBCentralManagerOptionRestoreIdentifierKey. - 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-centralbackground 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.
itsniper
force-pushed
the
38-background-scanning
branch
from
July 15, 2026 16:34
8e95480 to
146cd79
Compare
- 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
force-pushed
the
38-background-scanning
branch
from
July 16, 2026 02:13
274f52a to
fd45619
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plan:
docs/plans/background-scanning-state-restoration-2026-07-13.mdCloses #38