{"record":{"id":"db786df479161b2f","repo":"medusajs/medusa","slug":"failed-to-clear-events-for-eventgroupid-flowev","errorCode":null,"errorMessage":"Failed to clear events for eventGroupId - ${flowEventGroupId}","messagePattern":"Failed to clear events for eventGroupId - (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/workflows-sdk/src/helper/workflow-export.ts","lineNumber":643,"sourceCode":"\n    const eventBusService = (\n      flow.container as MedusaContainer\n    ).resolve<IEventBusModuleService>(Modules.EVENT_BUS, {\n      allowUnregistered: true,\n    })\n\n    if (!eventBusService || !flowEventGroupId) {\n      await onFinish?.(args)\n      return\n    }\n\n    const failedStatus = [TransactionState.FAILED, TransactionState.REVERTED]\n\n    if (failedStatus.includes(transaction.getState())) {\n      return await eventBusService\n        .clearGroupedEvents(flowEventGroupId)\n        .catch(() => {\n          logger.warn(\n            `Failed to clear events for eventGroupId - ${flowEventGroupId}`\n          )\n        })\n    }\n\n    await eventBusService\n      .releaseGroupedEvents(flowEventGroupId)\n      .then(async () => {\n        await onFinish?.(args)\n      })\n      .catch((e) => {\n        logger.error(\n          `Failed to release grouped events for eventGroupId: ${flowEventGroupId}`,\n          e\n        )\n\n        return flow.cancel(transaction)\n      })","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/workflows-sdk/src/helper/workflow-export.ts#L625-L661","documentation":"When a workflow run finishes in a FAILED or REVERTED state, the workflow engine tries to clear the event-bus events that were buffered under the run's eventGroupId so half-finished work doesn't emit events. If eventBusService.clearGroupedEvents rejects, the failure is swallowed and only this warning is logged.","triggerScenarios":"A workflow whose transaction state is FAILED or REVERTED AND the event bus (e.g. the EventBus module's internal storage) errors when deleting the grouped events — DB connectivity issues, missing table, or an event-bus service that doesn't support clearing.","commonSituations":"Workflows failing during a database outage so cleanup also fails; custom/local event bus modules that don't implement clearGroupedEvents; transient DB restarts while a long workflow is reverting.","solutions":["Check the event bus module and its database for errors around the failure time — the root cause is the workflow failure; the clear failure is secondary","If using a custom event bus module, implement clearGroupedEvents(eventGroupId)","Retry the workflow run; on success a new eventGroupId is used and the stale group can be purged manually","Inspect the event_group table (or equivalent) for orphaned groups and clean them up if they accumulate"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await eventBusService.clearGroupedEvents(eventGroupId)\n} catch {\n  logger.warn(`Failed to clear events for eventGroupId - ${eventGroupId}`)\n  // optionally enqueue retry/cleanup of the event group\n}","preventionTips":["Implement clearGroupedEvents on custom event bus modules","Keep the event bus DB healthy; investigate workflow failures that trigger cleanup","Periodically inspect for orphaned event groups after outages"],"tags":["workflows","event-bus","cleanup","transaction-failure"],"backgroundTag":"event-cleanup-failed","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}