Skip to content

Prevent first-time sync enable from overwriting remote settings#528

Draft
Copilot wants to merge 7 commits intomasterfrom
copilot/fix-settings-sync-behavior
Draft

Prevent first-time sync enable from overwriting remote settings#528
Copilot wants to merge 7 commits intomasterfrom
copilot/fix-settings-sync-behavior

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

Enabling settings sync on a new browser instance could upload an effectively empty local config before reading existing synced data, wiping settings on other devices. This changes first-time sync enable to pull from the configured backend first, merge once, and only upload when needed.

  • Initial sync enable flow

    • Intercept SettingsPageSaveOptions when syncSettings transitions from disabled to enabled.
    • Skip the normal immediate saveAllSync() path for that first enable.
    • Run a dedicated initial sync merge instead of pushing local state first.
  • One-time merge behavior

    • Read existing data from the selected sync backend (browser sync or WebDAV).
    • If sync data exists, treat it as the base state and merge local data into it.
    • If sync data is missing/empty, upload the current settings as the initial synced state.
  • Merge rules

    • Merge proxy servers, server subscriptions, smart profiles, rules, and rule subscriptions.
    • Avoid duplicate profiles by matching in priority order: profile id, builtin profile type, then profile name.
    • Avoid duplicate rules by comparing rule identity fields rather than appending blindly.
    • Preserve the existing sync option semantics through the normal applySyncSettings path.
  • Post-merge sync behavior

    • Upload the merged config only when the merge actually adds local data beyond the remote state.
    • If nothing changes after merge, do not perform a redundant upload.
  • Runtime consistency

    • Reload subscription timers/loaders after the initial merge flow so merged subscriptions take effect immediately.
    • Restore the previous options in memory if the initial sync read fails before completion.

Example of the new control flow:

if (!syncWasEnabled && message.options.syncSettings) {
	settingsOperationLib.performInitialSyncMerge(
		() => proxyEngineLib.updateBrowsersProxyConfig(),
		(error: Error) => {
			settingsLib.current.options = previousOptions;
		}
	);
	return true;
}

Copilot AI and others added 5 commits April 9, 2026 00:34
Agent-Logs-Url: https://github.com/salarcode/SmartProxy/sessions/69f46906-6c9e-45c5-8d08-6a4715b56051

Co-authored-by: salarcode <1272095+salarcode@users.noreply.github.com>
Agent-Logs-Url: https://github.com/salarcode/SmartProxy/sessions/69f46906-6c9e-45c5-8d08-6a4715b56051

Co-authored-by: salarcode <1272095+salarcode@users.noreply.github.com>
Agent-Logs-Url: https://github.com/salarcode/SmartProxy/sessions/69f46906-6c9e-45c5-8d08-6a4715b56051

Co-authored-by: salarcode <1272095+salarcode@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix settings sync behavior for new browser installations Prevent first-time sync enable from overwriting remote settings Apr 9, 2026
Copilot AI requested a review from salarcode April 9, 2026 00:41
@salarcode salarcode requested a review from Copilot April 10, 2026 02:15
Copy link
Copy Markdown

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 adjusts the “enable settings sync” flow to avoid pushing an effectively empty local configuration on first enable (which could wipe existing synced settings). Instead, it pulls from the configured backend first, performs a one-time merge, and only uploads if the merge actually adds data.

Changes:

  • Added an initial-sync merge flow in SettingsOperation that reads from the configured backend, merges local into remote, applies merged settings, and conditionally uploads.
  • Implemented merge helpers for proxy servers, proxy server subscriptions, smart profiles (including rules and rule subscriptions), plus a post-merge subscription reload.
  • Updated the SettingsPageSaveOptions handler to intercept the first transition to syncSettings = true and route through the initial merge flow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/core/SettingsOperation.ts Adds initial-sync read/merge/apply logic and merge utilities to prevent first-time enable from overwriting remote.
src/core/Core.ts Intercepts first-time sync enable during options save and runs the new initial merge flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Change strict equality to loose equality for matching
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.

Download settings for a new browser, rather the uploading empty settings.

3 participants