Billionmail/BillionMail · error

Chat not found

Error message

Chat not found

What it means

Chat loads the existing chat via GetChat(chatId) and returns this error when the lookup fails, meaning no chat session exists with that ID. Chat only updates an existing chat's supplier/model; it does not create one.

Source

Thrown at core/internal/service/askai/chat.go:262

	content = strings.TrimSpace(content)
	if content == "" {
		return errors.New("Content cannot be empty")
	}

	supplierInfo, err := GetSupplierConfig(supplierName)
	if err != nil {
		return errors.New("Supplier not found")
	}

	modelInfo := GetModelInfo(supplierName, modelId)
	if modelInfo == nil {
		return errors.New("Model not found")
	}

	// Check if the chat is already active
	chatInfo, err := GetChat(chatId)
	if err != nil {
		return errors.New("Chat not found")
	}
	// set the chat information
	chatInfo.SupplierName = supplierName
	chatInfo.ModelId = modelId
	err = SaveChat(chatId, chatInfo)
	if err != nil {
		return errors.New("Failed to save chat")
	}

	ChatStatus[chatId] = true // Set chat status to active
	defer func() {
		delete(ChatStatus, chatId) // Ensure chat status is removed after processing
	}()

	aiObj := NewOpenAI(ctx, supplierInfo.ApiKey, supplierInfo.BaseUrl, modelId, chatId, supplierName, modelInfo.MaxTokens)
	if aiObj == nil {
		return errors.New("failed to initialize AI client")
	}

View on GitHub (pinned to fc36c76c05)

Solutions

  1. Create the chat first (the chat-creation API) and use the returned ID
  2. Verify chatId exists via GetChat before calling Chat
  3. Clear stale chatIds on the client and force re-creation when GetChat fails

Example fix

// before
err := askai.Chat(ctx, staleChatId, supplier, model, content, true)
// after
if _, err := askai.GetChat(chatId); err != nil {
    chatId, err = askai.CreateChat(...) // recreate missing chat
}
err = askai.Chat(ctx, chatId, supplier, model, content, true)
Defensive patterns

Strategy: validation

Validate before calling

if _, err := askai.GetChat(chatId); err != nil {
    return fmt.Errorf("chat %s does not exist; create it first", chatId)
}

Try / catch

if err := askai.Chat(ctx, chatId, supplier, model, content, true); err != nil {
    if err.Error() == "Chat not found" {
        // invalidate client-side chatId and re-create the chat
    }
    return err
}

Prevention

When it happens

Trigger: Calling Chat with a chatId that was never created (CreateChat not called), a chat that was removed via RemoveChat, an expired/purged chat ID, or a typo/incorrect ID from the client.

Common situations: Frontend keeps a stale chatId in localStorage after the chat was deleted server-side; restarting with an in-memory chat store that was cleared; calling Chat before the chat-creation endpoint completes.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/5e7b10b6d48f9b9b. Report an issue: GitHub.