LykosAI/StabilityMatrix · error · InvalidOperationException

Conversation not found

Error message

Conversation {conversationId} not found

What it means

SendMessageAsync loads the chat conversation by its Guid from the database before dispatching the message. If GetConversationAsync returns null the conversation does not exist (or is not visible to the current settings/database), and the service throws InvalidOperationException with the conversation id rather than proceeding with a null conversation. It is a precondition failure: callers must supply the id of an existing conversation.

Solutions

  1. Verify the conversation exists before sending: load it via GetConversationAsync and null-check, or create one with CreateConversationAsync.
  2. Use the conversation id obtained directly from the service (e.g. the result of CreateConversationAsync or the current conversation list) instead of a cached/stale Guid.
  3. Check which settings directory / database the service is using — the id may exist in a different data directory.
  4. If the conversation was deleted, recreate it and re-send the prompt.

Example fix

// before
await chatService.SendMessageAsync(conversationId, providerId, prompt);
// after
var conversation = await chatService.GetConversationAsync(conversationId);
if (conversation is null)
{
    conversationId = await chatService.CreateConversationAsync(providerId);
}
await chatService.SendMessageAsync(conversationId, providerId, prompt);
Defensive patterns

Strategy: validation

Validate before calling

var conversation = await chatService.GetConversationAsync(conversationId);
if (conversation is null)
{
    throw new InvalidOperationException(
        $"Conversation {conversationId} does not exist; create it before sending messages");
}

Type guard

// C#: GetConversationAsync already returns a nullable record
bool ConversationExists(ImageGenerationConversation? c) => c is not null;

Try / catch

try
{
    await chatService.SendMessageAsync(conversationId, providerId, prompt);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("not found"))
{
    logger.LogWarning(ex, "Conversation missing, creating a new one");
    conversationId = await chatService.CreateConversationAsync(providerId);
    await chatService.SendMessageAsync(conversationId, providerId, prompt);
}

Prevention

When it happens

Trigger: Calling SendMessageAsync (either overload) with a conversationId Guid that has no matching row in the Conversations table — e.g. a stale id from a deleted conversation, a Guid from a different database/settings directory, or an id fabricated/misspelled by the caller.

Common situations: App data was migrated or the portable data directory changed so old conversation ids no longer resolve; the UI kept a stale conversation id after the conversation was deleted; passing a conversation from one workspace/install into another; tests constructing arbitrary Guids.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/12b6de4d03925ee1. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Core/Services/ImageGeneration/ImageGenerationChatService.cs:425

    }

    public async Task<(
        ImageGenerationMessage UserMessage,
        ImageGenerationMessage? AssistantMessage
    )> SendMessageAsync(
        Guid conversationId,
        string providerId,
        string? textPrompt,
        List<string>? imagePaths,
        Dictionary<string, object>? providerOptions,
        IProgress<ImageGenerationProgress>? progress,
        CancellationToken cancellationToken = default
    )
    {
        var conversation = await GetConversationAsync(conversationId).ConfigureAwait(false);
        if (conversation == null)
        {
            throw new InvalidOperationException($"Conversation {conversationId} not found");
        }

        var provider = GetProvider(providerId);
        if (provider == null)
        {
            throw new InvalidOperationException($"Provider {providerId} not found");
        }

        // Update conversation's provider if it changed
        var providerChanged = conversation.ProviderId != providerId;
        if (providerChanged)
        {
            logger.LogInformation(
                "Switching conversation {ConversationId} provider from {OldProvider} to {NewProvider}",
                conversationId,
                conversation.ProviderId,
                providerId
            );

View on GitHub (pinned to af93d6ef57)