Repository navigation
fix(app): run bounded cloud sync grace when screen locks (#7221) - #11127
Conversation
…re#7221) Foreground-only recovery stopped all uploads/reconcile on pause, so large backlogs stalled overnight. Allow one phone-disk upload + reconcile pass under iOS beginBackgroundTask; keep BLE drains deferred. Failure-Class: none Co-authored-by: Cursor <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
2 issues found across 10 files
Confidence score: 2/5
- In
app/lib/providers/sync_provider.dart, the screen-lock grace loop can run beyond the intended three-batch cap because failed/rejected batches don’t decrement themaxBatchesbudget, which risks prolonged background work during outages and battery/network drain — count every attempted batch toward the cap (or otherwise enforce a hard stop). - In
app/lib/services/wals/recording_transfer_coordinator.dart, replacing a queuedforegrounded/deviceConnectedwake withscreenLockedGracecan skip the required full transfer pass after resume/reconnect, so pending recordings may remain unsynced until another stronger trigger occurs — preserve or prioritize the highest-capability pending wake reason when updating preferences.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/services/wals/recording_transfer_coordinator.dart">
<violation number="1" location="app/lib/services/wals/recording_transfer_coordinator.dart:228">
P2: Resuming the app or reconnecting the device can lose the required full transfer pass because this preference replaces a pending `foregrounded`/`deviceConnected` wake with the lower-capability `screenLockedGrace` pass. Preserving normal full wakes over a grace wake keeps BLE WAL discovery and draining reliable across this lifecycle race.</violation>
</file>
<file name="app/lib/providers/sync_provider.dart">
<violation number="1" location="app/lib/providers/sync_provider.dart:480">
P1: The screen-lock grace pass is not actually bounded to three batches when uploads fail: failed or recovery-window-rejected batches do not consume the `maxBatches` budget, so a transient outage can make this background pass walk the entire backlog. Counting every attempted batch (or enforcing the attempt budget before each batch) would preserve the advertised bounded cloud grace behavior.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| _walsProcessedCount = 0; | ||
| final result = await _performSync( | ||
| operation: () => | ||
| _walService.getSyncs().syncLocalUploadsOnly(progress: this, maxBatches: kScreenLockedCloudGraceMaxBatches), |
There was a problem hiding this comment.
P1: The screen-lock grace pass is not actually bounded to three batches when uploads fail: failed or recovery-window-rejected batches do not consume the maxBatches budget, so a transient outage can make this background pass walk the entire backlog. Counting every attempted batch (or enforcing the attempt budget before each batch) would preserve the advertised bounded cloud grace behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/lib/providers/sync_provider.dart, line 480:
<comment>The screen-lock grace pass is not actually bounded to three batches when uploads fail: failed or recovery-window-rejected batches do not consume the `maxBatches` budget, so a transient outage can make this background pass walk the entire backlog. Counting every attempted batch (or enforcing the attempt budget before each batch) would preserve the advertised bounded cloud grace behavior.</comment>
<file context>
@@ -457,6 +459,36 @@ class SyncProvider extends ChangeNotifier implements IWalServiceListener, IWalSy
+ _walsProcessedCount = 0;
+ final result = await _performSync(
+ operation: () =>
+ _walService.getSyncs().syncLocalUploadsOnly(progress: this, maxBatches: kScreenLockedCloudGraceMaxBatches),
+ context: 'screen-lock cloud grace upload',
+ rethrowOnError: true,
</file context>
Count every selected upload batch toward maxBatches (including failures and recovery-window rejections) so grace cannot walk the whole backlog. Prefer foregrounded/deviceConnected over screenLockedGrace so unlock and reconnect still run BLE discovery. Failure-Class: none Co-authored-by: Cursor <[email protected]>
|
Addressed both cubic findings on the new tip: P1 — hard maxBatches bound: P2 — full wakes beat grace:
|
Failure-Class: none Co-authored-by: Cursor <[email protected]>
|
Fixed Formatting: |
|
Reviewed #7221 screen-lock cloud grace pass. The design is solid and the two prior cubic findings are correctly resolved on this tip:
The implementation is well-isolated: the new One thing worth a human glance before merge: CI looks clean (Dart Analyze & Tests, Android Compile Smoke, Sync Cloud Tasks Stack Gauntlet all green). Marking for maintainer review since this touches the app backgrounding + cloud upload surface. Thanks for the clean follow-up on the cubic findings and the focused tests. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
@mdmohsin7 I reran the focused Flutter tests on the #7221 worktree head (fix/7221-sync-background-grace):\n\n- flutter test test/unit/sync_continuation_policy_test.dart |
|
@mdmohsin7 Friendly bump on the code-owner review for #7221. Current head If the approach looks good, an APPROVE from you clears the merge gate. Thanks! |
|
@mdmohsin7 Friendly code-owner bump on #7221. Head If the approach looks good, an APPROVE from you clears the merge gate. Thanks! |
kodjima33
left a comment
There was a problem hiding this comment.
Bounded screen-lock grace pass (reconcile + max 3 upload batches) with a pure policy helper and tests.
|
Did you actually test and verify these things on device @aryanorastar? |
|
changes are iOS only, code talks about using BGProcessingTask but no swift code registers for it, no demo/proof showing it actually works |
|
@mdmohsin7 Fair call on the device-verification gap — thank you for catching it, and the revert is the right move. Honest answer to your question: no, I did not verify this on a physical device. Coverage was unit/coordinator tests only ( One clarification on the revert note, so we don’t chase the wrong fix on re-land:
Happy to re-open only after I can show on-device proof (or a maintainer smoke) that lock → grace starts → ≤3 batches → |
Summary
When the screen locks, Flutter hits
pausedand#9763's foreground-onlyRecordingTransferCoordinatorstops all upload/reconcile work. That matches #7221: overnight with the app "open" on fiber Wi-Fi still only drains ~5% of a 1000+ file backlog, and "processing on server" freezes at 0%.Implementation
decideScreenLockedSyncContinuationpolicy (app/lib/utils/sync_continuation_policy.dart).WakeTrigger.screenLockedGrace: while backgrounded, runs reconcile + bounded phone-disk uploads only (max 3 batches / ~15 WALs). Skips BLE device discovery/drain.SyncReconciler.onBackgroundstarts that grace when miss/uploaded work exists; iOSbeginBackgroundTaskviacom.omi/sync_background_task.WalSyncs.syncLocalUploadsOnly+LocalWalSyncImpl.maxBatchesfor the bounded pass.Out of scope: overnight BGProcessingTask for full 1000+ drain, BLE flash download in background, server job pipeline stalls.
Tests
flutter test test/unit/sync_continuation_policy_test.dartflutter test test/services/wals/recording_transfer_coordinator_test.dartProduct invariants affected
none
Failure class (fixes)
Failure-Class: none