← Context/ issues

Backfilled Mail Has No Conversation IDs

Only 221 of about 42,700 indexed messages carry a conversation ID: the ones the Worker synced itself. The backfill indexed everything else before reading the metadata that holds the ID, and never goes back.

Related: Backfill-Runs-Ended-Before-Writing-Status, Plan-C3-Backfill-Index-From-R2.

What we saw

Claude, in its first session with the connector (2026-11-27), said messages on the work accounts had no conversation ID, and read_message came back with an empty thread, so a back-and-forth can't be followed. It saw IDs only on Gmail.

The index says the problem is wider than that. Primary messages in D1:

AccountMessagesWith thread_idSynced live by the WorkerLive with thread_id
Gmail41,249220221221
humain.vc714111
mandatory.ventures714000

So it isn't about Workspace against Gmail. Mail the Worker synced itself always has a conversation ID; mail the backfill indexed from R2 almost never does.

Why

  • The live path asks for X-GM-THRID whenever the server advertises X-GM-EXT-1 (sync-worker/src/imap.ts, isGmail), which Workspace accounts do, and stores it on the row.

  • The backfill (sync-worker/src/backfill.ts) takes thread_id from the account's r2_meta row for that message. r2_meta is filled by reading the meta/ files a page at a time (metaBudget), so a large account's metadata arrives over many runs.

  • Indexing doesn't wait for it. A message indexed before its meta row exists gets threadId: null. Later runs find the message already indexed (outcome.status === "exists") and skip it, so the ID that arrives later is never written.

r2_meta agrees: the 1,218 Gmail rows read so far all have a thread_id. The data exists; it just landed after the messages were indexed.

Fix

  1. Backfill the column once. Write thread_id onto existing rows from r2_meta where the row has none (matched by account and sha256). One UPDATE per account, run after the meta read finishes.

  2. Stop it recurring. Either hold indexing for an account until its meta read is done, or have the meta read update messages.thread_id for rows that already exist. The second is simpler and survives any ordering.

  3. Check the meta files exist for the work accounts. humain.vc has 1 meta row and mandatory.ventures has none. If the laptop never wrote meta files for them, step 1 can't help, and those accounts need either a one-off X-GM-THRID fetch by UID or the fallback below.

  4. Fallback threading for mail without an ID. Group by References and In-Reply-To (both already in the stored message), with normalized-subject matching as a last resort. This also covers any future non-Google account.

How we'll know

  • The D1 table above shows thread_id on nearly every row for every account.

  • read_message on a work-account reply lists the rest of its conversation.

Resolved (2026-11-27)

The laptop index turned out to hold every message's conversation id (100% on all four accounts), so step 3's worry didn't apply and step 4's fallback isn't needed yet.

  • mail/push_meta_to_d1.py writes the laptop's per-message metadata (mailbox, UID, flags, labels, thread id) into D1's r2_meta and fills thread_id on rows already indexed. Run for humain.vc, mandatory.ventures, and Gmail: 230,938 r2_meta rows.

  • fillThreadIds in sync-worker/src/backfill.ts does the same fill when an account's meta read finishes, so the ordering can't strand ids again. Test: backfill.test.ts, "rows indexed before their meta arrived…".

  • After: humain.vc 714 of 714, mandatory.ventures 714 of 714, Gmail 44,092 of 44,100 indexed rows have a thread_id. Gmail's remaining backfill picks the ids up from r2_meta as it indexes.

  • Threading by References / In-Reply-To stays a fallback for any future non-Google account.