Issue Description
On v1.0.0, when two JMAP (or IMAP) imports into the same account start the same new thread at the same moment, each import first gets its own thread. A ThreadRecheck after commit then merges the two threads. Because the JMAP email id is built from the thread id and the document id, the merged email gets a new id. Email/query and Email/changes list only the new id, and never report the old one as destroyed. The id Email/import returned still resolves through Email/get, but with the old threadId. RFC 8621 §4.1.1 makes both id and threadId immutable, so a client that stored the import-time id loses track of the email for good, and nothing signals it. It happens in about 1 in 5 parallel-import races on v1.0.0 and never on v0.16.27 (0 of 15 runs). SMTP delivery doesn’t take this path.
Expected Behavior
RFC 8621 §4.1.1 marks id and threadId as immutable. The id Email/import returned should stay the email’s id after the thread is merged. Failing that, Email/changes should report the old id as destroyed and the new one as created, so a client that stored the import’s id can follow it.
Actual Behavior
for JMAP and IMAP ingests, ingest.rs:809-830 keeps a PendingThread. After commit, ThreadRecheck (message/ingest/recheck.rs, scheduling at line 111) finds the second thread created for the same messages and queues MergeThreads. The merged email moves to the other thread, and since the JMAP id is built from thread id and document id, its id changes. Meanwhile Email/get still accepts the old id, with the stale threadId.
Reproduction Steps
Two JMAP clients, in parallel, on one new account, each:
Email/getwithids: []→state: "n"- upload the same message (same Message-ID) and
Email/importit into the inbox Email/seta keyword on the returned idEmail/changesfrom"n"untilhasMoreChangesis false
In about 1 in 5 runs, one import returns an id that never appears again:
Email/import -> created {"e": {"id": "iaaaaac", "threadId": "c"}} newState "sam"
Email/changes (since "n") -> created ["eaaaaab", "eaaaaac"], updated [], newState "say"
Email/query -> ids ["eaaaaab", "eaaaaac"]
Email/get ["iaaaaac", "eaaaaac"] -> both found: iaaaaac threadId "c", eaaaaac threadId "b"
Asking Email/changes again later from "n" gives the same result. The same two clients against v0.16.27 never produce this (0 of 15 runs).
Stalwart Version
v1.x
Installation Method
Docker
Database Backend
RocksDB
Blob Storage
RocksDB
Search Engine
Internal
Directory Backend
Internal
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