mastra-ai/mastra · error

Notification ${input.id} was not found for thread ${threadId

Error message

Notification ${input.id} was not found for thread ${threadId}

What it means

The deliver action resolves notifications from the thread and, if an explicit input.id was requested but no matching notification is returned, throws this error. It ensures a targeted delivery request fails loudly rather than silently delivering nothing or the wrong batch.

Source

Thrown at packages/core/src/notifications/tool.ts:138

            priority: input.priority,
            source: input.source,
            limit: input.limit,
          }),
        };
      }

      if (input.action === 'read') {
        const notifications = input.id
          ? [await storage.getNotification({ threadId, id: input.id })]
          : await storage.listNotifications({
              threadId,
              status: input.status ?? ['pending', 'delivered'],
              priority: input.priority,
              source: input.source,
              limit: input.limit,
            });
        if (input.id && !notifications[0])
          throw new Error(`Notification ${input.id} was not found for thread ${threadId}`);
        return deliverNotifications({
          notifications: notifications.filter((notification): notification is NotificationRecord =>
            Boolean(notification),
          ),
          storage,
          context,
        });
      }

      if (!input.id) throw new Error(`notification-inbox ${input.action} requires id`);
      const statusByAction = {
        markSeen: 'seen',
        dismiss: 'dismissed',
        archive: 'archived',
      } satisfies Record<'markSeen' | 'dismiss' | 'archive', NotificationStatus>;

      return {
        notification: await storage.updateNotification({

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Check the notification exists with the right status via listNotifications before delivering
  2. Widen the status filter if the target notification may already be seen/dismissed
  3. Confirm the id belongs to the same threadId
  4. Handle the error and inform the user the notification no longer exists

Example fix

// before
await inboxTool.execute({ action: 'deliver', threadId, id: 'old-id' });
// after
const [n] = await storage.listNotifications({ threadId, id: 'old-id' });
if (n) await inboxTool.execute({ action: 'deliver', threadId, id: 'old-id' });
Defensive patterns

Strategy: validation

Validate before calling

const [target] = await storage.listNotifications({ threadId, id, status: ['pending', 'delivered'] });
if (!target) throw new Error(`Cannot deliver: notification ${id} not found or not deliverable`);

Type guard

function isDeliverable(n: NotificationRecord | undefined): n is NotificationRecord {
  return Boolean(n && (n.status === 'pending' || n.status === 'delivered'));
}

Try / catch

try {
  await inboxTool.execute({ action: 'deliver', threadId, id }, context);
} catch (e) {
  if (e instanceof Error && e.message.includes('was not found for thread')) {
    logger.warn('Deliver target missing', { threadId, id });
    return { delivered: 0 };
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the tool with action 'deliver' and an id that does not exist in the thread, has been dismissed/archived (filtered by the status filter ['pending','delivered']), or was persisted under a different threadId.

Common situations: Stale notification ids after storage reset; trying to deliver an already-seen/dismissed notification while the status filter excludes it; cross-thread id reuse.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/1b7f858c2525bb05. Report an issue: GitHub.