medusajs/medusa · warning

Failed to clear events for eventGroupId

Error message

Failed to clear events for eventGroupId - ${flowEventGroupId}

What it means

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.

Solutions

  1. 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
  2. If using a custom event bus module, implement clearGroupedEvents(eventGroupId)
  3. Retry the workflow run; on success a new eventGroupId is used and the stale group can be purged manually
  4. Inspect the event_group table (or equivalent) for orphaned groups and clean them up if they accumulate
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await eventBusService.clearGroupedEvents(eventGroupId)
} catch {
  logger.warn(`Failed to clear events for eventGroupId - ${eventGroupId}`)
  // optionally enqueue retry/cleanup of the event group
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/db786df479161b2f. Report an issue: GitHub.

Appendix: source

Thrown at packages/core/workflows-sdk/src/helper/workflow-export.ts:643

    const eventBusService = (
      flow.container as MedusaContainer
    ).resolve<IEventBusModuleService>(Modules.EVENT_BUS, {
      allowUnregistered: true,
    })

    if (!eventBusService || !flowEventGroupId) {
      await onFinish?.(args)
      return
    }

    const failedStatus = [TransactionState.FAILED, TransactionState.REVERTED]

    if (failedStatus.includes(transaction.getState())) {
      return await eventBusService
        .clearGroupedEvents(flowEventGroupId)
        .catch(() => {
          logger.warn(
            `Failed to clear events for eventGroupId - ${flowEventGroupId}`
          )
        })
    }

    await eventBusService
      .releaseGroupedEvents(flowEventGroupId)
      .then(async () => {
        await onFinish?.(args)
      })
      .catch((e) => {
        logger.error(
          `Failed to release grouped events for eventGroupId: ${flowEventGroupId}`,
          e
        )

        return flow.cancel(transaction)
      })

View on GitHub (pinned to 5e06e544a2)