mastra-ai/mastra · error
All message IDs must be non-empty strings
Error message
All message IDs must be non-empty strings
What it means
After normalization, deleteMessages verifies that every resolved message ID is a non-empty string. IDs that are empty strings, undefined, or non-strings (from objects whose `id` held such a value) trigger this error before any deletion happens.
Source
Thrown at packages/memory/src/index.ts:2838
}
if (input.length === 0) {
return;
}
messageIds = input.map(item => {
if (typeof item === 'string') {
return item;
} else if (item && typeof item === 'object' && 'id' in item) {
return item.id;
} else {
throw new Error('Invalid input: array items must be strings or objects with an id property');
}
});
const invalidIds = messageIds.filter(id => !id || typeof id !== 'string');
if (invalidIds.length > 0) {
throw new Error('All message IDs must be non-empty strings');
}
const span = this.createMemorySpan('delete', observabilityContext, undefined, {
messageCount: messageIds.length,
});
try {
const memoryStore = await this.getMemoryStore();
await memoryStore.deleteMessages(messageIds);
if (this.vector) {
this.trackVectorCleanup(this.deleteMessageVectors(messageIds));
}
span?.end({ output: { success: true }, attributes: { messageCount: messageIds.length } });
} catch (error) {
span?.error({ error: error as Error, endSpan: true });
throw error;View on GitHub (pinned to 75dd419e61)
Solutions
- Filter the array to entries with truthy string IDs before calling: items.filter(m => typeof m?.id === 'string' && m.id)
- Ensure messages are persisted (and have server-assigned IDs) before attempting deletion
- Fix the upstream data source producing empty IDs
Example fix
// before await memory.deleteMessages(messages); // some messages lack ids // after const deletable = messages.filter(m => typeof m.id === 'string' && m.id.length > 0); await memory.deleteMessages(deletable);
Defensive patterns
Strategy: validation
Validate before calling
const deletable = messages.filter((m): m is { id: string } => typeof m.id === 'string' && m.id.length > 0);
if (deletable.length === 0) return; // nothing valid to delete Type guard
const hasNonEmptyId = (item: string | { id?: string }): item is { id: string } | string =>
typeof item === 'string' ? item.length > 0 : typeof item.id === 'string' && item.id.length > 0; Try / catch
try {
await memory.deleteMessages(messages);
} catch (err) {
if (err instanceof Error && err.message.includes('non-empty strings')) {
console.error('Message with empty/missing id:', messages.filter(m => !m.id));
}
throw err;
} Prevention
- Only delete messages after they are persisted and have server-assigned IDs
- Add a shared precondition filter for non-empty string IDs
- Log/skip invalid records rather than letting them abort the whole deletion batch
When it happens
Trigger: Passing objects whose `id` is an empty string or undefined (e.g. records not yet persisted); arrays containing '' or null after a prior shape check; template-built IDs that interpolated to empty values.
Common situations: Deleting messages fetched from an API where optional `id` fields are missing; optimistic-UI code deleting not-yet-created messages; CSV/import pipelines producing empty IDs.
Related errors
- Invalid input: must be an array of message IDs or message ob
- Invalid input: array items must be strings or objects with a
- Received input message with wrong threadId. Input ${message.
- Received input message with wrong resourceId. Input ${messag
- Found unhandled message ${JSON.stringify(message)}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/0ec64ca0af47a485.
Report an issue: GitHub.