elsa-workflows/elsa-core · error · ArgumentException
A conversation user ID is required. (Parameter…
Error message
A conversation user ID is required. (Parameter 'conversation')
What it means
The store's Validate method requires a non-whitespace UserId on every AIConversation being saved. UserId is used for ownership checks (ValidateUserOwnership) and must be present to attribute the conversation; otherwise ArgumentException with paramName 'conversation' is thrown.
Solutions
- Populate conversation.UserId with the authenticated user's identifier before SaveAsync.
- If truly system-initiated, use an explicit system user identifier rather than null/empty (note ValidateUserOwnership only guards overwrites of records that already have a UserId).
- Add a pre-save check in your service layer that rejects conversations without a user.
Example fix
// before
await store.SaveAsync(new AIConversation { Id = id });
// after
await store.SaveAsync(new AIConversation { Id = id, UserId = currentUser.Id ?? "system" }); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(conversation.UserId)) throw new ArgumentException("A conversation user ID is required before SaveAsync."); Type guard
static bool HasUser(AIConversation c) => !string.IsNullOrWhiteSpace(c.UserId);
Try / catch
try { await store.SaveAsync(conversation); }
catch (ArgumentException ex) when (ex.ParamName == "conversation" && ex.Message.Contains("user ID")) { /* resolve current user or use a system identity */ } Prevention
- Resolve the user identity from auth context before creating conversations.
- Use an explicit system user for background/service-initiated conversations.
- Validate at the service boundary, not only at the store.
- Keep UserId assignment next to Id assignment in one factory method.
When it happens
Trigger: Calling SaveAsync with an AIConversation whose UserId is null, empty, or whitespace (Id validation passed but user ID validation failed).
Common situations: Service-to-service calls without a user context; authentication not resolving the current user's identifier; a mapper that copies Id but not UserId; creating conversations from background jobs with no ambient user.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- A conversation ID is required. (Parameter 'conversation')
- A proposal ID is required.
- A proposal conversation ID is required.
- A conversation ID is required. (Parameter 'conversation')
- A conversation user ID is required. (Parameter…
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/444844246521d040.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.AI.Persistence.EFCore/Stores/EFCoreAIConversationStore.cs:234
private static bool BelongsToTenant(string? storedTenantId, string? requestedTenantId) =>
string.Equals(NormalizeTenantId(storedTenantId), NormalizeTenantId(requestedTenantId), StringComparison.Ordinal);
private static string NormalizeTenantId(string? tenantId) => tenantId ?? "";
private static void ValidateUserOwnership(AIConversationRecord record, AIConversation conversation)
{
if (!string.IsNullOrWhiteSpace(record.UserId) && !string.Equals(record.UserId, conversation.UserId, StringComparison.Ordinal))
throw new InvalidOperationException("Cannot overwrite an AI conversation that belongs to another user.");
}
private static void Validate(AIConversation conversation)
{
if (string.IsNullOrWhiteSpace(conversation.Id))
throw new ArgumentException("A conversation ID is required.", nameof(conversation));
if (string.IsNullOrWhiteSpace(conversation.UserId))
throw new ArgumentException("A conversation user ID is required.", nameof(conversation));
}
}
View on GitHub (pinned to fe9217bdfa)