fix: Sync() only fetches the first page of history items#5
Open
RyanGWU82 wants to merge 1 commit into
Open
Conversation
…-index Sync() was using s.history.LatestServerIndex as the start-index for the next Items() request. LatestServerIndex is the server's total item count and is constant across pages, so every request after the first asked for items starting at the very end of the history and received nothing. The correct field is LoadedServerIndex, which accumulates the number of item-batches received so far and steps through the history page by page. This matches the pattern used by all CLI tools in cmd/. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While using this SDK against my own account, I found that
Syncer.Sync()silently produces incomplete, stale data. On my account (55,054 history items spanning two years), only ~2,500 items — the oldest ones — were ever processed. Current tasks were invisible, all modification timestamps were from the earliest weeks of the history, andsync_staterecordedserver_index = 55054, making the syncer believe it was fully up to date and skip all future syncs.Root cause: The pagination loop uses
s.history.LatestServerIndexas thestart-indexfor each subsequent request.LatestServerIndexis the server's total item count and is constant across pages, so after the first batch the syncer asks for items at the very end of the history, receives nothing, and stops. The correct field isLoadedServerIndex, which accumulates the number of item-batches received so far. All thecmd/tools already use this correctly.Fix: One line in
sync/sync.go:A regression test (
TestSync_PaginatesAllPages) is included. It uses a fake two-page server where the correct next index (1) returns page 2 and the wrong index (2) returns empty — confirming the test would have caught the original bug.