Repository navigation
fix(wallet): pause background refresh until the locked-launch fix lands - #1148
Conversation
A BGAppRefresh task launches the app while the device is locked. The mnemonic keychain items are kSecAttrAccessibleWhenUnlockedThisDeviceOnly, so the launch-time presence read fails and is taken as "no wallet": the root controller offers Create/Recover over a funded wallet, and the SDK runtime never starts in that process. Reachable since the refresh task was introduced with the notifications rework (#1088); the fix — a tri-state presence and a launch hold that waits for protected data — is in progress in a separate PR (#1147) and needs a device test before it can ship. Until then background refresh is paused as a build-level switch (BackgroundRefreshCoordinator.isEnabledInThisBuild = false): - start() withdraws the pending request and submits nothing; a task delivered anyway (an earlier build's request) completes at once — as a success, so nothing counts against the app's refresh budget — without starting the runtime or re-submitting. - The BGTask handler stays registered and the Info.plist permitted identifier and `fetch` mode stay: a request submitted by an earlier build can still launch this one, and BGTaskScheduler requires a handler for every permitted identifier at that moment. - Everything else in the coordinator (observers, catch-up stamp, become-active rearm) behaves as before. Re-enable by flipping the switch to true once #1147 has landed and been verified on a device. The switch is injected into the coordinator so its tests cover both modes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThis change disables background refresh in this build. The coordinator cancels pending requests, skips new submissions, and completes delivered tasks successfully without starting a runtime or sync. ChangesBackground refresh pause
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to Background refresh is paused, so incoming-transaction notifications will not be produced while the app is closed. No additional actionable issue is established here; the separately reported locked-launch concern still warrants resolution before relying on the pause as a safe-release fix. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
llbartekll
left a comment
There was a problem hiding this comment.
LGTM. The valve is tight: scheduleNextRefresh() is the only path to submit, so its guard covers the didEnterBackground call and both in-run calls. Registration staying unconditional is correct, since the permitted identifier and the fetch mode are still in both plists. A delivered task completes synchronously with success: true and never reaches run, so there's no runtime bring-up and no re-submit. The three new tests cover all of that.
I checked that the "no App Store build" claim holds: #1088 (84229f9) isn't an ancestor of tf-9.0.0__11 or v8.6.0, so no shipped or tagged TestFlight build ever submitted a request. One FYI: cancel in start() can't help a process that the stale request itself launched. The launch-path "no wallet" read happens before the handler runs. So a dev device that ran an internal #1088 build could still hit the setup screen once after installing this. That's internal only, so it doesn't block.
Non-blocking doc nits (these lines are outside the diff hunks, so I'm leaving them here instead of inline):
BackgroundRefreshCoordinator.swift:92-93: theBackgroundTaskSchedulingdoc still says "registration and request submission are the only calls the coordinator makes".cancelmakes that out of date.:354and:384: "skipped only when no wallet exists" / "Skipped only when a wallet is provably absent". With the pause in, those skips are no longer the "only" ones. Worth a clause, or at least worth fixing when the switch is flipped back.
|
⛔ Final review complete — 1 blocking finding(s) (commit f8fd5f6) |
Review follow-up on the pause: the BackgroundTaskScheduling seam now also cancels, and scheduleNextRefresh has a second skip while background refresh is paused. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
At f8fd5f6, the coordinator correctly prevents new submissions and completes delivered tasks without coordinator work. However, it does not meet the stated release-safety guarantee for an upgrade first launched while locked by an earlier build's pending request: ordinary application startup still makes the unsafe wallet-presence decision. Verification was source-based; no independent build or device-smoke result is asserted.
🔴 1 blocking
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: general); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)
- Triage:
lowbygpt-6-astra(effort low) — The diff adds a contained background-refresh kill switch, cancellation seam, and focused tests without changing wallet presence detection, key handling, runtime lifecycle logic, or funds movement. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 45% left; passed overgemini-3.8-flash-high(antigravity below 15% reserve: weekly 1% left, 5h 100% left) - Fresh verifier:
gpt-6-astra— final-verifier; agentastra-verifier - Phase 2 reviewers:
gpt-6-astra— general (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `DashWallet/Sources/Infrastructure/Notifications/BackgroundRefreshCoordinator.swift`:
- [BLOCKING] DashWallet/Sources/Infrastructure/Notifications/BackgroundRefreshCoordinator.swift:325-331: Cancellation during startup cannot protect an upgrade's first locked launch
An earlier build's pending request can launch the updated app while locked before this cancellation runs, as the PR description explicitly acknowledges. Completing that task without coordinator work does not bypass AppDelegate's normal startup: it still calls startIfReady, installs DWInitialViewController, and makes the window visible. SwiftDashSDKHost.hasPersistedSDKWallet maps a keychain-read error to false, and DWAppRootViewController selects setup when that result is false and no legacy migration is pending. For an existing SDK wallet with the migration-done sentinel, the legacy hold is bypassed, so this residual delivery can still leave Create/Recover over a funded wallet. Foregrounding does not repair that decision: the root only checks the lock screen, and the coordinator rearms the runtime only when it previously stopped it. The pause reduces future exposure but does not satisfy the stated safe-release guarantee. Protect or defer normal startup for this remaining locked-launch path, and add coverage that launches through the app/root decision rather than invoking only the task handler.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- The pinned DashUIKit requires a newer toolchain than the documented minimum — The pinned DashUIKit revision 83cf65a84834f6a7a1f0a82446ea1258ea86f37d declares swift-tools-version 6.3, while this machine's Xcode 16.4 provides Swift 6.1.2. This conflicts with the repository's Xcode 16+ setup guidance. The dependency pin and guidance are unchanged by this PR, so this is a separate reproducible-build concern, not a defect in the refresh pause.
- Follow-up: Track toolchain/dependency alignment separately: document a compatible Xcode minimum or select a dependency revision supporting the intended minimum.
| // Registration above is unconditional even while paused: a request | ||
| // an earlier build submitted can still launch this one, and | ||
| // `BGTaskScheduler` requires a handler for every permitted | ||
| // identifier at that moment. The handler then only completes the | ||
| // task; here the pending request is withdrawn so it does not. | ||
| if !isEnabled { | ||
| scheduler.cancel(identifier: Self.taskIdentifier) |
There was a problem hiding this comment.
🔴 Blocking: Cancellation during startup cannot protect an upgrade's first locked launch
An earlier build's pending request can launch the updated app while locked before this cancellation runs, as the PR description explicitly acknowledges. Completing that task without coordinator work does not bypass AppDelegate's normal startup: it still calls startIfReady, installs DWInitialViewController, and makes the window visible. SwiftDashSDKHost.hasPersistedSDKWallet maps a keychain-read error to false, and DWAppRootViewController selects setup when that result is false and no legacy migration is pending. For an existing SDK wallet with the migration-done sentinel, the legacy hold is bypassed, so this residual delivery can still leave Create/Recover over a funded wallet. Foregrounding does not repair that decision: the root only checks the lock screen, and the coordinator rearms the runtime only when it previously stopped it. The pause reduces future exposure but does not satisfy the stated safe-release guarantee. Protect or defer normal startup for this remaining locked-launch path, and add coverage that launches through the app/root decision rather than invoking only the task handler.
source: gpt-6-astra (phase2-reviewer: general)
There was a problem hiding this comment.
Agreed that this is the remaining path, and it is stated in the PR description. It is out of scope here by design. This PR only stops new requests from being submitted. The launch-path decision itself is fixed in #1147, which holds the root decision and the runtime start until protected data is available, and it includes a DEBUG harness that goes through the app and root decision. The residual can only happen on a device that ran a build containing #1088. Every TestFlight build since #1088 merged has been internal, and no tagged or App Store build contains it, so no user outside the team can have a pending request. The pause does what it claims for every build cut from develop from now on.
🤖 Addressed with Claude Code
There was a problem hiding this comment.
I confirmed that the pause prevents new submissions and that no locally available tag contains #1088; given your clarification that the affected TestFlight builds were internal-only, I accept leaving the residual upgrade-launch path to #1147 rather than blocking this pause on that fix.
Noted as intentionally deferred; I will not press it further here.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Issue being fixed or feature implemented
A background app refresh can launch the app while the device is locked. The mnemonic keychain items are
kSecAttrAccessibleWhenUnlockedThisDeviceOnly, so the wallet-presence read at launch fails and is treated as "no wallet". The root controller then shows Create a New Wallet / Recover Wallet over a funded wallet, and the SDK runtime never starts in that process. If the user opens the same process later, they land on setup. Going through Create from there ends on a home screen with no runtime: zero balance, core tab layout, no sync.This became reachable with the notifications rework (#1088), which introduced the
BGAppRefreshTask. Before that, the app never scheduled background fetches. The fix is in #1147 (tri-state wallet presence plus a launch hold that waits for protected data), and it needs a device test before it can ship.This PR is a release safety valve: while it is in, no App Store build cut from develop can do a locked background launch.
What was done?
BackgroundRefreshCoordinator.isEnabledInThisBuild = falsepauses background refresh in this build. The flag is injected into the coordinator (isEnabled:), so its tests cover both modes.start()withdraws the pending request (BGTaskScheduler.cancel(taskRequestWithIdentifier:)) and logs once.scheduleNextRefresh()submits nothing.BGTaskSchedulerregistration instart(), the Info.plist permitted identifier and thefetchbackground mode. A request from an earlier build can still launch this one, and the scheduler requires a registered handler for every permitted identifier at that moment.isEnabledInThisBuildtotrueonce fix(wallet): hold the launch decision while the keychain is locked #1147 has landed and been verified on a device.How Has This Been Tested?
BackgroundRefreshCoordinatorTests: 21/21 pass.isEnabled: trueexplicitly.startstill registers and withdraws the pending request; backgrounding submits nothing, even with a wallet or a locked device; a delivered task completes without touching the runtime or submitting.SwiftDashSDKCoreLifecycleTestsas a baseline: unchanged, only the two known balance-message failures.dashpayDebug on an arm64 simulator: builds.Breaking Changes
None, apart from the pause itself: while it is in, incoming-transaction notifications are not produced while the app is closed.
BackgroundTaskSchedulinggainscancel(identifier:), an internal seam.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit