{"record":{"id":"12b6de4d03925ee1","repo":"LykosAI/StabilityMatrix","slug":"conversation-conversationid-not-found","errorCode":null,"errorMessage":"Conversation {conversationId} not found","messagePattern":"Conversation (.+?) not found","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Services/ImageGeneration/ImageGenerationChatService.cs","lineNumber":425,"sourceCode":"    }\n\n    public async Task<(\n        ImageGenerationMessage UserMessage,\n        ImageGenerationMessage? AssistantMessage\n    )> SendMessageAsync(\n        Guid conversationId,\n        string providerId,\n        string? textPrompt,\n        List<string>? imagePaths,\n        Dictionary<string, object>? providerOptions,\n        IProgress<ImageGenerationProgress>? progress,\n        CancellationToken cancellationToken = default\n    )\n    {\n        var conversation = await GetConversationAsync(conversationId).ConfigureAwait(false);\n        if (conversation == null)\n        {\n            throw new InvalidOperationException($\"Conversation {conversationId} not found\");\n        }\n\n        var provider = GetProvider(providerId);\n        if (provider == null)\n        {\n            throw new InvalidOperationException($\"Provider {providerId} not found\");\n        }\n\n        // Update conversation's provider if it changed\n        var providerChanged = conversation.ProviderId != providerId;\n        if (providerChanged)\n        {\n            logger.LogInformation(\n                \"Switching conversation {ConversationId} provider from {OldProvider} to {NewProvider}\",\n                conversationId,\n                conversation.ProviderId,\n                providerId\n            );","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Services/ImageGeneration/ImageGenerationChatService.cs#L407-L443","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the conversation exists before sending: load it via GetConversationAsync and null-check, or create one with CreateConversationAsync.","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.","Check which settings directory / database the service is using — the id may exist in a different data directory.","If the conversation was deleted, recreate it and re-send the prompt."],"exampleFix":"// before\nawait chatService.SendMessageAsync(conversationId, providerId, prompt);\n// after\nvar conversation = await chatService.GetConversationAsync(conversationId);\nif (conversation is null)\n{\n    conversationId = await chatService.CreateConversationAsync(providerId);\n}\nawait chatService.SendMessageAsync(conversationId, providerId, prompt);","handlingStrategy":"validation","validationCode":"var conversation = await chatService.GetConversationAsync(conversationId);\nif (conversation is null)\n{\n    throw new InvalidOperationException(\n        $\"Conversation {conversationId} does not exist; create it before sending messages\");\n}","typeGuard":"// C#: GetConversationAsync already returns a nullable record\nbool ConversationExists(ImageGenerationConversation? c) => c is not null;","tryCatchPattern":"try\n{\n    await chatService.SendMessageAsync(conversationId, providerId, prompt);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not found\"))\n{\n    logger.LogWarning(ex, \"Conversation missing, creating a new one\");\n    conversationId = await chatService.CreateConversationAsync(providerId);\n    await chatService.SendMessageAsync(conversationId, providerId, prompt);\n}","preventionTips":["Always keep conversation ids sourced from the live service/database, not stale UI state","Null-check GetConversationAsync before sending","Refresh conversation references after deletes, migrations, or settings-directory changes","Never hardcode or fabricate conversation Guids"],"tags":["state","database","invalid-argument","conversation"],"backgroundTag":"record-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}