Repository navigation
Conversation
An iPhone reading a Galaxy S22's request connected and then timed out after 8 s until Bluetooth was cycled on the S22, which had kept services of earlier GATT servers registered. - Answer each read through the server it arrived on, with an error once that server is closed, instead of leaving it unanswered. - Clear the service before closing the server. - Serve a new request from the open server instead of reopening it. Fixes #2257 Verified: just compile, just lint, just test on this change
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. |
Confidence Score: 4/5
[Medium impact] The changes affect the Android nearby-payment Bluetooth serving path in Receive. The PR appears safe to merge, with a non-blocking gap in tests for request updates during a read. Findings
SummaryThis PR keeps the nearby GATT server open when the payment request changes.
Reviews (1) · Last reviewed commit: "fix: answer every nearby read and keep t..." · Reviewed by Greptile |
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Answers each nearby GATT read through the server it arrived on (an error once that server is closed), clears the service before closing, and keeps one server open across request updates. Reviewed 039aceb9c, full tier, static: the Bitkit Android branch is not built on this box, so this is reasoned from the code and from CI.
What I checked, and 5 candidates I ruled out
Read in full: NearbyAdvertiser.kt, NearbyEffects.kt (advertise effect and offerPaymentNearby), NearbyScanner.kt read session, NearbyProtocol.kt, both test files; iOS NearbyPaymentScanner.swift for how a GATT error is handled on the reader side.
CI: build-and-test, lint, detekt, compose UI and the e2e shards green; onchain_boost_receive_widgets still pending when this was posted.
Ruled out
- Observer re-add misses the new uri:
LifecycleRegistryreplays events up to the current state to a newly added observer, so re-keying the effect onurire-runsON_RESUMEand serves the new request; a null uri goes throughserveNearbytostop(). - Stop on dispose skipped or doubled: the
urieffect only removes its observer, theadvertisereffect stops once on leaving composition, andstop()is idempotent. - Read on a binder thread sees a stale generation:
serverGenerationis now@Volatileandrequestalready was; a read racingstop()getsGATT_FAILUREthrough its own server, which the iOS reader treats as a quick retry (fail(error)keepsretrySoontrue). - Request changes between the meta read and a chunk read: now possible on the kept server, but the reader then sees a length mismatch and drops the read (Android
decodereturns null, iOS fails it); a mix of two equal-length requests over 512 bytes would still have to passnearbyPaymentRequest. Narrow, and the old behaviour (server torn down mid-read) also lost that read. clearServices()on a server that failedaddService:openServercloses and returns null on that path, sostop()never sees it.
Merge confidence: 4/5, the unit tests cover the server reuse and the error answers, but the fix targets a device-level Bluetooth stack state that only manual tests 1 to 3 can confirm.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the run metadata available to the reviewer does not report it)
Keeping the server open across request changes let a payer read the length of one request and the chunks of the next. Verified: just compile, just lint, just test on this change
| response == null -> BluetoothGatt.GATT_INVALID_OFFSET | ||
| else -> BluetoothGatt.GATT_SUCCESS | ||
| } | ||
| runCatching { owner.sendResponse(device, requestId, status, offset, response) } |
There was a problem hiding this comment.
A read already dispatched on the old server can still reach this line after close(). Android 16 then returns false without sending GATT_FAILURE. The tests verify the call, so they pass even when the response never goes out. If the connection stays up, the payer can still wait for its timeout. Could we log the failed send and check what the payer sees when Receive closes during a read? Android 16 source
There was a problem hiding this comment.
Addressed in 5729094. A false return is now logged, and the tests stub it for a closed server and check the warning. What the payer sees when Receive closes mid-read needs two phones, so it's added as QA case 4 in the description.
A read that reaches a server after close() can't be answered: sendResponse returns false and sends nothing. Log it, and make the tests model that instead of counting the call as an answer. Verified: just compile, just lint, nearby unit tests (just test on the tree before the log test)
Fixes #2257
Description
Fix for the likely cause. Not tested on devices yet (see Gaps).
The trace in this issue shows each failed attempt as connect, MTU 517, then a disconnect 7.4 to 7.8 s later and a new attempt ~2.7 s after it, which is the iPhone reader's 8 s timeout plus its 2 s retry. The S22's Bluetooth dump still listed six advertising sets for the nearby service (some from November, some from the dev build) and three registrations of the nearby service, and only turning Bluetooth off and on on the S22 fixed it. The GATT database is shared by every server on the phone, so a service left behind by a closed server can take the iPhone's read, and nobody answers it. Android logs read requests only at verbose level, so the trace can't show which step stalled.
Out of Scope
Design
N/A — no UI changes.
Preview
N/A — no user-visible changes.
QA Notes
Setup
Journeys
N/A — not drivable; see Manual Tests.
Manual Tests
Automated Checks
NearbyAdvertiseEffectTest.kt— a request change keeps the server open; nothing to offer closes itNearbyAdvertiserTest.kt— a new request is served from the open server; a read after stop, or on a closed server, is only tried on its own server, never the new one, and a send that goes nowhere is logged; the service is cleared before close; a payer gets the chunks of the request it read the length of, until it disconnectsjust compile,just lint,just testEvidence
just compile,just lintandjust testpass on 89c9dbb;just compile,just lintand the nearby unit tests pass on 5729094.Gaps
Models used
Claude Opus 5.5(reasoning:medium)Claude Opus 5.5(reasoning:medium)Gemini 4 Neon(reasoning:high)