Repository navigation
fix: connect bluetooth nearby payments at close range - #2225
Conversation
A paying phone connected only at -60 dBm or stronger, and Android advertised at ADVERTISE_TX_POWER_LOW (-15 dBm). In paired QA an iPhone saw a Galaxy S22 at -75 to -63 dBm side by side, connecting only at -58 dBm with the top corners pressed together. Accept -75 dBm, as on iOS, and advertise at high power. 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. |
Verified: none (file rename)
[Medium impact] The PR changes Bluetooth discovery in the nearby-payment workflow. The PR appears safe to merge, with a non-blocking request to test the scanner threshold. Findings
SummaryThis PR makes nearby Bluetooth payments easier to connect:
No current behavior defect was found. A non-blocking finding asks for a regression test of the scanner threshold. Acknowledgment: 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 and raises the Receive advertiser to ADVERTISE_TX_POWER_HIGH. Reviewed 29e519a, light tier, static: on this repo the PR branch is not built here, so this is read from the code and CI.
What I checked, and 2 candidates I ruled out
Read in full: NearbyAdvertiser.kt, NearbyProtocol.kt, the MIN_RSSI use in NearbyScanner.kt, NearbyAdvertiserTest.kt
Call sites traced: NearbyProtocol.MIN_RSSI has one reader, NearbyScanner.onCandidate; no other -60 literal stands in for it in app/src/main or the tests
Parity: the gate now matches synonymdev/bitkit-ios#1568, and both copies of nearby-payments.md carry the same line
CI: build-and-test, lint and compose-ui still running at review time
Ruled out
- Advertising power read by RSSI on the other side:
setIncludeTxPowerLevel(false)stays, and neither scanner computes distance from TX power, so the change moves RSSI only, which is the intent. - Wrong-phone pickup at the wider gate: the scanner still picks the strongest candidate over its window and a Bluetooth request always opens the send review (no QuickPay), as the PR states; the closest-phone heuristic is declared out of scope.
Merge confidence: 4/5, no findings but CI 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)
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: full PR diff against its merge base, at 29e519a.
No new actionable code findings.
The payer connects to an advertiser at −75 dBm or stronger, and Receive advertises at high transmit power. A Bluetooth read still opens the normal send review: nearby scanner callbacks pass suppressQuickPay, and handleQuickPayIfApplicable skips QuickPay when that flag is set. On bitkit-ios#1568 at f909155, only the connect gate, the shared nearby-payments.md sentence, and transmit-power parity were checked. Both apps use −75 dBm and the same doc sentence. iOS has no public transmit-power control; Android's move from low to high power is the Android-specific half.
Greptile's open thread asks for a unit test that the scanner accepts −75 dBm and rejects −76 dBm. NearbyScanner drops readings below MIN_RSSI (−75). No Android unit test asserts that boundary. The iOS twin tests it. The current threshold matches the documented gate.
Ready for device testing. The author's two-phone cases are the checks that exercise this change. Reading a request needs two physical phones; the send-scanner journey covers Bluetooth permission state and leaves the read as a manual test.
Device testing: not performed in this review. The author reports running NearbyAdvertiserTest; this review inspected that test and did not run it. Run the author's 3 m case as written: higher transmit power can make a phone across the room louder than the earlier low-power measurements, so record the phones and distance if a review opens.
Suggested additional test cases
- Android payer with QuickPay enabled, payment scanner open, another phone showing Receive beside it: the send review opens, and no payment is sent until the payer confirms.
- Two Android phones, one on Receive and one on the payment scanner, held side by side: the payment review opens within a few seconds. The author cases each pair one side with an iPhone, so this covers the louder advertiser and the wider gate together.
Reviewer model: grok-4.7
Reasoning effort: xhigh
Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.nearby.*' detekt
@piotr-iohk Added both to Manual Tests. The scanner gate test from Greptile's thread landed in eec5a62 (−74, −75 and −76 dBm). |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since 29e519a, including affected code paths and prior findings, at eec5a62. Baseline: previous review (unchanged NearbyAdvertiser, docs/nearby-payments.md, and changelog coverage inherited; NearbyProtocol, NearbyScanner, NearbyProtocolTest, and the send/scanner handoff reassessed).
1 actionable finding — resolve or provide an evidence-backed rebuttal.
The follow-up extracts NearbyProtocol.isInRange(rssi) (rssi >= MIN_RSSI), routes NearbyScanner.onCandidate through it, and adds boundary tests at −74, −75, and −76 dBm in NearbyProtocolTest.kt. Greptile's review thread is marked resolved and its test-coverage ask is verified in source and in CI on eec5a62 (build-and-test, lint, detekt); local Gradle execution was unavailable here because no Android SDK is installed in the review environment. QuickPay remains suppressed for Bluetooth reads across SendRecipientScreen, QrScanningSheet, and SendRoute.QrScanner.
Twin parity: On synonymdev/bitkit-ios#1568 at b4c1708, only the shared −75 dBm connect gate, nearby-payments.md, and send-scanner cooldown/retry contracts were checked (not a full iOS review). Both apps match on −75 dBm and have byte-identical nearby-payments.md. iOS added a 2 s retry after failed reads while Android keeps 10 s due to Android's 5-scans/30 s limit (documented out of scope). However, when backing out of send review to the Send recipient scanner, iOS keeps lastAttempts across NearbyPaymentScanner.stop() in SendOptionsView, whereas Android clears skippedUntil in NearbyScanner.stop() and recreates NearbyScanner on SendRecipientScreen recomposition, which would immediately reopen the review while a Receive phone remains within the widened 1.5–3 m range.
Recommended before device testing: Preserve per-device nearby cooldown across SendRecipientScreen pause/dispose and add a unit test covering cooldown retention across stop/restart before running the two-phone manual pass.
Device testing: not performed in this review. The author reports passing the checked two-phone manual cases and running ./gradlew testDevDebugUnitTest --tests 'to.bitkit.nearby.*' detekt; the two-Android-phones case remains unchecked and requires two physical Android devices.
Suggested additional test cases
- Android Send sheet back-out at 1.5–3 m: On an Android payer with Bluetooth enabled, open Send (
SendRecipientScreen, not the Home main scanner) while a Receive phone is 1.5–3 m away so the payment review (or amount screen for an amountless request) opens automatically; tap Back to return to the Send recipient screen while leaving the Receive phone in place. Expected: the payer stays on Send recipient long enough to choose Enter Manually, Paste, Contacts, or scan a QR code rather than immediately reopening the same review within ~1 s.
Findings
- [MEDIUM] Preserve nearby device cooldown when backing out to SendRecipientScreen — inline at
app/src/main/java/to/bitkit/nearby/NearbyScanner.kt:101.
Reviewer model: gemini-4-neon
Reasoning effort: high
piotr-iohk
left a comment
There was a problem hiding this comment.
Bluetooth device QA on regtest on Android eec5a62bb514 and iOS twin b4c1708c9d92, using a Galaxy S22 and iPhone 13 with camera access denied in both QA apps.
- Passed, both cross-platform directions. Galaxy Receive advertised at high transmit power. The iPhone opened the exact Galaxy 1,000-sat request, and the Galaxy opened the exact iPhone 5,000-sat request. At 1 metre the iPhone still opened the Galaxy request.
- Passed, QuickPay. With 24,901 sats in Spending and QuickPay set to $5, the $3.02 Lightning request remained on Confirm for at least 37 seconds. The iPhone received 5,000 sats after the deliberate swipe.
- Blocked. The 3-metre range and Android-to-Android cases still need a longer separation and a second physical Android phone, respectively.
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. Keep the per-phone 10 s cooldown across scanner restarts, so Back from the Send sheet review does not read the same phone again at once. Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.nearby.*' detekt lintDevDebug; two-phone run (Pixel 10 Pro, iPhone Air): 10 m+ not read, side by side read both ways, Send sheet Back stays on Send
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 (Battery Saver) still gets read. Verified: ./gradlew testDevDebugUnitTest --tests 'to.bitkit.nearby.*' detekt lintDevDebug
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since eec5a62, including affected code paths and callers, at 7b69f70. Baseline: previous QA review (unchanged NearbyAdvertiser transmit power / NearbyAdvertiserTest.kt and changelog.d/next/2225.fixed.md inherited).
No new actionable code findings.
Parity and contracts: Compared against synonymdev/bitkit-ios#1568 at 978ec5c. The median RSSI selection (MIN_READINGS = 3, lower median, -75 dBm threshold), 500 ms selection window with 2 s slow-phone extension, and docs/nearby-payments.md contract match iOS (docs/nearby-payments.md and Docs/nearby-payments.md are identical). Intentional platform differences match the PR scope: NearbySkips persists the 10 s per-device cooldown across recreated Compose NearbyScanner instances (matching iOS's retained @State scanner across Back from send review), and Android keeps the 10 s retry interval after failed reads due to Android's 5-scans-in-30 s BLE scan throttle.
Validation and limitations: At 7b69f70, CI build-and-test, lint, detekt, and build succeeded; three e2e-tests-local jobs (send, onchain_boost_receive_widgets, multi_address_local) were still in progress at inspection time. Local Gradle execution was not run in this environment (no Android SDK installed). Unit tests (NearbyProtocolTest.kt, NearbySkipsTest.kt) cover the pure selection and cooldown primitives, while NearbyScanner window scheduling and BLE lifecycle orchestration were verified by source analysis only.
Device testing: not performed in this review (code-only; BLE scanning and advertising require two physical devices). Note that the author's manual checklist still leaves the two-Android-phones side-by-side case unchecked.
Suggested additional test cases:
- Android Send sheet cooldown expiry: With two physical phones side by side (one on Receive, one on Android Send), let Send open the payment review, tap Back, confirm it stays on Send for ~10 s, then remain on Send past 10 s and confirm the Receive phone is read again (verifying
NearbySkipsexpires cleanly). - Android median selection with two Receive phones: With two physical Receive phones active (one ~0.5 m away and one ~2–3 m away), open the Android payment scanner and verify it consistently opens the closer phone's payment request.
Earlier findings reconciled at this revision: 2 verified fixed.
Reviewer model: gemini-4-neon
Reasoning effort: high
piotr-iohk
left a comment
There was a problem hiding this comment.
Passed the Android Send cooldown test on 7b69f70c78ac with a physical Galaxy S22 and iPhone 13 on regtest. The iPhone ran the companion PR at 978ec5cccd79 and stayed on Receive with the same 1,000-sat Lightning invoice throughout.
The Galaxy opened Confirm over Bluetooth with camera access denied. I tapped Back and left it on Send. Four successive UI captures showed the recipient screen. The next connection to the same iPhone started 10.51 s after the first read. At 12.43 s, Android read the invoice again and reopened Confirm without another tap. The full invoice on the second review matched the one displayed by the iPhone. Android logged QuickPay suppression on both reads.
| Galaxy log event | UTC |
|---|---|
| First nearby request read | 20:15:30.958 |
| Next Bluetooth connection to the same phone | 20:15:41.470 |
| Second nearby request read | 20:15:43.389 |
This follow-up covers cooldown expiry and cross-platform payment review. The 1.5–3 m and 10 m range cases, Android-to-Android, and selection between two simultaneous advertisers remain unverified in this setup.
Test resultsTested on a Pixel 10 Pro (Android 17) and an iPhone Air (iOS 27.2.1) on mainnet. Each phone ran Median gate (71250fa)The head 7b69f70 adds only the wait of up to 2 s for a phone with fewer than 3 readings; 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 (eec5a62): 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)
|
Verified: ./gradlew detekt
|
4cf623f rewords the docs line and the scanner comments: the window extends in 500 ms steps, up to 2 s, only while no phone qualifies yet and some phone has fewer than 3 readings. That's what the code already does (raised on synonymdev/bitkit-ios#1568 in synonymdev/bitkit-ios#1568 (comment)). No code change. |
piotr-iohk
left a comment
There was a problem hiding this comment.
QA review
Scope: changes since 7b69f70, including affected code paths and prior findings, at 4cf623f. Baseline: previous review (unchanged NearbyAdvertiser / NearbyAdvertiserTest.kt, changelog.d/next/2225.fixed.md, and unchanged runtime/test logic in NearbyProtocol.kt, NearbyScanner.kt, NearbyProtocolTest.kt, and NearbySkipsTest.kt inherited).
No new actionable code findings.
Commit 4cf623f updates only comments and documentation (NearbyProtocol.needsMoreReadings KDoc, NearbyScanner class KDoc, and docs/nearby-payments.md) with no executable code changes. The updated wording accurately matches NearbyScanner.connectToClosest(), which extends the 500 ms collection window in 500 ms steps up to 2 s only while no advertiser qualifies yet (closest == null) and some advertiser has fewer than 3 readings (needsMoreReadings(readings)).
Parity and contracts: Compared against synonymdev/bitkit-ios#1568 at 978ec5c (merged to iOS master at e3fa548). iOS NearbyPaymentScanner.connectToStrongest() uses the same extension condition (bestID == nil and needsMoreReadings), while Docs/nearby-payments.md at 978ec5c predates this wording clarification. The matching iOS doc/comment sync is open in synonymdev/bitkit-ios#1573 at b208491, where Docs/nearby-payments.md is byte-identical to Android's copy at 4cf623f.
Validation and prior findings: git diff --check passed locally. At 4cf623f, CI build-and-test, lint, detekt, compose-ui / ui-tests, and build succeeded; e2e-tests-local shards were still in progress at inspection time. Both earlier review threads (RSSI boundary test coverage and SendRecipientScreen cooldown persistence) remain marked resolved and verified fixed in source.
Device testing: not performed in this review (code-only). Because 4cf623f changes comments and documentation only with no runtime delta since 7b69f70, prior physical-device observations at eec5a62bb514 (QA report), 71250fa44 (author results), and 7b69f70c78ac (Send cooldown QA) still correspond to the unchanged runtime code; the unchecked two-physical-Android-phones case and two-simultaneous-advertisers selection remain unverified.
Reviewer model: gemini-4-neon
Reasoning effort: high
piotr-iohk
left a comment
There was a problem hiding this comment.
Approved at 4cf623fb1bc7. Build, lint and E2E passed on this commit. The change since the Galaxy S22 device run is limited to documentation and code comments. Current review · E2E run
On regtest at 7b69f70c78ac, the Galaxy and iPhone 13 verified the Android Send cooldown. After Back, the next connection started at 10.51 seconds. The same 1,000-sat invoice reopened at 12.43 seconds, and QuickPay stayed suppressed. Earlier physical runs covered reads in both directions. Galaxy device results
At 71250fa44, the median-signal fix kept the Android scanner open for 33 seconds at 10 m despite a −75 dBm spike. A physical range retest with the later extended scan window remains open, as do selection between two simultaneous advertisers and a two-physical-Android run. The two-emulator run covered the Android-to-Android protocol flow. Range and emulator results
|
Merging: approved on 4cf623f with CI green, and the cross-platform device runs passed on this code paired with synonymdev/bitkit-ios#1568 (merged). |
Twin: synonymdev/bitkit-ios#1568
Refs: synonymdev/bitkit-ios#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)Out of Scope
Design
N/A — no UI changes.
Preview
N/A — no user-visible changes.
QA Notes
Journeys
N/A
Manual Tests
Automated Checks
NearbyAdvertiserTest.kt(asserts high transmit power)NearbyProtocolTest.kt(−75 gate at −74, −75 and −76 dBm; median ranking, a spike or too few readings never win)NearbySkipsTest.kt(cooldown kept across scanners)./gradlew testDevDebugUnitTest --tests 'to.bitkit.nearby.*' detekt lintDevDebug