fix: recover app-state sync errors safely - #144
Open
joldmarfilho wants to merge 1 commit into
Open
Conversation
Reviewer's GuideImplements a controlled, rate-limited app-state recovery flow for WhatsApp app-state sync errors, including a two-stage retry (full sync then recovery request), logging, and tests ensuring per-collection cooldown behavior. Sequence diagram for controlled app-state sync error recoverysequenceDiagram
actor UserDevice
participant MyClient
participant Logger
participant WAClient
participant PrimaryDevice
UserDevice->>MyClient: myEventHandler(AppStateSyncError)
MyClient->>MyClient: handleAppStateSyncError(evt)
MyClient->>MyClient: reserveAppStateRecovery(evt.Name, evt.FullSync)
alt [cooldown active]
MyClient->>Logger: GetLogger(userID)
Logger-->>MyClient: LogInfo
MyClient-->>UserDevice: [return]
else [allowed]
MyClient->>Logger: GetLogger(userID)
alt [incremental sync failed]
Logger-->>MyClient: LogWarn
MyClient->>WAClient: FetchAppState(ctx, evt.Name, true, false)
else [full sync failed]
Logger-->>MyClient: LogWarn
MyClient->>WAClient: SendPeerMessage(ctx, whatsmeow.BuildAppStateRecoveryRequest(evt.Name))
WAClient-->>Logger: LogInfo
end
end
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:
- Consider clearing or pruning entries in
appStateRecovery(e.g., onAppStateSyncCompletefor a given collection) to avoid unnecessary cooldown after successful recovery and to keep the map from growing over the lifetime of the client. - In
handleAppStateSyncError, the recovery goroutine uses a fresh background context; consider deriving the context from the client or event lifecycle so that recovery attempts are automatically cancelled when the client is shutting down or the session is no longer valid.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider clearing or pruning entries in `appStateRecovery` (e.g., on `AppStateSyncComplete` for a given collection) to avoid unnecessary cooldown after successful recovery and to keep the map from growing over the lifetime of the client.
- In `handleAppStateSyncError`, the recovery goroutine uses a fresh background context; consider deriving the context from the client or event lifecycle so that recovery attempts are automatically cancelled when the client is shutting down or the session is no longer valid.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Description
Related Issue
Closes #(issue_number)
Type of Change
Testing
Screenshots (if applicable)
Checklist
Additional Notes
Summary by Sourcery
Handle WhatsApp app-state sync errors with controlled recovery and add cooldown-based deduplication for recovery attempts.
Bug Fixes:
Tests: