fix(history): deliver on-demand history-sync and deepen on-link backfill - #133
Open
nicolasnovis wants to merge 3 commits into
Open
Conversation
…ssage The on-demand history-sync request was sent to messageInfo.Chat (the contact) with Peer:true. Peer messages must go to the account's OWN JID — sending to the contact fails with "no signal session established" and never returns history. whatsmeow's BuildHistorySyncRequest documents SendPeerMessage as the way to send it (it targets getOwnID().ToNonAD() with Peer:true). The target chat/cursor is already encoded inside the built request, so no information is lost.
…kfill RequireFullSync=true alone yields a shallow/uneven backfill because the phone falls back to conservative defaults when no HistorySyncConfig is provided. Setting an explicit deep window makes newly linked devices receive the full available message history.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures newly linked devices receive complete message history by fixing how on-demand history-sync requests are sent and by explicitly configuring a deep on-link history sync window in device properties. Sequence diagram for on-demand history-sync request using SendPeerMessagesequenceDiagram
actor ApiClient
participant ChatService as chatService
participant WMClient as whatsmeowClient
participant Phone
ApiClient->>ChatService: HistorySyncRequest(data, instance)
ChatService->>WMClient: GetMessageInfo(data.ChatID)
ChatService->>WMClient: BuildHistorySyncRequest(&messageInfo, data.Count)
WMClient-->>ChatService: histRequest
ChatService->>WMClient: SendPeerMessage(context, histRequest)
WMClient->>Phone: peer history-sync request to own JID
Phone-->>WMClient: HistorySync ON_DEMAND response
WMClient-->>ChatService: res
ChatService-->>ApiClient: HistorySync data
Sequence diagram for deep on-link history sync configuration in StartClientsequenceDiagram
participant WhatsmeowService as whatsmeowService
participant Store as deviceStore
participant Phone
WhatsmeowService->>Store: StartClient(cd)
WhatsmeowService->>Store: set DeviceProps.Os
WhatsmeowService->>Store: set DeviceProps.RequireFullSync = true
WhatsmeowService->>Store: set DeviceProps.HistorySyncConfig(FullSyncDaysLimit, FullSyncSizeMbLimit, StorageQuotaMb)
Store-->>Phone: registration with DeviceProps
Phone-->>Store: deep HistorySync for newly linked device
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The hard‑coded
HistorySyncConfiglimits (10 years / 2GB) inStartClientare quite opinionated; consider moving them to configuration or at least named constants so deployments can tune history depth and resource usage. - Since
HistorySyncRequestnow always usesSendPeerMessagewithcontext.Background(), consider threading a request/context down into this call so history sync requests can be cancelled or time‑bounded by the caller rather than always using a detached background context.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The hard‑coded `HistorySyncConfig` limits (10 years / 2GB) in `StartClient` are quite opinionated; consider moving them to configuration or at least named constants so deployments can tune history depth and resource usage.
- Since `HistorySyncRequest` now always uses `SendPeerMessage` with `context.Background()`, consider threading a request/context down into this call so history sync requests can be cancelled or time‑bounded by the caller rather than always using a detached background context.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
… + thread caller context - Extract the HistorySyncConfig depth/size limits into named package constants (historyFullSyncDaysLimit / historyFullSyncSizeMbLimit / historyStorageQuotaMb) so deployments can tune them in one place. - Thread the caller's context into HistorySyncRequest instead of a detached context.Background(), so the on-demand history-sync peer message can be cancelled / time-bounded by the request. Signature updated across the ChatService interface, the implementation, and the gin handler (ctx.Request.Context()).
Author
|
Thanks for the review! Addressed both points in ff3542b:
|
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.
Summary
Two small fixes so that message history actually reaches newly linked devices:
On-demand history-sync now delivers.
HistorySyncRequestsent the peer request tomessageInfo.Chat(the contact). Peer messages must be sent to the account's own JID — sending to the contact fails withfailed to encrypt peer message ... no signal session established with <device>and the phone never returns any history. Switched toclient.SendPeerMessage, which whatsmeow documents as the correct way to send aBuildHistorySyncRequest(it targetsgetOwnID().ToNonAD()withPeer: true). The target chat/cursor is already encoded inside the built request, so no information is lost.On-link backfill is now deep.
RequireFullSync = truealone still produced a shallow, uneven backfill because the phone falls back to conservative defaults when noHistorySyncConfigis provided. Setting an explicit deep window makes a freshly linked device receive the full available history.Why
On the current release, after pairing a device:
POST /chat/history-syncreturns200but noHistorySync(ON_DEMAND) event ever arrives — the request 500s internally withno signal session established, and even when a session exists the request is addressed to the wrong JID so the phone has nothing to answer.Together these make it impossible to backfill a conversation's history through the API.
Changes
pkg/chat/service/chat_service.go— send the on-demand request viaSendPeerMessage.pkg/whatsmeow/service/whatsmeow.go— setDeviceProps.HistorySyncConfig(FullSyncDaysLimit,FullSyncSizeMbLimit,StorageQuotaMb).Notes
The
FullSyncDaysLimit/size values are conservative-but-generous defaults; happy to make them configurable via instance settings/env if preferred.Summary by Sourcery
Ensure newly linked devices receive complete message history via on-link and on-demand history sync.
Bug Fixes:
Enhancements: