elsa-workflows/elsa-core · error · ArgumentException

A conversation ID is required. (Parameter 'conversation')

Error message

A conversation ID is required. (Parameter 'conversation')

What it means

InMemoryAIConversationStore.Validate requires every conversation passed to SaveAsync to have a non-whitespace Id. An empty or null Id makes the record unaddressable, so an ArgumentException naming the 'conversation' parameter is thrown before anything is stored.

Solutions

  1. Populate conversation.Id before calling SaveAsync (e.g. Guid.NewGuid().ToString()).
  2. Add a null/empty check on the source of the conversation Id in your code.
  3. Use the store's conversation-creation API that assigns an Id instead of constructing manually.

Example fix

// before
await store.SaveAsync(new AIConversation { UserId = user });
// after
await store.SaveAsync(new AIConversation { Id = Guid.NewGuid().ToString(), UserId = user });
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(conversation.Id)) throw new ArgumentException("Conversation Id required");

Type guard

bool HasId(AIConversation c) => !string.IsNullOrWhiteSpace(c.Id);

Try / catch

try { await store.SaveAsync(conversation); } catch (ArgumentException ex) when (ex.ParamName == "conversation") { logger.LogError(ex, "Conversation missing Id/UserIds"); }

Prevention

When it happens

Trigger: Calling SaveAsync with an AIConversation whose Id is null, empty, or whitespace.

Common situations: Constructing conversations from deserialized payloads missing the Id; relying on a default (empty) Id field; mapping code that drops the conversation ID during transformation.

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/2b8daaeef17b95b7. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.AI.Host/Services/InMemoryAIConversationStore.cs:71

        var expiresAt = conversation.RetentionExpiresAt;
        return expiresAt.HasValue && expiresAt <= DateTimeOffset.UtcNow;
    }

    private static void ValidateOwnership(AIConversation existing, AIConversation conversation)
    {
        if (!string.Equals(NormalizeTenantId(existing.TenantId), NormalizeTenantId(conversation.TenantId), StringComparison.Ordinal))
            throw new InvalidOperationException("Cannot overwrite an AI conversation that belongs to another tenant.");

        if (!string.IsNullOrWhiteSpace(existing.UserId) && !string.Equals(existing.UserId, conversation.UserId, StringComparison.Ordinal))
            throw new InvalidOperationException("Cannot overwrite an AI conversation that belongs to another user.");
    }

    private static string NormalizeTenantId(string? tenantId) => tenantId ?? "";

    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)