Issue Description
stalwart-migrate run (and run --final, verify --full) silently skips registered accounts that have no per-account change counter in the v0.16 store. All runs report ok, errors: 0, and verification reports 0 mismatches, because the skipped accounts never enter the account list. In our case 4 of 8 accounts were skipped, including two mailboxes with about 96 GB of mail (roughly 279,000 messages).
With a shared blob store (mode = "reuse", the recommended answer), the skipped accounts’ blobs are not referenced by anything in the v1 store. As we read the docs, 1.0 deletes unreferenced blobs, so cutting over would eventually lose that mail with no warning anywhere in the process. We caught it only because the account count looked wrong.
Cause (from the 1.0.3 source)
crates/source-v016/src/adapter/principal.rs, accounts(), lists accounts by iterating the counter subspace for 4-byte keys (the per-account ChangeId counter). adapter/mod.rs then intersects that with
registry::account_ids():
let mut accounts = principal::accounts(&data).await?;
let registered = registry::account_ids(&data).await?;
accounts.retain(|account| registered.contains(account.account_id));
An account that is registered and has data, but has never had a change written under the current key layout, has no counter key, so it’s never listed. Over JMAP, all four skipped accounts had Mailbox/get state = "n". All four accounts that were copied had real states (sam, svypq, …).
How the accounts got there:
- Two were large mailboxes whose data dates from older versions. The store was created in January 2025 and went 0.15 → 0.16 in place with
migrate_v016.py. Those mailboxes have had no changes since. - Two were created automatically by 0.16 when an LDAP-directory address was looked up, and were never used.
Expected Behavior
Every registered account is migrated. Or, if an account can’t be listed for some reason, the run reports it as an
error, and run --final refuses to finalise.
Actual Behavior
account pass started accounts=4 removed=0, where the registry holds 8 Account objects. status shows Accounts: 4 / done 4. verify --sample 100 checks 4 accounts, 0 mismatches. Nothing appears in report.
Reproduction Steps
- A v0.16.27 store (RocksDB data store, file system blob store) containing an account that has data but whose
ChangeIdcounter key is absent. Two ways to get one: an account that hasn’t changed since before the store was upgraded in place, or one that 0.16 created on directory lookup and that was never used. JMAP showsMailbox/getstatenfor it. stalwart-migrate prepare, thenstalwart-migrate run.- Compare
account pass started accounts=N(orstatus) with the number of Account objects in the registry.
Workaround
Write any change to each affected account on 0.16 before the final run, so the counter is created. As the recovery admin over JMAP, we created and then destroyed an empty mailbox in each account:
["Mailbox/set", {"accountId": "<id>", "create": {"t": {"name": "zz-migrate", "parentId": null}}}, "c"]
["Mailbox/set", {"accountId": "<id>", "destroy": ["<created id>"]}, "d"]
The next incremental run listed all 8 accounts and copied the missing ones (279,089 emails). run --final --verify-full then passed with 8 accounts and 0 mismatches. The migrated server has been working since.
Suggested fix
- Build the account list from the registry, and treat a missing counter as change counter 0.
- Have
run --finalandverifycompare the registry’s Account count with the tracked accounts, and fail on a difference.
Relevant Log Output
INFO migrate::orchestrator::job: account done account_id=105 checkpoint=3
INFO migrate::orchestrator::job: account done account_id=104 checkpoint=3
INFO migrate::orchestrator::job: account done account_id=98 checkpoint=4014
INFO migrate::orchestrator::job: account done account_id=34 checkpoint=3
INFO migrate::orchestrator: run finished run_id=1 status=ok ... "accounts_full":4,"errors":0 ...
verify: 4 accounts checked, 0 mismatches, 0 not explained by earlier reports (ok)
-- after touching accounts 38, 94, 106, 107 --
INFO migrate::orchestrator::account: account pass started accounts=4 removed=0
INFO migrate::orchestrator::job: account done account_id=107 checkpoint=3
INFO migrate::orchestrator::job: account done account_id=106 checkpoint=3
INFO migrate::orchestrator::job: account done account_id=38 checkpoint=2
INFO migrate::orchestrator::job: account done account_id=94 checkpoint=2
INFO migrate::orchestrator: run finished run_id=3 status=ok ... "accounts_full":4,"accounts_unchanged":4,"emails_written":279089 ...
Stalwart Version
v1.x
Installation Method
Binary (Linux)
Database Backend
RocksDB
Blob Storage
Filesystem
Search Engine
Internal
Directory Backend
LDAP
Additional Context
This differs from “Missing Emails after v1.0.0 migration” (#2069), which was caused by
starting 0.16 against the new store.
I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.
on
I have searched this support forum (open and closed topics) and confirm this is not a duplicate.
on
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
on