Repository navigation
fix: connect bluetooth nearby payments at close range - #1568
Conversation
The scanner connected only at -60 dBm or stronger. In paired QA an iPhone saw a Galaxy S22's Receive screen at -75 to -63 dBm side by side, connecting only at -58 dBm with the top corners pressed together. Accept -75 dBm, as on Android. A Bluetooth request still opens the send review and never QuickPay. Verified: none (needs two physical phones)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge. SummaryLowers the Bluetooth connection threshold from −60 to −75 dBm so nearby phones can connect more easily.
Reviews (1) · Last reviewed commit: "fix: connect bluetooth nearby payments a..." · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Lowers the nearby-payments RSSI gate from -60 to -75 dBm on the iOS scanner, matching synonymdev/bitkit-android#2225. Reviewed f909155, light tier, static: iOS does not build here.
What I checked, and 1 candidate I ruled out
Read in full: NearbyProtocol.swift, NearbyPaymentScanner.swift (isEligible, candidate selection), NearbyProtocolTests.swift
Call sites traced: NearbyProtocol.minRssi has one reader, NearbyPaymentScanner.isEligible; the 127 "unavailable" sentinel is still excluded, and the test moves the boundary pair to -75 / -76
Parity: both copies of nearby-payments.md carry the same line; the Android advertiser power change in the twin has no iOS counterpart because CoreBluetooth does not expose advertising TX power
CI: SwiftFormat and validate green; Run Tests and Run Integration Tests still running at review time
Ruled out
- Wrong-phone pickup at the wider gate:
max(by: rssi)over the selection window still takes the strongest candidate, and a Bluetooth request always opens the send review; the closest-phone heuristic is declared out of scope.
Merge confidence: 4/5, no findings but unit tests had not finished when this was posted.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the runtime does not report it to the reviewer)
A failed connect or read skipped the same phone for 10 s, which hits while the phones are being brought together. Retry it after 2 s; a completed read still waits 10 s. Verified: none (iOS tests left to CI)
coreyphillips
left a comment
There was a problem hiding this comment.
Two independent reviews, nothing blocking a merge.
Verified: none (iOS tests left to CI)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at f909155.
No new actionable code findings.
No actionable code findings. The payer connects at −75 dBm instead of −60 dBm. isEligible accepts a reading at or above that gate and rejects CoreBluetooth's unavailable sentinel, 127. NearbyProtocolTests expects −75 to be eligible and −76 to be rejected. A Bluetooth request still enters beginNearbyScan, which holds QuickPay suppression until the send route is chosen, so the payment opens on the normal send review. The scanner still keeps the strongest reading from the 0.3s selection window.
Compared with bitkit-android#2225 at 29e519a2bdd2138ea303e13e19326476690d9aa6, limited to this gate and the shared document. Both apps use −75 dBm, and the two nearby-payments.md copies are identical. That Android revision also sets advertise TX power to high. iOS starts advertising with the service UUID only; CoreBluetooth provides no advertise TX power control.
Ready for device testing. Device testing was not performed in this review. The simulator has no Bluetooth, so the author's two-phone checks are the runtime plan. Use an Android build that includes the twin's high advertise power for the iPhone-scanner cases: the −75 to −63 dBm side-by-side readings on the PR were taken while Android advertised at low power, and the across-the-room check is what shows that −75 dBm stays limited to a nearby phone.
The unit-test workflow was still running on this revision (Run Tests), so this review uses the test source rather than that run.
Reviewer model: grok-4.7
Reasoning effort: xhigh
|
Pushed 410d28c and b4c1708: a failed connect or read now retries the same phone after 2 s instead of 10 s; a completed read still waits 10 s. A failure is most likely while the phones are being brought together, so the 10 s skip kept a close phone out of reach. Covered in synonymdev/bitkit-android#2225 keeps 10 s: each Android attempt restarts the scan and Android ignores a sixth scan start within 30 s, so its retry could only drop to 8 s. |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since f909155, including affected code paths and prior findings, at b4c1708. Baseline: QA review.
No new actionable code findings.
No new actionable code findings in the follow-up.
A failed connect or read now stores failedAttemptDate, eight seconds before the failure, so the existing 10 second debounce lets that phone be read again 2 seconds later. A completed read keeps the timestamp from the start of the connection and waits 10 seconds. The retry only updates that timestamp; a delivered Bluetooth request still enters beginNearbyScan, which suppresses QuickPay until the send route is chosen. NearbyProtocolTests covers the 2 second debounce math. Prior reviews on f909155 reported no findings.
Compared with bitkit-android#2225 at eec5a62bb51483306d4a4985215e4cbf204d37bd, limited to this retry and the shared gate. Android's finish still skips the device for 10 seconds after a failed read and starts a new scan. The author reports Android keeps that interval because a sixth scan start within 30 seconds is ignored. The two nearby-payments.md copies remain identical and do not state a retry interval. Inherited from the baseline: the −75 dBm gate, eligibility, strongest-candidate selection, the shared document, and the changelog fragment.
Ready for device testing. Device testing was not performed in this review. The simulator has no Bluetooth. Run Tests was still in progress on this revision, so this review uses the test source rather than that run.
Suggested additional test cases
- iPhone scanner, Android Receive, on an Android build that includes the twin's high advertise power. Let the first connect or read fail while the phones are brought together, then hold them side by side. The payment review should open about 2 seconds after that failure. After a review opens, that phone should stay unread for 10 seconds.
Reviewer model: grok-4.7
Reasoning effort: xhigh
@piotr-iohk Added to Manual Tests. |
piotr-iohk
left a comment
There was a problem hiding this comment.
Bluetooth device QA on regtest on iOS b4c1708c9d92 and Android twin eec5a62bb514, using an iPhone 13 and Galaxy S22 with camera access denied in both QA apps. The iPhone build used a separate QA bundle for signing and storage.
- Passed, both cross-platform directions. The iPhone opened the exact Galaxy 1,000-sat invoice. The Galaxy opened the exact iPhone 5,000-sat invoice and paid it after a deliberate swipe. The iPhone confirmed receipt.
- Passed, retry after a read failure. Briefly pausing the Android QA process triggered a real read timeout on the iPhone. After resuming the process, the same Galaxy GATT peer reconnected 2.43 seconds after disconnection and the matching 1,000-sat review opened.
- Passed, successful-read cooldown. With the scanner kept open by a valid invoice above the iPhone’s Spending balance, the app displayed the expected insufficient-funds message and consecutive GATT connections started 10.61 seconds apart. With the funded 1,000-sat review left open, the peer was read once in the 15-second observation.
- Blocked, 3-metre range. The iPhone read the Galaxy’s request at the available 1-metre separation. The specified 3-metre check remains open.
Gate and rank each phone on its lower median RSSI over a 500 ms window (at least 3 readings) instead of its strongest single reading, so one spike from a phone 10 m away no longer opens its request. Verified: SwiftFormat lint; two-phone run (Pixel 10 Pro, iPhone Air): side by side read both ways, Back did not reopen; iOS unit tests left to CI
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since b4c1708, including affected code paths and prior findings, at ee91b3b. Baseline: QA review.
No new actionable code findings.
No new actionable code findings in the follow-up. NearbyPaymentScanner now collects all non-127 RSSI readings over a 0.5 s selectionWindow and uses closest(_:) to pick the peer with the strongest lower median ((count - 1) / 2) at or above −75 dBm among peers with at least 3 readings (minReadings). Both candidates and readings are cleared whenever the window closes (including when no peer qualifies) and on stop(), while peers that fail the median gate remain undebounced so a phone moving closer is re-sampled on the next window. NearbyProtocolTests.testScannerPicksTheStrongestMedianInRange covers median selection over a higher single peak, single-spike rejection at −75 dBm, and rejecting peers with fewer than 3 readings. Inherited unchanged from the baseline: the 2 s retry after a failed read (failureRetryInterval, failedAttemptDate, fail stamp) and its debounce tests, delivery and QuickPay suppression (Scanner, ScannerManager.beginNearbyScan, ScannerScreen, SendOptionsView), and changelog.d/next/1568.fixed.md.
Existing review thread (non-blocking): discussion_r4759375073 (unresolved; approving reviewer marked it non-blocking) notes that NearbyPaymentScanner.fail (Bitkit/Services/NearbyPaymentScanner.swift:184-193) applies the 2 s retry to non-transient protocol errors (unsupported meta, service not found, missing characteristics, length mismatch) as well as transient drops. Verified in ee91b3b: an incompatible peer is retried about every 2.5 s instead of 10 s, without starving compatible peers.
Twin comparison: compared with bitkit-android#2225 at 71250fa for the median gate, Back-from-review cooldown, and shared doc. Both apps use −75 dBm, 500 ms window, at least 3 readings, the same lower-median formula, the same 4-case median test, and identical nearby-payments.md copies. On iOS, SendOptionsView and ScannerScreen keep NearbyPaymentScanner alive while paused across Back from the send review, so lastAttempts already preserves the 10 s cooldown (matching Android's new NearbySkips). Android intentionally keeps its 10 s post-failure retry because of Android scan-start rate limits.
Recommended before device testing: wait for Run Tests and Run Integration Tests to finish on ee91b3b (build-local and SwiftFormat passed; no local Swift/Xcode toolchain is available in this review environment, so NearbyProtocolTests was inspected from source), and resolve or close the non-blocking thread discussion_r4759375073.
Device testing: not performed in this review (code-only; the iOS simulator has no Bluetooth). Earlier physical QA (review 6137231681) ran on b4c1708 paired with Android eec5a62—before ee91b3b replaced peak selection with the 500 ms / 3-reading median gate—and had the 3 m range check blocked at 1 m. Re-run the physical two-phone manual checks on ee91b3b paired with Android 71250fa (side-by-side both directions, 1.5–3 m read and Back-from-review cooldown, and 10 m+ non-read).
Reviewer model: gemini-4-neon
Reasoning effort: high
When the 500 ms window ends with no phone in range and one still has fewer than 3 readings, keep collecting for another window, up to 2 s, so a close phone whose readings arrive slowly (Low Power Mode) still gets read. Verified: SwiftFormat lint; Release build for device; iOS unit tests left to CI
A missing characteristic, unsupported meta or length mismatch can't succeed on retry, so it keeps the 10 s pause instead of the 2 s retry meant for drops while the phones are brought together. Verified: SwiftFormat lint; iOS unit tests left to CI
coreyphillips
left a comment
There was a problem hiding this comment.
Rechecked after 2 new commits (a7b0148, 978ec5c). Nothing blocking remains.
addressed
- Protocol failures that cannot succeed on retry now retry every 2 s (Bitkit/Services/NearbyPaymentScanner.swift:184-193). Fixed: At
NearbyPaymentScanner.swift:205-210,fail(_:retrySoon:)now stampsDate()(the fullretryInterval) whenretrySoonis false. I read every call site at HEAD. Missing meta (239), missing data (246), length mismatch (252), unsupported meta (291) and service not found (349) passretrySoon: false. Timeout (201), read error (286), failed connect (328), disconnect (335) and the discovery errors (346, 360) keep the 2 s default. One caveat on my own earlier list: against an Android Receive phone, which does not snapshot its request per central, a length mismatch can come from the request changing mid-read, so a retry could fix it. That race is rare, and 10 s is what master already did, so this doesn't reopen the point.
new since the last review
nits
- Doc and header say the window extends whenever a peer is short of readings (Docs/nearby-payments.md:46-49)
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since ee91b3b, including affected code paths and prior findings, at 978ec5c. Baseline: QA review.
No new actionable code findings.
No new actionable code findings in the follow-up. NearbyPaymentScanner now tracks selectionStartedAt on the first discovery of an empty window and keeps rescheduling connectToStrongest every 0.5 s up to maxSelectionWindow (2 s) while closest(readings) is nil, central != nil, connected == nil, and needsMoreReadings(readings) reports any peer with fewer than 3 readings; bestID is evaluated before the 2 s cutoff, and candidates/readings are cleared when the window closes or on stop(). fail(_:retrySoon:) now keeps the full 10 s retryInterval (Date()) for protocol failures (service not found, missing meta characteristic, missing data characteristic, unsupported meta, request does not match its announced length) while keeping the 2 s failureRetryInterval for transient BLE failures (timeout, failed connect, disconnect, discovery errors, and read errors). NearbyProtocolTests.testScannerKeepsCollectingWhileAPeerHasTooFewReadings covers needsMoreReadings(_:). Inherited unchanged from the baseline: the −75 dBm median gate and closest(_:) selection, isEligible / median / 2 s debounce tests, stop() and Back-from-review debounce retention across SendOptionsView/ScannerScreen/ScannerSheet, delivery and QuickPay suppression (Scanner, ScannerManager.beginNearbyScan), and changelog.d/next/1568.fixed.md.
Reconciled review threads:
- discussion_r4759375073 (resolved): verified fixed in 978ec5c across all 5 protocol-failure call sites in
NearbyPaymentScanner.swift. - discussion_r4759815359 (unresolved, non-blocking nit from approving review): notes that
Docs/nearby-payments.md:46-49andNearbyPaymentScanner.swift:9-10say the window extends while a peer has fewer than 3 readings, whereasNearbyPaymentScanner.swift:183(matching AndroidNearbyScanner.kt:119) extends only whenbestID == nil(no peer qualifies yet). Verified against source; intentional code behavior with minor prose imprecision.
Twin comparison: compared with synonymdev/bitkit-android#2225 at 7b69f70 for the 2 s window extension, needsMoreReadings test, and shared doc. Both apps use the same 500 ms / 2 s extension condition (bestID == nil / closest == null), identical needsMoreReadings unit assertions, and byte-identical nearby-payments.md copies. Android intentionally keeps a 10 s retry for all attempts due to OS scan-start rate limits.
Recommended before device testing: wait for Run Tests, build-local, and Run Integration Tests to complete on 978ec5c (SwiftFormat and validate passed; no local Swift/Xcode toolchain is available in this review environment, so NearbyProtocolTests was inspected from source), and resolve or address the non-blocking prose nit in discussion_r4759815359.
Device testing: not performed in this review (code-only; the iOS simulator has no Bluetooth). Earlier physical QA (review 6137231681) ran on b4c1708 paired with Android eec5a62—before ee91b3b, a7b0148, and 978ec5c—and had the 3 m range check blocked at 1 m. Re-run the physical two-phone manual checks on 978ec5c paired with Android 7b69f70 (side-by-side both directions, 1.5–3 m read with Back-from-review cooldown, 10 m+ non-read, and 2 s transient-failure retry / 10 s post-open cooldown).
Reviewer model: gemini-4-neon
Reasoning effort: high
piotr-iohk
left a comment
There was a problem hiding this comment.
Passed the cross-platform Bluetooth follow-up on 978ec5cccd79 using an iPhone 13 and a Galaxy S22 running Android #2225 at 7b69f70c78ac. Both ran regtest builds.
- iPhone on Receive. It kept the same 1,000-sat invoice available while the Galaxy opened review, returned to Send, and read it again. The Galaxy reconnected 10.51 s after its first read and delivered the second read at 12.43 s. The second review contained the exact advertised invoice.
- iPhone on Send. The Galaxy advertised its own 1,000-sat regtest invoice. The iPhone opened manual payment review, and its full recipient field matched the Galaxy invoice. The run stopped at review in both directions.
The timing above measures the Android scanner. The iOS scanner’s failure-retry timing and the 1.5–3 m and 10 m distance cases were outside this follow-up.
Test resultsTested on a Pixel 10 Pro (Android 17) and an iPhone Air (iOS 27.2.1) on mainnet. Each phone ran Median gate (ee91b3b)The head 978ec5c adds only the wait of up to 2 s for a phone with fewer than 3 readings and the full 10 s pause after protocol errors; these runs predate it.
iPhone Receive, Android scanner, 10 m or more
Android Receive, iPhone scanner, side by side
iPhone Receive, Android Send sheet, side by side, then Back
On the previous head (b4c1708): strongest single reading
iPhone Receive, Android scanner, 10 m or more (read on a spike)
Android Receive, iPhone scanner, touching
iPhone Receive, Android scanner, touching
QuickPay on, 5,000 sat request, touching
Android Receive, iPhone scanner, 2.5–3 m
iPhone Receive, Android scanner, 2.5–3 m
Back out of the review, iPhone payer, 1.5–2 m
Back out of the review, Android payer, 1.5–2 m
Two Android emulators (regtest, empty wallets)
|
|
Merging: approved on 978ec5c with CI green, and the cross-platform device run passed on this head paired with synonymdev/bitkit-android#2225. |
Twin: synonymdev/bitkit-android#2225
Refs: #1302
Description
Fix for the likely cause, tested on a Pixel 10 Pro and an iPhone Air with the phones touching and at a distance (results in the comments).
nearby-payments.md(both copies stay identical)Design
N/A — no UI changes.
Preview
N/A — no user-visible changes.
QA Notes
Journeys
N/A
Manual Tests
Automated Checks
NearbyProtocolTests.swift(−75 gate and −76 boundary, 2 s retry after a failed read, median ranking where a spike or too few readings never win)