Skip to content

Fix: honor chat_default as fallback chat model for subscribed (self-hosted) users - #1399

Open
SnowingFox wants to merge 1 commit into
khoj-ai:masterfrom
SnowingFox:fix/chat-default-fallback
Open

Fix: honor chat_default as fallback chat model for subscribed (self-hosted) users#1399
SnowingFox wants to merge 1 commit into
khoj-ai:masterfrom
SnowingFox:fix/chat-default-fallback

Conversation

@SnowingFox

Copy link
Copy Markdown

Problem

On self-hosted Khoj (billing disabled), every user is treated as subscribed by ais_user_subscribed(). In the async chat-model-selection path, ConversationAdapters.aget_default_chat_model() only ever returned chat_advanced for subscribed users and never fell back to chat_default. This made chat_default dead config on self-hosted installs and forced self-hosters to use chat_advanced for every LLM call (intent classification, code generation, title generation, chat responses), regardless of the sidebar model picker.

Root cause

In src/khoj/database/adapters/__init__.py, the subscribed branch of aget_default_chat_model() checks think_paid_fast, then think_paid_deep, then chat_advanced — but, unlike the non-subscribed branch and the synchronous get_default_chat_model(), it never falls back to chat_default. Because ais_user_subscribed() returns True whenever state.billing_enabled is False, self-hosted users always take the subscribed branch, so the server admin's chat_default model is never selected.

Fix

Add the missing chat_default fallback to the subscribed branch of aget_default_chat_model(), mirroring the non-subscribed branch and the existing synchronous get_default_chat_model(). When chat_advanced (and the think-paid slots) are not configured, the server admin's chat_default model is now used. When chat_advanced is set, it still takes priority, preserving existing behavior.

Test

New tests/test_chat_model_selection.py:

  • test_aget_default_chat_model_honors_chat_default_when_chat_advanced_unset — with a self-hosted (billing disabled) user and only chat_default configured, aget_default_chat_model returns chat_default. Fails before the fix (returns the first-created chat model instead) and passes after.
  • test_aget_default_chat_model_prefers_chat_advanced_when_set — locks in that chat_advanced still wins when it is configured.

Fixes #1282

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self-hosted: chat_advanced overrides all model selection, sidebar picker and chat_default are ignored

1 participant