Sync engine crash-loops with no such table: MessageFolder when PRAGMA user_version is ahead of the actual schema (V10 silently skipped)

Summary

After updating to Mailspring 1.26.0 (1.26.0-3b46a5b1, macOS <version / chip>, previously on <1.25.0?>), all five accounts (2 Gmail, 2 Outlook, 2 generic IMAP) went into “Sync error”. Reconnect briefly appeared to work, then each account failed again.

This is probably not a general regression. My local database had been run by a non-release build earlier (see “Unconfirmed” below), and the engine does not notice that its schema doesn’t match the version number. I’m filing this as a hardening request and a recovery recipe for others in the same situation.

Symptom

Every sync worker dies shortly after the folder list syncs, with this exception (account names, hosts and token IDs removed):

[background] [info] Syncing folder list...
[background] [info] syncFolderUIDRange for <folder>, UIDs: <n> - <n>, Heavy: true
[background] [critical]
*** Mailspring Sync
*** A C++ exception occurred during program execution:
*** no such table: MessageFolder

On generic IMAP accounts it appears in the CONDSTORE path (syncFolderChangesViaCondstore ... N changed) instead. The process restarts and fails again. No database dialog was shown at launch.

What the database looked like (measured)

  • PRAGMA user_version returned 12.
  • sqlite_master had Message and MessageBody but no MessageFolder or MessageOrphan.
  • Message still had the old columns remoteFolderId, remoteUID and remoteXGMLabels.
  • The old index MessageUIDScanIndex was present, and MessageFolder*/MessageListDateIndex indexes were not.
  • Event had recurrenceId (V9 applied).
  • PRAGMA quick_check returned ok. The installed mailsync binary contains the V10 CREATE TABLE ... MessageFolder SQL, so the release ships the migration.

Analysis (from reading source only; I did not build or debug the engine)

In Mailspring-Sync 675e9f2 (the commit pinned by the 1.26.0 tag), MailStore::migrate() runs _migrateToV10 only when user_version < 10. With the version already at 12, V10 was skipped, --mode migrate exited 0 and printed nothing, and the sync workers then ran V10-era queries against the pre-V10 schema.

V10 itself is transactional, so I cannot explain from the 1.26.0 source how a database ends up at 12 with the old schema.

Unconfirmed

  • How the version got ahead. My best guess is that I previously ran a locally built performance dev branch on the same profile, and that it recorded a user_version of 10 or higher without the release’s V10 schema change. I have not confirmed which branch it was or what version number it wrote. <fill in if checked: branch, its CURRENT_VERSION, its migrations>
  • Nothing else is known to have touched the file (no restore from backup that I’m aware of).

Recovery that worked for me

With Mailspring and all mailsync processes quit and a full copy of the config folder made first:

sqlite3 "$HOME/Library/Application Support/Mailspring/edgehill.db" "PRAGMA user_version = 9;"

Relaunching ran V10 to V12 (a brief “upgrading database” popup), after which all accounts synced normally. Afterwards user_version was 12 and MessageFolder, MessageOrphan and their indexes existed. Counts after the migration: Message 33543, MessageFolder 33548, MessageOrphan 0. I assume the five extra placements are messages that live in more than one folder, but I haven’t checked.

Caution: running that same command a second time, after the migration had already succeeded, makes the next launch fail with “We encountered a problem with your local email database. Error: no such column: remoteFolderId” and a Rebuild prompt. I did this by accident. The fix was to set the version back to 12.

Suggestion (low priority)

Consider having the engine confirm that the tables expected for the recorded schema version exist. If they don’t, it could re-run the missing step, or stop with a clear message pointing at the database, instead of crash-looping with a bare SQLite error. This only matters for databases touched by a non-release build.

Environment

  • Mailspring 1.26.0-3b46a5b1, macOS <version / chip>
  • edgehill.db about 195 MB, five accounts