#8190·elsa-core

DeleteWorkflowLabels ignores version-deleted notifications; store version-delete APIs unused

Author: sfmskywalkerCreated Sep 20, 2026Updated Sep 20, 2026
Labelsbugcoreprio lowelsa 3triaged

Problem

DeleteWorkflowLabels only cleans associations when an entire definition is deleted. Deleting one or many versions leaves WorkflowDefinitionLabel rows for those WorkflowDefinitionVersionIds orphaned.

The association store already exposes version-scoped delete APIs (and conformance covers them), but nothing in the Labels module subscribes to the version-deleted notifications the management layer already publishes.

Evidence (main / elsa-core)

Handler only wires definition-level notifications

src/modules/Elsa.Labels/Handlers/DeleteWorkflowLabels.cs

  • Handles WorkflowDefinitionDeletedDeleteByWorkflowDefinitionIdAsync
  • Handles WorkflowDefinitionsDeletedDeleteByWorkflowDefinitionIdsAsync
  • Does not handle WorkflowDefinitionVersionDeleted / WorkflowDefinitionVersionsDeleted

Management already publishes version deletes

src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionManager.cs

  • DeleteVersionAsyncWorkflowDefinitionVersionDeleted
  • BulkDeleteByIdsAsyncWorkflowDefinitionVersionsDeleted

Dead / unused store surface (unless callers exist outside Labels)

IWorkflowDefinitionLabelStore:

  • DeleteByWorkflowDefinitionVersionIdAsync
  • DeleteByWorkflowDefinitionVersionIdsAsync

Implemented by Memory + EF (InMemoryWorkflowDefinitionLabelStore, EFCoreWorkflowDefinitionLabelStore) and exercised in LabelStoreConformanceTests, but not invoked from DeleteWorkflowLabels.

Why it matters

Labels are assigned per version (WorkflowDefinitionLabels.Update sets WorkflowDefinitionVersionId = workflowDefinition.Id). Version delete without cascade leaves stale association rows until the whole definition is removed — wrong for FindByLabelIds / filter providers and for subtractive store hygiene.

Proposed direction

  • Extend DeleteWorkflowLabels to handle WorkflowDefinitionVersionDeleted / WorkflowDefinitionVersionsDeleted using the existing version-delete store methods (mirror definition-level handlers).
  • Alternatively, if product intent is “labels always follow definition id only”, delete the unused version-delete APIs and stop storing per-version rows — but current Update endpoint + store contract say otherwise.

Out of scope / already tracked

  • Labels List TotalCount Memory vs EF → #8170
  • Labels Get/Post/Update missing Name → #8189
  • Shell FastEndpoints Labels → #8188

Light milestone note for Crew Lead: Soft Backlog / correctness; small handler wiring; not auto-Ready.

Source: elsa-workflows/elsa-core