elsa-workflows / elsa-workflows/elsa-core

IStartupTask Not Run When No Tenants Are Available

Open
#7,304 2 comments 0 reactions 0 assignees View on GitHub
codex codex-automation triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

### Problem Description

When multitenancy is enabled with a tenants provider that returns **zero tenants** (e.g., `ConfigurationTenantsProvider` with empty `Multitenancy:Tenants`), the following occurs:

- `ActivateTenants` hosted service runs `ActivateTenantsAsync`
- `DefaultTenantService.RefreshAsync()` / `GetTenantsDictionaryAsync()` receives an empty tenant list
- The `foreach (var tenant in tenants)` loop never executes
- `RegisterTenantAsync()` is never called
- `TenantActivatedAsync` is never invoked
- **No startup tasks run**, including `PopulateRegistriesStartupTask`, `RunMigrationsStartupTask`, `UpdateRouteTableStartupTask`, etc.

### Expected Behavior

- When multitenancy is enabled but no tenants are configured, the system should **at least activate `Tenant.Default`** (`Tenant.DefaultTenantId = ""`) so that:
1. Core startup tasks execute (registry population, migrations, route updates)
2. The application can operate in a "single default tenant" mode until tenants are added

### Affected Code Paths

```
ActivateTenants.StartAsync
→ ITenantService.ActivateTenantsAsync
→ DefaultTenantService.RefreshAsync / GetTenantsDictionaryAsync
→ foreach (var tenant in tenants) // Never executes if empty
→ RegisterTenantAsync
→ tenantEvents.TenantActivatedAsync
→ TenantTaskManager.TenantActivatedAsync
→ RunStartupTasksAsync // Never reached
→ IStartupTask.ExecuteAsync (PopulateRegistriesStartupTask, etc.)
```

Contributor guide

Open the contributing guide

Research direction

Start at ActivateTenants.StartAsync and trace ITenantService.ActivateTenantsAsync through DefaultTenantService.RefreshAsync and GetTenantsDictionaryAsync. Verify the empty-tenant path reaches tenant activation and startup-task execution, and confirm that the default tenant and listed startup tasks operate correctly when no tenants are configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.