mastra-ai/mastra · error

Notification summary is missing agentId

Error message

Notification summary is missing agentId

What it means

sendNotificationSummary batches multiple pending notifications into one summary signal delivered through the first record's agent. This error is thrown when the first record of a batch has no `agentId`, which is required to resolve the agent that receives the summary. Like the per-record variant, it signals a corrupted or non-standard record in storage.

Source

Thrown at packages/core/src/notifications/dispatcher.ts:194

    deliveredSignalId: result.signal.id,
    lastDeliveryAttemptAt: now,
  });
  return { record: updated, signal: result.signal };
}

async function sendNotificationSummary({
  mastra,
  storage,
  records,
  now,
}: {
  mastra: Mastra;
  storage: NotificationsStorage;
  records: NotificationRecord[];
  now: Date;
}): Promise<{ records: NotificationRecord[]; signal: CreatedAgentSignal }> {
  const first = records[0];
  if (!first?.agentId) throw new Error('Notification summary is missing agentId');
  if (!first.resourceId) throw new Error('Notification summary is missing resourceId');

  const agent = (await mastra.getAgentById(first.agentId as never)) as NotificationDispatchAgent;
  const summary = summarizeNotifications(records);
  const signal = createNotificationSummarySignal(summary);
  // The all-low-priority batch persists without waking, so it never starts a
  // run and needs no stream options.
  const allLowPriority = records.every(record => record.priority === 'low');
  const streamOptions = allLowPriority
    ? undefined
    : await resolveIfIdleStreamOptions(mastra, agent, {
        record: first,
        threadState: agentThreadStreamRuntime.getThreadState(
          { resourceId: first.resourceId, threadId: first.threadId },
          agent.getPubSub?.(),
        ),
        now,
      });

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure all notifications are created through the official API so agentId is always set on every record in a batch.
  2. Backfill agentId on stored records missing it, or drop them from the batch.
  3. Guard batching code so records arrays passed to the summary path are non-empty and validated (filter out records without agentId before flushing).
  4. Audit your storage adapter/migrations for writes that omit agentId.

Example fix

// before
await flushSummary(allPendingRecords); // may contain records without agentId
// after
const deliverable = allPendingRecords.filter(r => r.agentId && r.resourceId);
if (deliverable.length) await flushSummary(deliverable);
Defensive patterns

Strategy: validation

Validate before calling

if (!records.length || !records[0]?.agentId) {
  logger.warn('Skipping summary batch: first record missing or lacks agentId');
  return;
}

Type guard

function isSummarizable(records: NotificationRecord[]): records is [NotificationRecord & { agentId: string; resourceId: string }, ...NotificationRecord[]] {
  const first = records[0] as (NotificationRecord & { agentId?: string; resourceId?: string }) | undefined;
  return !!first && typeof first.agentId === 'string' && typeof first.resourceId === 'string';
}

Try / catch

try {
  await sendNotificationSummary({ mastra, storage, records, now });
} catch (err) {
  if (err instanceof Error && err.message === 'Notification summary is missing agentId') {
    logger.error('Summary batch contained a record without agentId; falling back to per-record delivery', { err });
    await Promise.all(records.map(r => sendNotificationRecord({ mastra, storage, record: r, now })));
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: A low-priority batch flush calls sendNotificationSummary with records[0] missing or having an empty agentId — e.g. an empty/undefined records array (first is undefined), or a persisted record created without agentId reaching the summary path.

Common situations: Batching logic grouping records where the anchor record was written outside the official API; migrations or older versions dropping agentId; custom storage adapters losing fields; a bug in batch grouping that includes undefined entries.

Related errors


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