Skip to content

Fix MongoDB tenant-agnostic workflow definition persistence and lookup#159

Draft
sfmskywalker with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-tenant-agnostic-workflow-issue
Draft

Fix MongoDB tenant-agnostic workflow definition persistence and lookup#159
sfmskywalker with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-tenant-agnostic-workflow-issue

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

MongoDB multitenancy handling for workflow definitions was inconsistent: agnostic (TenantId == "*") definitions could be overwritten to null on write and excluded from tenant-scoped reads. This made CLR-defined workflows unreachable under concrete tenant contexts.

  • Write-path tenancy behavior (MongoDbStore)

    • Preserve Tenant.AgnosticTenantId instead of restamping it.
    • Only apply ambient tenant stamping when TenantId is null.
    • Keep explicitly scoped tenant IDs unchanged.
  • Read-path tenant filter (MongoDbStore)

    • Tenant-scoped queries now include agnostic documents in addition to tenant-matching ones.
  • Regression coverage (Elsa.MongoDb.UnitTests)

    • Added targeted tests for:
      • preserving "*" on save,
      • stamping ambient tenant for unscoped entities,
      • including agnostic records in tenant-scoped filtering logic.
  • Test assembly access

    • Added InternalsVisibleTo("Elsa.MongoDb.UnitTests") to expose internal filter logic for focused unit coverage.
internal static IQueryable<TDocument> ApplyTenantFilter(IQueryable<TDocument> queryable, string? tenantId) =>
    queryable.Where(x =>
        (x as Entity)!.TenantId == tenantId ||
        (x as Entity)!.TenantId == Tenant.AgnosticTenantId);

private static void ApplyTenantId(Entity tenantDocument, string? tenantId)
{
    if (tenantDocument.TenantId == Tenant.AgnosticTenantId) return;
    if (tenantDocument.TenantId != null) return;
    tenantDocument.TenantId = tenantId.EmptyToNull();
}

Copilot AI changed the title [WIP] Fix tenant-agnostic workflow definitions with MongoDb persistence Fix MongoDB tenant-agnostic workflow definition persistence and lookup Jun 17, 2026
Copilot AI requested a review from sfmskywalker June 17, 2026 18:21
@arledesma

Copy link
Copy Markdown

If you merge this one then don't forget to close out #155

CoPilot also removed the reference to the source issue #158 from the description (it's available in history)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants