First, to be clear on scope: this is about the local desktop app aidulc (an English intensive-reading and shadowing tool), not the AIDU Chrome extension on the Downloads page. Both sync vocabulary through the same Cloudflare Worker—the desktop app pushes words up, and the extension or phone app pulls them down for review.

This round fixed two concrete sync issues: “Sync Now” failing to pull existing cloud words, and a sync setup page with unclear steps. Below is the full breakdown: symptom, sequence of failure, fix steps, and what has not been manually tested yet.


1. 1,000+ Words in the Cloud, Zero Pulled on “Sync Now”

1. Symptom

Over 1,000 vocabulary words were already stored in the cloud, while a fresh local database had 6 words. Clicking “Sync Now” reported “Synced”, yet the local vocabulary list still had only those 6 words.

Clicking the standalone “Pull” button worked normally; only “Sync Now” missed all existing cloud entries.

2. How It Failed (Step by Step)

The Worker maintains a monotonically increasing version number (rev) for the whole deck—every write increments it. The desktop app stores a local cursor (last_pull_rev) recording the last version it pulled.

“Sync Now” runs push first, then pull. The bug happened at the handoff between steps 2 and 3:

  1. Starting state: The cloud has 1,000+ words (say at version 1000). The fresh local database has 6 words, and its local pull cursor is 0.
  2. Push local words: Desktop pushes those 6 words to the cloud. The server accepts them, bumps the deck version to 1006, and returns 1006 in the push response.
  3. Pull cloud words (the bug): Desktop asks the server for all words with version greater than X. It should have passed the local pull cursor 0, but instead passed 1006 from the push response.
  4. Corrupt local cursor: No word on the server has a version greater than 1006, so the server returns an empty list. Desktop then saves 1006 as its local pull cursor and displays “Synced”. Every subsequent sync starts from 1006, leaving the earlier 1,000+ words permanently skipped.

(The standalone “Pull” button was unaffected because it reads local last_pull_rev directly rather than using a push response.)

3. Fix Steps

The fix has three steps:

  1. Read the local pull cursor: Keep the push-then-pull order (so unpushed local edits are not overwritten by remote data), but pass the stored last_pull_rev as the starting version for pull. In the same function, a partial-push-failure branch also skipped pulling while still advancing the pull cursor to the push version—changed it to leave the pull cursor untouched.
  2. Reset already-corrupted local databases: Existing databases stuck at 1006 will not rewind on their own. I added database migration v38, which resets sync_state.last_pull_rev to 0. On the next sync, the app pulls the full cloud deck once and merges by updated_at (newer wins, so newer local edits stay intact). last_push_at is preserved so it does not trigger a full re-push.
  3. Fix the test mock: Previously, the mock worker in tests did not filter rows by word rev > since, so tests passed even with the bug present. I updated the mock to match the real Worker’s filtering and added three regression tests: a fresh device (1 local word + 3 cloud words → 4 words after sync), partial push failure leaving the pull cursor unchanged, and migration v38.

1. What Was Wrong With the Old Layout

After entering a Cloudflare Worker URL, it was unclear how to proceed for three reasons:

  • “Add Backend (Name + URL)” only added an item to a list without connecting;
  • The form that actually exchanged credentials sat on a separate “CF Worker URL + Secret” row below, duplicating the URL field with no guidance;
  • “Scan QR to Pair Phone” and “Add Another Computer” were hidden inside a “More” menu.

2. New Connection Steps

In the November 16 update, the top of the sync page was replaced with a “Connect Sync Server” card. The duplicate URL/token row was removed, and “Add Backend” moved into a collapsed advanced section. Connecting a new computer now takes one of two paths:

Option A: Sync URL + Invite Code or Root Secret

  1. Enter the sync server URL in the first field and a credential (a 6-digit invite code or ROOT_SECRET) in the second field.
  2. A live hint below the input shows which credential type is detected and what is still missing.
  3. Click “Connect”. On failure, the card explains the reason and next step (expired invite code or mismatched ROOT_SECRET), and the self-hosting docs now explain where to find a forgotten ROOT_SECRET.

Option B: Paste a Phone Pairing Link Directly

  1. Copy the pairing link (https://…/#t=<token>&u=<url>) from “Scan QR to Pair Phone” on an already-connected device.
  2. Paste it straight into the credential box on the new computer; the form splits out the URL and token automatically.
  3. Click “Connect”. The new sync_connect_token command verifies the token against the server before saving. Tested against the live server with a fake token, it returns HTTP 401 and refuses to save a connected state.

Once Connected

The card switches to “✓ Connected” and exposes two actions directly:

  • “Add Another Computer”: displays the 6-digit invite code steadily in the card instead of a disappearing toast;
  • “Scan QR to Pair Phone”: shows the QR code and copyable pairing link.

3. Two Trade-Offs of Reusing the Phone Token

Skipping ROOT_SECRET comes with two clear constraints:

  1. Desktop and phone share the same token, so tapping “Revoke this device” on the phone disconnects the desktop as well;
  2. The server user field is unknown on this path and stored as empty; switching to an invite code later will trigger one full re-push (without data loss).

3. Verification Scope

Current status:

  • Verified: The cursor fix, partial-push-failure branch, and v38 migration pass regression tests; credential parsing has 5 unit tests and 9 view smoke tests; fake-token rejection was verified against the live server (HTTP 401).
  • Not yet verified: The new sync guide card and pairing-link paste flow have not been clicked through in a real desktop window yet. Once a manual desktop pass is done, I will record the result.