Skip to content

[Watch + Up Next] Clear replaces properly when performing a login sync#3982

Draft
bjtitus wants to merge 2 commits intotrunkfrom
bjtitus/up-next-clear-replace-on-login
Draft

[Watch + Up Next] Clear replaces properly when performing a login sync#3982
bjtitus wants to merge 2 commits intotrunkfrom
bjtitus/up-next-clear-replace-on-login

Conversation

@bjtitus
Copy link
Contributor

@bjtitus bjtitus commented Feb 20, 2026

📘 Part of: Watch + Up Next Sync

The clearPendingUpNextChangesOnLogin Feature Flag controls this change.

The core bug here is that we were calling clearSyncedData(latestActionTime: latestActionTime) where latestActionTime could be 0 (its default value) after syncing during a login, effectively a no-op.

The theory is the following:

  1. Device is logged out in the background. The logout doesn't actually clear any of the replace changes, I think the intent here is that another account could be logged in and send replace events to the wrong account.
  2. Device is logged back in after reauth with token or manually
  3. Sync is triggered
  4. The UpNextSyncTask makes a call to clearSyncedData but with the default latestActionTime of 0, this leaves unsynced replace changes.
  5. On the next sync after initial login, those replace changes would be sent.

Several of the watch logs indicate logouts which could potentially be more likely to trigger a case like this.

To test

Checklist

  • I have considered if this change warrants user-facing release notes and have added them to CHANGELOG.md if necessary.
  • I have considered adding unit tests for my changes.
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

Copilot AI review requested due to automatic review settings February 20, 2026 02:51
@dangermattic
Copy link
Collaborator

1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@bjtitus bjtitus added the [Project] Watch + Up Next Sync Improvements for Watch + Up Next Sync issues label Feb 20, 2026
@bjtitus bjtitus added this to the 8.7 milestone Feb 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where stale Up Next replace actions persist through login sync and are incorrectly sent on subsequent syncs, potentially clearing the server's queue unexpectedly.

Changes:

  • Added feature flag clearPendingUpNextChangesOnLogin (defaulted to false for gradual rollout)
  • Modified UpNextSyncTask.process() to clear all pending changes using Int64.max during login sync when feature flag is enabled
  • Added comprehensive test coverage in UpNextSyncTaskTests to verify the fix works and doesn't break existing behavior
  • Added unit tests in UpNextChangesDataManagerTests to demonstrate the bug at the database layer

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
Modules/Server/Sources/PocketCastsServer/Public/Sync/UpNextSyncTask.swift Implements the fix: uses Int64.max instead of latestActionTime (which is 0) during login sync to clear all pending changes when feature flag is enabled
Modules/Server/Tests/PocketCastsServerTests/UpNextSyncTaskTests.swift New test file with comprehensive integration tests verifying the fix works, the bug exists when disabled, and normal sync behavior is preserved
Modules/DataModel/Tests/PocketCastsDataModelTests/UpNextChangesDataManagerTests.swift Adds unit tests demonstrating the bug at the database layer and verifying the fix approach


clearSyncedData(latestActionTime: latestActionTime)
// For login syncs, clear all pending changes since we've applied server state
// and any pending changes are stale. See: https://github.com/Automattic/pocket-casts-ios/issues/XXXX
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub issue URL contains a placeholder "XXXX" instead of an actual issue number. This should be replaced with the real issue number before merging.

Suggested change
// and any pending changes are stale. See: https://github.com/Automattic/pocket-casts-ios/issues/XXXX
// and any pending changes are stale after applying the latest server state.

Copilot uses AI. Check for mistakes.
@bjtitus bjtitus force-pushed the bjtitus/up-next-clear-replace-on-login branch from 4aeceb6 to f51129e Compare February 20, 2026 03:43
@bjtitus bjtitus force-pushed the bjtitus/up-next-clear-replace-on-login branch from f51129e to 6473fe7 Compare February 24, 2026 00:51
@pocketcasts pocketcasts modified the milestones: 8.7, 8.8 Mar 2, 2026
@pocketcasts
Copy link
Contributor

Version 8.7 has now entered code-freeze, so the milestone of this PR has been updated to 8.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Project] Watch + Up Next Sync Improvements for Watch + Up Next Sync issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants