Repository navigation
fix(sync): stop infinite re-fetch loop during bidirectional pagination - #293
Conversation
release URL and description
- Client: fetch remaining server pages once after local pages exhaust, instead of re-requesting on every outer-loop iteration - Server: reset page cursor only at session start (pageIndex==0), removing mid-exhaustion resets that restarted from page 0 - Add SyncIncomingHandler tests verifying session-aware cursor reset
There was a problem hiding this comment.
Code Review
This pull request refactors the paginated sync process to prevent unbounded re-fetch loops. It moves the server-side page cursor reset to the start of a new sync session (when pageIndex is 0) and defers fetching remaining server pages until after local data is exhausted. Additionally, comprehensive unit tests are added to verify the cursor reset behavior. The review feedback highlights two key improvements: a high-severity issue where lockstep pages overwrite each other in storage, potentially causing data loss, and a medium-severity recommendation to guard the final sequential page fetch against cancelled sync operations.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
- Convert sync_pagination_service_test from testWidgets to plain test() to prevent Future.delayed hanging under fake async clock (root cause of 10+ minute test suite stalls and cascading 750+ failures) - Fix sync_incoming_handler_test: use @GenerateNiceMocks instead of hand-rolled Mock classes to resolve null-safety dummy value issues with non-nullable Future<void> return types - Fix date_filter_setting_test: compute expected week boundaries from DateTime constructor instead of assuming same month as now (failed when week start falls in previous month near month boundaries) - Fix lockstep loop test to actually exercise 3-page sequence and verify cursor reset fires exactly once on pageIndex 0 - Extract helpers from syncEntityWithPagination into focused private methods for improved readability and testability
…lation - Use storeAdditionalServerPage for pages with known server page index to prevent silent data loss from key collisions in _pendingResponseData - Add _isSyncCancelled guard in _fetchRemainingServerPages to skip unnecessary work and log noise after cancellation
🚀 Motivation and Context
Bidirectional sync between mobile and desktop never completes. When syncing 10,000+ AppUsageTimeRecord records, the client re-requests ALL server pages on every outer-loop iteration, and the server resets its page cursor to -1 on exhaustion — restarting pagination from page 0. This produces an infinite re-fetch loop (~20,000 redundant page requests).
Root cause (verified via log analysis + code trace):
sync_pagination_service.dart):requestAdditionalServerPages()called inside the per-iteration while loop, not oncesync_incoming_handler.dart):setLastSentServerPage(..., -1)on exhaustion path restarts the auto-advance counter⚙️ Implementation Details
Client (
sync_pagination_service.dart):requestAdditionalServerPages()calllastReceivedServerPageandtotalServerPagesduring locksteprequestAdditionalServerPages()call for remaining server pagesServer (
sync_incoming_handler.dart):pageIndex == 0(new session)Tests (
sync_incoming_handler_test.dart):📋 Checklist for Reviewer
flutter teston commands + services)flutter analyze— no issuesdart format— clean🔗 Related
Addresses the issue where sync from SAMSUNG SM-S911B to NixOS 26.11 server hangs indefinitely.