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

  1. Populate conversation.UserId with the authenticated user's identifier before SaveAsync.
  2. 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).
  3. 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

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


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)