{"record":{"id":"e6ea52a9c489df3f","repo":"mastra-ai/mastra","slug":"invalid-input-must-be-an-array-of-message-ids-or","errorCode":null,"errorMessage":"Invalid input: must be an array of message IDs or message objects","messagePattern":"Invalid input: must be an array of message IDs or message objects","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/index.ts","lineNumber":2819,"sourceCode":"    return memoryStore.updateMessages({ messages });\n  }\n\n  /**\n   * Deletes one or more messages\n   * @param input - Must be an array containing either:\n   *   - Message ID strings\n   *   - Message objects with 'id' properties\n   * @returns Promise that resolves when all messages are deleted\n   */\n  public async deleteMessages(\n    input: MessageDeleteInput,\n    observabilityContext?: Partial<ObservabilityContext>,\n  ): Promise<void> {\n    // Normalize input to messageIds before creating span to avoid leaking full message objects into traces\n    let messageIds: string[];\n\n    if (!Array.isArray(input)) {\n      throw new Error('Invalid input: must be an array of message IDs or message objects');\n    }\n\n    if (input.length === 0) {\n      return;\n    }\n\n    messageIds = input.map(item => {\n      if (typeof item === 'string') {\n        return item;\n      } else if (item && typeof item === 'object' && 'id' in item) {\n        return item.id;\n      } else {\n        throw new Error('Invalid input: array items must be strings or objects with an id property');\n      }\n    });\n\n    const invalidIds = messageIds.filter(id => !id || typeof id !== 'string');\n    if (invalidIds.length > 0) {","sourceCodeStart":2801,"sourceCodeEnd":2837,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/index.ts#L2801-L2837","documentation":"Memory message deletion accepts an array of message IDs (strings) or message objects with `id`. Before creating the delete span, the library validates that the input is an array; anything else (undefined, a single ID string, an object) throws this error immediately.","triggerScenarios":"Passing a single string message ID instead of an array; passing undefined/null (e.g. from a variable that failed to populate); passing a single message object instead of [message].","commonSituations":"Calling deleteMessages(id) with one ID from an older code sample; an upstream query returning undefined that is forwarded directly; TypeScript types bypassed via `any` or JS callers.","solutions":["Wrap the input in an array: deleteMessages([messageId]) or deleteMessages([message])","Check that the source of the argument actually resolves to an array before calling","Validate the payload shape at the boundary (e.g. with zod) to fail fast with a clearer error"],"exampleFix":"// before\nawait memory.deleteMessages(messageId);\n\n// after\nawait memory.deleteMessages([messageId]);","handlingStrategy":"validation","validationCode":"function assertMessageIdArray(input: unknown): asserts input is (string | { id: string })[] {\n  if (!Array.isArray(input)) throw new TypeError('deleteMessages expects an array of ids or message objects');\n}","typeGuard":"const isMessageIdArray = (v: unknown): v is (string | { id: string })[] =>\n  Array.isArray(v) && v.every(i => typeof i === 'string' || (typeof i === 'object' && i !== null && 'id' in i));","tryCatchPattern":"try {\n  await memory.deleteMessages(input as any);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Invalid input')) {\n    console.error('deleteMessages input must be an array:', input);\n  }\n  throw err;\n}","preventionTips":["Always pass arrays, even for a single ID: [id]","Type the variable as (string | { id: string })[] so TypeScript catches single-value misuse","Avoid `any`-typed intermediaries that let undefined flow into deleteMessages"],"tags":["memory","input-validation","api-misuse"],"backgroundTag":"invalid-input-type","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}