Repository navigation
fix: run pubky work on its own service queue - #1798
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Regtest APKDownload bitkit-dev-debug universal APK (expires in 30 days). |
[Medium impact] The PR appears safe to merge. SummaryMoves queued Pubky work from
jvsena42 explicitly leaves synchronous Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A["PubkyService calls"] --> B["PUBKY queue"]
B --> C["Paykit work and Pubky auth"]
D["CoreService construction"] --> E["CORE queue"]
E --> F["Core database setup"]
Reviews (1) · Last reviewed commit: "chore: rename changelog fragment" · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Moves every PubkyService call from ServiceQueue.CORE to a new single-thread ServiceQueue.PUBKY, so a stuck Paykit platform init can no longer hold the thread CoreService.init blocks the main thread on. Reviewed 2fd4796, full tier, static: per this repo's convention for unattended reviews the branch was not built here, so the build and tests are CI's.
What I checked, and 5 candidates I ruled out
Read in full: ServiceQueue.kt, PubkyService.kt, the setup and lock path of PaykitSdkService.kt (initialize, setupMutex, operationLock, completeSdkCall, handle), CoreService.init and the Paykit backfill on CORE, PubkyRepo.ensureServiceInitialized, the changed tests.
Ruled out
- Lost ordering with core DB work: no
PubkyServicemethod touches the bitkit-core database. The two bitkit-core calls that moved areparsePubkyAuthUrl(stateless) andapprovePubkyAuth, which bitkit-core runs on its own tokio runtime (ensure_runtime().spawninsrc/lib.rs), so neither relied on CORE's thread. Paykit ordering comes fromsetupMutexandoperationLock, not the queue. - CORE/PUBKY deadlock: the only
ServiceQueue.*.blockingcaller isCoreService.init, and the CORE work that reads Paykit state (backfillPaykitContactsthroughPrivatePaykitContactResolver) goes throughioDispatcherrather thanPubkyService, so no thread waits on the other queue while holding its own. cancellablePublicRead/importShopContactscancellation: both swapped toPUBKY.queueContext.minusKey(Job)together, same semantics as before on the new thread.- Thread-local static mocks in other tests:
PubkyAuthApprovalViewModelTestandPrivatePaykitRepoTestmock bitkit-core on their own thread and mockpubkyRepo/paykitSdkServicerather than callingPubkyService; the two relay tests that do go throughPubkyServicewere moved toPUBKY. - Enum ordinal shift from inserting
PUBKY: nothing readsServiceQueueordinals orentries.
Test: paykit initialization does not hold the core queue blocks the mocked initialize() on a latch and asserts ServiceQueue.CORE.blocking still runs; with PubkyService on CORE that latch would hold the CORE thread and the 5 s await fails, so it covers the regression.
CI at review time: lint, detekt and build green; build-and-test, compose-ui / ui-tests and the e2e shards still running.
Merge confidence: 4/5, no findings, but the unit and e2e runs were still pending when this was posted and the branch was not built here.
Reviewer model: claude-opus-5-5
Reasoning effort: Not exposed (the review runner does not report a setting)
There was a problem hiding this comment.
Verdict: ✅ Approve
Findings: None.
QA for 2fd4796:
Check: Dev build ✅ The app builds at the reviewed head.
assembleDevDebug passed on the unmodified head.
Pubky queue isolation and cancellation ✅ The focused unit tests pass.
PubkyServiceTest.kt and PaykitSdkServiceTest.kt passed, including the blocked-initialization regression, public-read cancellation, relay timeout and cancellation, and deferred shop import cancellation.
Check: Cold launch regression report ✅ The author reports both controlled startup variants at this head.
Manual case 1 reuses the author's QA Evidence: the fixed variant reaches Home without an ANR while Pubky blocks for 15 seconds; the unfixed control triggers an input-dispatch ANR. I did not repeat this unchanged-head device case. The affected 32-bit physical device and the cause of the native constructor delay remain unverified.
Full review: ef8cffa..2fd4796, all five changed files. Other Pubky workflows were reviewed statically. The earlier static review also reports no findings.
iOS: no twin PR is needed; Paykit startup runs outside the core queue and core database initialization does not wait on that queue.
Reviewed by gpt-6.1-sol-high
Fixes #1695
This PR moves Pubky and Paykit work off the shared core service queue so that a slow Paykit start can no longer freeze app launch.
Description
Out of Scope
CoreServiceinit: construction still waits on the core queue from the main thread for its own database setup. Making it asynchronous would change when other callers see the database as ready. After this change, nothing except user-started Trezor operations runs on the core queue beforeCoreServiceexists.initDbdirectly instead of waiting on a queue.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
git applyon top of the branch, build withjust build, and never commit it. Both start Pubky initialization fromApp.onCreateand block its thread for 15 s, the way the stuck native Paykit constructor did.repro-fixed.diffkeeps this PR's fix: Pubky init blockspubky-queue.repro-unfixed.diffalso movesPubkyService.initialize()back toServiceQueue.CORE, as on master: Pubky init blockscore-queue.git checkout -- app/src/main/java.repro-fixed.diff
repro-unfixed.diff
Journeys
N/A — no user-visible behaviour change.
Manual Tests
regression:With the repro patch, force-stop the app → cold launch → press a key within 5 s → Home loads with no ANR dialog, and the log showsREPRO blocking 'pubky-queue'. The unfixed variant shows the Application Not Responding dialog andREPRO blocking 'core-queue'. — injecting a blocking native constructor (code patch) not in CapabilitiesAutomated Checks
PubkyServiceTest.kt— a Paykit initialization that blocks its thread no longer prevents the core queue from running work; fails without the fixPubkyServiceTest.kt— relay approval tests run on the Pubky queue so their thread-local native mocks applyPaykitSdkServiceTest.kt— shop import cancellation test drains the Pubky queue instead of the core queueEvidence
2fd479699, locally:just compile,just lintandjust testpassed. The newPubkyServiceTest.ktcase failed with thePubkyServicechange reverted and passed with it.2fd479699plus the repro patch, dev debug arm64 build on the Gate_Throwaway emulator (Android, existing regtest wallet):REPRO blocking 'core-queue' for 15s, thenANR in to.bitkit.dev (to.bitkit.dev/to.bitkit.ui.MainActivity)with reasonInput dispatching timed out, and the focused window isApplication Not Responding: to.bitkit.dev.REPRO blocking 'pubky-queue' for 15s, no ANR is logged, MainActivity keeps focus, and Home showsTotalBalance,SendandReceive.Gaps
Models used
claude-opus-5-5(reasoning: Not exposed)claude-opus-5-5(reasoning: Not exposed)claude-opus-5-5(reasoning: Not exposed)Metadata note: the sessions report the model ID but expose no reasoning-effort setting in run metadata. The reviewer subagent self-reported low effort, but no run record confirms it.
🤖 Generated with Claude Code