Fix: honor chat_default as fallback chat model for subscribed (self-hosted) users - #1399
Open
SnowingFox wants to merge 1 commit into
Open
Fix: honor chat_default as fallback chat model for subscribed (self-hosted) users#1399SnowingFox wants to merge 1 commit into
SnowingFox wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 returnedchat_advancedfor subscribed users and never fell back tochat_default. This madechat_defaultdead config on self-hosted installs and forced self-hosters to usechat_advancedfor 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 ofaget_default_chat_model()checksthink_paid_fast, thenthink_paid_deep, thenchat_advanced— but, unlike the non-subscribed branch and the synchronousget_default_chat_model(), it never falls back tochat_default. Becauseais_user_subscribed()returnsTruewheneverstate.billing_enabledisFalse, self-hosted users always take the subscribed branch, so the server admin'schat_defaultmodel is never selected.Fix
Add the missing
chat_defaultfallback to the subscribed branch ofaget_default_chat_model(), mirroring the non-subscribed branch and the existing synchronousget_default_chat_model(). Whenchat_advanced(and the think-paid slots) are not configured, the server admin'schat_defaultmodel is now used. Whenchat_advancedis 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 onlychat_defaultconfigured,aget_default_chat_modelreturnschat_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 thatchat_advancedstill wins when it is configured.Fixes #1282