Verify reports unexplained “differs in the target: keywords” mismatches after run --final (v0.16.27 → v1.0.0, RocksDB)

Issue Description

verify reports unexplained “differs in the target: keywords” mismatches after run --final (v0.16.27 → v1.0.0, RocksDB)

Stalwart Version

v0.16.x

Installation Method

Binary (Linux)

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

Additional Context

Setup: Stalwart v0.16.27 (official binary, enterprise build), single node, RocksDB data + blobs in the same store, ~4 GB, 6 accounts. stalwart-migrate v1.0.0 (standard build), target: new empty RocksDB directory.

Steps: prepare (0 errors) → run with v0.16 live → stop v0.16 → run --final --allow-errors (only errors were 6 SpamTrainingSample objects whose blobs are missing in the source).

Result: Finalize completed, but verification failed: 6 accounts checked, 598 mismatches, 592 not explained by earlier reports. Reproducible with a separate verify run (same numbers).

Mismatches:

110 × email … differs in the target: keywords, only accounts 3 and 4, in contiguous document-id ranges (e.g. 596–614, 1073–1089)
118 × telemetry span … differs in the target (not “missing”)
6 × the accepted SpamTrainingSample errors

The copy runs did not report any change for these emails (no info/warning rows for accounts 3 and 4 besides the verify rows). --log-level debug verify shows no detail about which keywords differ.

Questions: Is this a verifier issue or are keywords actually lost/changed during the copy? Is there a way to output the source and target keyword sets for a mismatching email?

migrate-status:

State database: /var/lib/stalwart-migrate/state.sqlite
tool_version 1.0.0
edition enterprise
source_def_hash 9ad418df48bb0f251deccc3b8677dfd5
target_def_hash 81a023434b1f436a83ae7694b8f90b9f
target_schema_version 7
categories settings,principals,mail,calendars,contacts,files,sieve,identities,push_subscriptions,spam_samples,reports,archive,spam_model,queue,tasks,telemetry
created_at 2026-10-26T20:09:56Z
accepted_errors 3
final_generation done 3
source_store directory /var/lib/stalwart
target_claim f65a41a560b2561c4c9008042a8be1b3
claim_generation 6f18ce5ae07545bf8541286993c1b28d
claim_generation_pending 6f18ce5ae07545bf8541286993c1b28d
final_done not done

Accounts: 6
done 6

Recent runs:
#5 verify failed started 2026-10-26T20:20:58Z took 12s
accounts_checked=6, mismatches=598, unexplained=592
#4 verify failed started 2026-10-26T20:16:49Z took 12s
accounts_checked=6, mismatches=598, unexplained=592
#3 final ok started 2026-10-26T20:16:18Z took 31s
accounts_unchanged=6, blob_bytes=3771, blobs_copied=1, global_records=31, issues=38
#2 final failed started 2026-10-26T20:14:14Z took 31s
accounts_unchanged=6
#1 incremental failed started 2026-10-26T20:09:56Z took 33s
accounts_full=6, blob_bytes=4472032060, blobs_copied=13637, bytes_written=3806410556, emails_written=9493, errors=6, global_records=43925, issues=147, log_rows=54649, objects_written=13463, registry_dropped=12, registry_written=14932

Reports in the latest run:
verify mismatch 218

Reports in all runs:
error skipped 6
info changed 107
info dropped 2
verify mismatch 436
warning dropped 70

It’s a verifier problem in 1.0.0, not lost keywords. Stalwart 1.0 sets $hasattachment or $hasnoattachment on every message from its content, while 0.16 kept whatever a client had stored, and 1.0.0 compared the two. The contiguous ranges in accounts 3 and 4 are messages where they disagreed, most likely tagged in bulk by one client. stalwart-migrate 1.0.1 leaves those two keywords out of both the copy and the check, so there’s nothing to print anymore.

1.0.1 also changed how trace spans are converted, in particular the timestamps inside their events, which should clear the telemetry rows as well.

Since 1.0.0 already wrote those emails and spans into the target, I’d start over with 1.0.1: a new, empty RocksDB directory and a new state directory. If 1.0 is already serving mail from the store you migrated into, tell me before you redo anything.

I’m getting this “differs in the target: keywords” verification error on 50 emails with stalwart-migrate 1.0.2 (just tried that version. It also fails on 1.0.1).

@ad1217 the attachment keywords were what tripped TAVeek’s run on 1.0.0, but they’re filtered out on both sides since 1.0.1, so your 50 rows come from something else. I went through how 1.0.2 converts and compares keywords and haven’t found another case where the two sides could disagree, and the verify row doesn’t say which keyword differs, so I need a bit more from you.

Did the 1.0.2 run start from a new, empty target and a new state directory, or did it continue a state that 1.0.0 or 1.0.1 had already written to? And please post the output of stalwart-migrate status --state <your state dir>, plus the rows that stalwart-migrate report --state <your state dir> --account <id> prints for one of the accounts with mismatches. If those emails have something in common (one folder, tagged by one client, Thunderbird or Apple Mail labels), that would help too.

@ad1217 stalwart-migrate 1.0.3 is out, and its verify rows now name the keywords that differ, for example:

differs in the target: keywords (keywords only in the source: "$label1"; only in the target: none)

Verify doesn’t change either store, so you can run 1.0.3 against the state and target you already have, with the same --source and --target as before:

stalwart-migrate verify --source <0.16 config> --target <1.0 config> --state <your state dir> --full
stalwart-migrate report --state <your state dir> --severity verify

The rows from the new run carry the keyword lists. Post a few of them here; they should show what’s going on with your 50 emails.

Yeah, that helps. This appears to be my fault:
8 verify mismatch 0 email 58355 differs in the target: keywords (keywords only in the source: "\\seen"; only in the target: none) (all 50 have the same message). I vaguely remember having typo’ed that (two backslashes instead of one) in a sieve script at some point in the past. Not sure how to fix it though, as JMAP returns no results for that keyword. Knowing this is the issue, ideally I’d just be able to ignore it and proceed.

JMAP query returning no results
{
  "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
  "methodCalls": [
    [
      "Email/query",
      {
        "accountId": "a",
        "filter": {
          "hasKeyword": "\\\\seen"
        },
        "limit": 1000
      },
      "s0"
    ]
  ]
}

("hasKeyword": "\\seen" correctly produces the same results as $seen)

This is running 1.0.3 on the partially completed output from 1.0.2, which was done with a clean state dir and output dir.

stalwart-migrate status output
State database: /var/lib/stalwart-migrate/state.sqlite
tool_version           1.0.3
edition                community
source_def_hash        c19b9455d0b6fa5e6ead29d3335332c2
target_def_hash        4cd7aaf275746d4da2e1071ca06fbb85
target_schema_version  2147483655
categories             settings,principals,mail,calendars,contacts,files,sieve,identities,push_subscriptions,spam_samples,reports,archive,spam_model,queue,tasks,telemetry
created_at             2026-10-27T21:15:28Z
final_generation       done 5
source_store           directory /var/lib/stalwart/data
target_claim           6873209f1ea82c82b13d89d8543648d5
claim_generation       9e564e5edce06ff6b0824ca54e1e5faa
claim_generation_pending 9e564e5edce06ff6b0824ca54e1e5faa
final_done             not done

Accounts: 4
  done                  4

Recent runs:
  #8     verify       failed       started 2026-10-28T14:02:20Z  took 118s
         accounts_checked=4, mismatches=50, unexplained=50
  #7     incremental  ok           started 2026-10-28T14:02:01Z  took 1s
         accounts_delta=2, accounts_unchanged=2, blob_bytes=340025, blobs_copied=9, bytes_written=355095, emails_written=10, issues=40, log_rows=22, objects_written=21, registry_written=3
  #6     verify       failed       started 2026-10-27T22:06:13Z  took 48s
         accounts_checked=4, mismatches=50, unexplained=50
  #5     final        ok           started 2026-10-27T22:05:42Z  took 31s
         accounts_unchanged=4, global_records=22, issues=57
  #4     verify       failed       started 2026-10-27T21:37:07Z  took 52s
         accounts_checked=4, mismatches=50, unexplained=50

Reports in the latest run:
  verify   mismatch             50

Reports in all runs:
  info     changed             170
  info     dropped               6
  verify   mismatch            200
  warning  changed               1
  warning  dropped             189
  warning  skipped              60

@ad1217 that \seen keyword is harmless. 1.0 reads \seen as another spelling of $seen, so the migration stored those 50 messages with $seen and nothing was lost. The bug was in verify: it compared keywords as plain strings, so \seen looked missing from the target. I’ve changed it to compare keywords the way the copy stores them, and the fix ships in the next stalwart-migrate release.

--allow-errors only accepts copy errors, never verification mismatches, so the run can’t be marked done before that release. Once it’s out, run run --final again with the same --state, --source and --target. It picks up where you are, so there’s no need to start over.

Thanks a lot for the quick fix — confirming it’s resolved on my side.

I started over with stalwart-migrate 1.0.3, a new empty target and a new state directory, and the migration went through cleanly:

verify: 6 accounts checked, 10 mismatches, 0 not explained by earlier reports (ok)

The 10 mismatches are only SpamTrainingSample objects whose blobs were already missing in the 0.16 source, accepted with --allow-errors. (Side note: that number grew from 6 to 10 between Monday and today, so 0.16 apparently keeps producing such orphaned samples.)

After the final run I switched over with the official install.sh and am now on 1.0.1 (RocksDB, single node). IMAP logins with app passwords, inbound and outbound mail, TLS and DANE all work as before.

Great work on the migration tooling and the fast turnaround!

Greetings

@ad1217 1.0.4 is released with the \seen verify fix (it took a day longer than planned, see Stalwart-migrate 1.0.4 failed to release). Run run --final again with the same --state, --source and --target. It resumes where it stopped, and those 50 messages should no longer show up as mismatches.

I wound up rerunning it with a clean state/target as it produced some other errors on my first attempt with the existing data, but I’ve now successfully migrated with 1.0.4. Thanks!