Skip to content

backfill: move on-demand anchor past batches that convert to nothing - #1056

Open
indent[bot] wants to merge 2 commits into
mainfrom
indent/whatsapp-on-demand-skipped-batch-anchor
Open

indent[bot] wants to merge 2 commits into
mainfrom
indent/whatsapp-on-demand-skipped-batch-anchor

Conversation

@indent

@indent indent Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Logs

No messages to backfill, but HasMore is true: 560 in 24 h vs 86 the day before. Loki samples (15-min windows on 3 clusters, Nov 13-14) show at least 4 accounts, each stuck on one chat during manual scroll-back. One account sent 259 requests in 8 minutes. Every round does the same thing: a history sync request with the same anchor, an ON_DEMAND reply with 50 messages and COMPLETE_BUT_MORE_MESSAGES_REMAIN_ON_PRIMARY, 0 converted, an unchanged cursor, and has_more=true.

Cause

handleOnDemandHistorySync skips ignore-type messages (content-less stubs). When the whole batch is skipped it returns no messages but HasMore. fetchMessagesFromPhone always anchors on the oldest bridged message, which didn't move, so the phone returns the same batch forever and older history is unreachable.

Change

When an on-demand batch converts to nothing, the cursor carries the oldest skipped message key (timestamp, fromMe, ID). fetchMessagesFromPhone anchors on it when it's older than the oldest bridged message. FetchMessages reads only the cursor's timestamp part, so existing cursors work unchanged.

Before / after

Note: not tested against a live account.

Case Base Head
100 system stubs before oldest bridged message, then real history Same anchor re-requested every scroll, nothing bridged Next requests anchor on oldest stub; real messages bridged on 3rd scroll
50 stubs in the same second as oldest bridged message Same anchor re-requested every scroll, nothing bridged Second request anchors on oldest stub; real messages bridged
Batches of real messages (adjacent) Anchor moves to oldest bridged message each scroll Same

View in Indent
Tag @indent to continue the conversation here.

@Fizzadar
Fizzadar requested a review from tulir November 16, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant