{"record":{"id":"c1401bf4367c2ceb","repo":"hcengineering/platform","slug":"cannot-create-message-group-not-found-cardid","errorCode":null,"errorMessage":"Cannot create message, group not found: cardId = ${event.cardId}, messageId = ${event.messageId}, created = ${event.date.toISOString()}","messagePattern":"Cannot create message, group not found: cardId = (.+?), messageId = (.+?), created = (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/communication/packages/server/src/middleware/storage.ts","lineNumber":237,"sourceCode":"    event.collaborators = added\n    return {}\n  }\n\n  private async removeCollaborators (event: Enriched<RemoveCollaboratorsEvent>): Promise<Result> {\n    if (event.collaborators.length === 0) return { skipPropagate: true }\n    await this.db.removeCollaborators({ cardId: event.cardId, account: event.collaborators })\n\n    return {}\n  }\n\n  private async createMessage (event: Enriched<CreateMessageEvent>): Promise<Result> {\n    if (event.messageId == null) {\n      throw new Error('Message id is required')\n    }\n\n    const group = await this.blob.getMessageGroupByDate(event.cardId, event.date)\n    if (group == null) {\n      throw new Error(\n        `Cannot create message, group not found: cardId = ${event.cardId}, messageId = ${event.messageId}, created = ${event.date.toISOString()}`\n      )\n    }\n    const result: CreateMessageResult = {\n      messageId: event.messageId,\n      created: event.date,\n      blobId: group.blobId\n    }\n    const created = await this.db.createMessageMeta(\n      event.cardId,\n      event.messageId,\n      event.socialId,\n      event.date,\n      group.blobId\n    )\n\n    if (!created) {\n      return {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/communication/packages/server/src/middleware/storage.ts#L219-L255","documentation":"After validating messageId, createMessage looks up the message group for the card and date via `this.blob.getMessageGroupByDate(cardId, date)`. If no group exists, it throws this Error with cardId, messageId and created date embedded. It means storage cannot attach the message because the expected day-group blob for that card was never created.","triggerScenarios":"A CreateMessageEvent arrives for a cardId whose message group for the event date does not exist in blob storage — typically the card/group was never initialized, was deleted, or the event date doesn't match any existing group.","commonSituations":"Events arriving out of order (create-card event lost or delayed); replaying old events after the group was archived/deleted; clock/date mismatch where the event's `date` lands on a day with no group; importing data from another environment.","solutions":["Ensure the card/message-group is created (initialize the group for the card/date) before dispatching message-create events.","Check event ordering/delivery: verify the card-creation event was processed (idempotent retries, queue ordering).","Verify the event `date` is correct (client clock skew can point at a date with no group).","If the group was intentionally deleted, decide whether to recreate it or drop the stale event instead of failing.","From the error's cardId/messageId/created fields, query blob storage to confirm the missing group and backfill it."],"exampleFix":"// before\nawait storage.processEvent({ type: 'message.create', cardId: 'c1', messageId: 'm1', date: new Date(), ... })\n// Error: Cannot create message, group not found: cardId = c1 ...\n// after: create the group first\nawait blob.createMessageGroup('c1', date)\nawait storage.processEvent({ type: 'message.create', cardId: 'c1', messageId: 'm1', date, ... })","handlingStrategy":"validation","validationCode":"async function assertGroupExists(blob, cardId, date) {\n  const group = await blob.getMessageGroupByDate(cardId, date)\n  if (group == null) throw new Error(`Message group for card ${cardId} on ${date.toISOString()} does not exist; create it first`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await storage.processEvent(createMsgEvent)\n} catch (e) {\n  if (e.message.startsWith('Cannot create message, group not found')) {\n    const { cardId, created } = parseGroupError(e.message)\n    await blob.createMessageGroup(cardId, new Date(created))\n    return retry(processEvent, createMsgEvent)\n  }\n  throw e\n}","preventionTips":["Guarantee card/message-group creation events are processed before message-create events (ordering/idempotency).","Handle clock skew: normalize event dates server-side.","When deleting groups, also handle or drop dependent queued events.","Use the error's cardId/messageId/created fields to backfill missing groups."],"tags":["storage","messages","blob","events","consistency"],"backgroundTag":"referenced-resource-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}