Stalwart-migrate 1.0.3: accounts with no change counter are skipped without warning (their mail is not copied, final run and verify pass)

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

  1. A v0.16.27 store (RocksDB data store, file system blob store) containing an account that has data but whose ChangeId counter 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 shows Mailbox/get state n for it.
  2. stalwart-migrate prepare, then stalwart-migrate run.
  3. Compare account pass started accounts=N (or status) 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 --final and verify compare 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

Thanks for the detailed report. I couldn’t find anything in the current docs that mentions accounts without a change counter, so I can’t confirm your diagnosis from the documentation. I also couldn’t locate the source-v016 adapter source in the repos I can search, so I haven’t verified the accounts() logic you quote.

The docs say verify checks the accounts the migration tracked. They describe --sample as a percentage of accounts and --full as “every account”. They don’t say how the account list is built. That matches what you saw: if an account never enters the list, verify can’t flag it. Reading the docs alone, I can’t say whether this is intended, so it needs a human to confirm.

Until someone confirms, your workaround looks sensible. Before the final run, compare the number of Account objects in the registry with the accounts=N count in the log (or in status). If you write a change to each missing account on 0.16 so the counter exists, you can then confirm that all accounts are copied. Other people reading this should do the same check, especially with mode = "reuse", because unreferenced blobs could be lost.

Relevant docs: Verifying the migration | Stalwart

This isn’t covered in the current docs. A community member or staff member will follow up.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

For whoever picks this up, the code is in the stalwart-migrate repo (tag v1.0.3):

Quick check on any 0.16 server: Mailbox/get on an account that returns state: "n" means there’s no change counter, and such an account won’t be listed by run.

@sphen13 this is fixed in stalwart-migrate 1.0.4, which came out today. The account list now comes from the registry, and an account without a ChangeId counter is listed with counter 0. That means it gets a full copy on the next run, and verify checks it like any other account. Rollback had the same gap and is fixed too.

You’ve already finished with the create-and-delete-a-mailbox workaround, so there’s nothing left for you to do. Anyone who migrated with 1.0.3 or earlier and is already on 1.0 should compare the number of accounts with data on both sides. An account that only exists on 0.16 is one this bug skipped.