Foundry376/Mailspring · error

Cannot find thread ${message.threadId} to process mail rules

Error message

Cannot find thread ${message.threadId} to process mail rules.

What it means

processMessages could not load the Thread for a message's threadId before applying rule actions, which operate on threads. Fires when the message is a draft/outbox-only message, the thread was deleted, or the database read raced with a sync deletion.

Source

Thrown at app/src/mail-rules-processor.ts:190

        const allMatching = messages.filter((message) => this._checkRuleForMessage(rule, message));

        // Rules are declared at the message level, but actions are applied to
        // threads. To ensure we don't apply the same action 50x on the same thread,
        // just process one match per thread.
        const seenThreadIds = new Set<string>();
        const matching = [];
        for (const message of allMatching) {
          if (!seenThreadIds.has(message.threadId)) {
            seenThreadIds.add(message.threadId);
            matching.push(message);
          }
        }
        for (const message of matching) {
          // We always pull the thread from the database, even though it may be in
          // `incoming.thread`, because rules may be modifying it as they run!
          const thread = await DatabaseStore.find<Thread>(Thread, message.threadId);
          if (!thread) {
            console.warn(`Cannot find thread ${message.threadId} to process mail rules.`);
            continue;
          }
          await this._applyRuleToMessage(rule, message, thread);
        }
      } catch (err) {
        // Errors during condition evaluation (e.g. invalid regex) should disable
        // the rule rather than crash the entire processor and block other rules.
        Actions.disableMailRule(rule.id, err.toString());
      }
    }
  }

  _conditionTemplateMap: Map<string, (typeof ConditionTemplates)[number]> | null = null;

  _getConditionTemplateMap() {
    if (!this._conditionTemplateMap) {
      this._conditionTemplateMap = new Map();
      for (const t of ConditionTemplates) {

View on GitHub (pinned to 648c685d60)

Solutions

  1. Ignore if the thread was deleted concurrently; the rule will apply to remaining messages
  2. Re-run mail rules after sync completes so threads are loaded
  3. Check for messages without valid thread associations (e.g. pending drafts)
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at app/src/mail-rules-processor.ts:190 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Foundry376/Mailspring@648c685d60 (2026-09-03). Data as JSON: /api/errors/05f42f2ff23da0b5. Report an issue: GitHub.