Skip to content

fix: Sync() only fetches the first page of history items#5

Open
RyanGWU82 wants to merge 1 commit into
arthursoares:mainfrom
RyanGWU82:fix/sync-pagination
Open

fix: Sync() only fetches the first page of history items#5
RyanGWU82 wants to merge 1 commit into
arthursoares:mainfrom
RyanGWU82:fix/sync-pagination

Conversation

@RyanGWU82

Copy link
Copy Markdown

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, and sync_state recorded server_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.LatestServerIndex as the start-index for each subsequent request. LatestServerIndex is 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 is LoadedServerIndex, which accumulates the number of item-batches received so far. All the cmd/ tools already use this correctly.

Fix: One line in sync/sync.go:

-startIndex = s.history.LatestServerIndex
+startIndex = s.history.LoadedServerIndex

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.

…-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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant