Skip to content

fix: skip sync when the OS reports disconnected - #5694

Open
haydenholligan wants to merge 2 commits into
ankitects:mainfrom
haydenholligan:fix/offline-sync
Open

haydenholligan wants to merge 2 commits into
ankitects:mainfrom
haydenholligan:fix/offline-sync

Conversation

@haydenholligan

@haydenholligan haydenholligan commented Sep 25, 2026 •

Copy link
Copy Markdown

Linked issue (required)

Closes #5693

Summary / motivation (required)

Prevent an intermittent long sync wait after losing connectivity. Use Qt's cached native network status to skip collection and media sync when the OS reports Disconnected. Manual Sync shows Anki's existing translated warning dialog; automatic startup/shutdown sync skips silently.

Steps to reproduce (required, use N/A if not applicable)

  1. Open stock Anki 26.09.2 on macOS and make an online sync request.
  2. Keep Anki open, turn Wi-Fi off, and click Sync after disconnection.
  3. Observe a possible long wait before the network error.

This is conditional: our first request after disconnection took 45–51 seconds, while cold-start and later offline attempts could fail immediately.

How to test (required)

Checklist (minimum)

  • I ran ./ninja check or an equivalent relevant check locally.
  • I added or updated tests when the change is non-trivial or behavior changed.

Details

  • just test-py passed before rebasing; just check passed again after rebasing onto main. The check used Anki's local contributor-email allowlist.
  • Regression tests cover offline skips, completion callbacks, reconnection eligibility, unknown/unavailable status, custom servers, and pending-change status.
  • Real Wi-Fi-off A/B test used isolated 26.09.2 app copies and disposable profiles. Stock failed after 45.8 seconds; the patched handler returned in 0.4 seconds with a warning and no collection-sync request.
  • AnkiWeb credentials were deliberately invalid; this does not claim successful authenticated AnkiWeb sync. Installed Anki and the real collection were unchanged.

Before / after behavior (optional)

Before: attempts sync while offline; failure can be immediate or delayed.
After: definite offline status prevents the request and gives immediate manual feedback.

Risk / compatibility / migration (optional)

Native reachability is advisory and may be inaccurate. Unknown/unavailable status and custom sync servers retain normal behavior. Background sync-status checks remain unchanged. This does not shorten timeouts while reported online, cancel an in-flight sync, or force collection sync on reconnection.

UI evidence (required for visual changes; otherwise N/A)

Stock Anki versus offline-sync fix during a real Wi-Fi disconnect

Stock waited 45.8 seconds; the patched handler returned in 0.4 seconds with the standard warning dialog and no sync request. Recorded from real app frames on the release-based revision before rebase; both patches were unchanged by rebase. GIF playback is 4x; captions show measured real timings. This demonstrates the intermittent delay after an online request followed by disconnection, not every offline attempt.

Scope

  • This PR is focused on one change (no unrelated edits).

Initialize Qt's native network information backend and use definite offline
status to skip automatic collection and media sync. Manual collection sync
shows the existing offline message immediately. Allow requests when network
status is unknown or a custom sync server is configured.

Keep the existing background status calculation so locally pending changes
continue to update the sync indicator while offline.

Cover offline callbacks, manual sync, reconnection, unsupported reachability,
custom servers, media sync, and pending local status updates in Qt tests.

Validation: just test-py and just check. The pending-status regression tests
fail with the removed guard and pass without it. A prior physical Wi-Fi-off
A/B test reproduced a 45-second stock wait and an immediate offline response
from the patched manual handler using disposable profiles.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 Anki | 🛠️ Build #34759443 | 📁 Comparing a296f18 against latest (618c178)

  🔍 Preview build  

5 files changed · + 1 added · ± 4 modified

+ Added

± Modified

This branch has not been deployed

No deployments
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.

Sync can take about 45 seconds to fail after disconnecting Wi-Fi on macOS

1 participant