diff --git a/hermes_cli/auth.py b/hermes_cli/auth.py index 6d5bfb8ae1..e24bbe6355 100644 --- a/hermes_cli/auth.py +++ b/hermes_cli/auth.py @@ -9392,6 +9392,9 @@ def _login_nous(args, pconfig: ProviderConfig) -> None: # purchases are reflected immediately. free_tier = check_nous_free_tier(force_fresh=True) _portal_for_recs = auth_state.get("portal_base_url", "") + # Narrow before the tier split, so a rescued id still has to + # pass the free/paid predicate. + _policy_allowed = nous_policy_allowed_ids() if free_tier: try: from hermes_cli.nous_account import ( @@ -9417,6 +9420,9 @@ def _login_nous(args, pconfig: ProviderConfig) -> None: model_ids, pricing = union_with_portal_free_recommendations( model_ids, pricing, _portal_for_recs, ) + model_ids = restrict_to_nous_policy( + model_ids, _policy_allowed, rescue_empty=True, + ) model_ids, unavailable_models = partition_nous_models_by_tier( model_ids, pricing, free_tier=True, ) @@ -9428,15 +9434,9 @@ def _login_nous(args, pconfig: ProviderConfig) -> None: model_ids, pricing = union_with_portal_paid_recommendations( model_ids, pricing, _portal_for_recs, ) - # Neither the curated list nor the Portal's recommendations - # know what the org may reach. - _policy_allowed = nous_policy_allowed_ids() - model_ids = restrict_to_nous_policy( - model_ids, _policy_allowed, rescue_empty=True, - ) - unavailable_models = restrict_to_nous_policy( - unavailable_models, _policy_allowed, - ) + model_ids = restrict_to_nous_policy( + model_ids, _policy_allowed, rescue_empty=True, + ) _portal = auth_state.get("portal_base_url", "") if model_ids: from hermes_cli.nous_account import nous_policy_notice diff --git a/hermes_cli/model_setup_flows.py b/hermes_cli/model_setup_flows.py index 90c9dd38d2..c24274591d 100644 --- a/hermes_cli/model_setup_flows.py +++ b/hermes_cli/model_setup_flows.py @@ -531,6 +531,14 @@ def _model_flow_nous(config, current_model="", args=None): # of CLI release cadence. unavailable_models: list[str] = [] unavailable_message = "" + + # Neither the curated list nor the Portal's recommendations know what the + # org may reach. Narrow before the tier split, so an id the policy rescues + # still has to pass the free/paid predicate instead of going around it. + from hermes_cli.models import nous_policy_allowed_ids, restrict_to_nous_policy + + _policy_allowed = nous_policy_allowed_ids() + if free_tier: try: from hermes_cli.nous_account import ( @@ -551,6 +559,9 @@ def _model_flow_nous(config, current_model="", args=None): model_ids, pricing = union_with_portal_free_recommendations( model_ids, pricing, _nous_portal_url, ) + model_ids = restrict_to_nous_policy( + model_ids, _policy_allowed, rescue_empty=True, + ) model_ids, unavailable_models = partition_nous_models_by_tier( model_ids, pricing, free_tier=True ) @@ -558,16 +569,9 @@ def _model_flow_nous(config, current_model="", args=None): model_ids, pricing = union_with_portal_paid_recommendations( model_ids, pricing, _nous_portal_url, ) - - # Neither the curated list nor the Portal's recommendations know what the - # org may reach. - from hermes_cli.models import nous_policy_allowed_ids, restrict_to_nous_policy - - _policy_allowed = nous_policy_allowed_ids() - model_ids = restrict_to_nous_policy( - model_ids, _policy_allowed, rescue_empty=True, - ) - unavailable_models = restrict_to_nous_policy(unavailable_models, _policy_allowed) + model_ids = restrict_to_nous_policy( + model_ids, _policy_allowed, rescue_empty=True, + ) if not model_ids and not unavailable_models: print("No models available for Nous Portal after filtering.") diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.py index ec3aae53ec..4c66f9e9b3 100644 --- a/hermes_cli/web_server.py +++ b/hermes_cli/web_server.py @@ -7505,10 +7505,19 @@ def get_recommended_default_model(provider: str = ""): except Exception: portal_url = "" + # This endpoint picks the model a user lands on without choosing it, + # so an unreachable one here is worse than in a picker. Narrow before + # the tier split, so a rescued id still has to pass the free/paid + # predicate. + _policy_allowed = nous_policy_allowed_ids() + if free_tier: model_ids, pricing = union_with_portal_free_recommendations( model_ids, pricing, portal_url ) + model_ids = restrict_to_nous_policy( + model_ids, _policy_allowed, rescue_empty=True, + ) model_ids, _unavailable = partition_nous_models_by_tier( model_ids, pricing, free_tier=True ) @@ -7516,12 +7525,9 @@ def get_recommended_default_model(provider: str = ""): model_ids, pricing = union_with_portal_paid_recommendations( model_ids, pricing, portal_url ) - - # This endpoint picks the model a user lands on without choosing - # it, so an unreachable one here is worse than in a picker. - model_ids = restrict_to_nous_policy( - model_ids, nous_policy_allowed_ids(), rescue_empty=True, - ) + model_ids = restrict_to_nous_policy( + model_ids, _policy_allowed, rescue_empty=True, + ) model = pick_silent_default_model(model_ids, provider="nous") return {"provider": "nous", "model": model, "free_tier": bool(free_tier)} diff --git a/tests/hermes_cli/test_nous_policy_filter.py b/tests/hermes_cli/test_nous_policy_filter.py index 2de0597964..5dc6c60d28 100644 --- a/tests/hermes_cli/test_nous_policy_filter.py +++ b/tests/hermes_cli/test_nous_policy_filter.py @@ -213,3 +213,28 @@ class TestRescueIsOptIn: empty — not a filter result to rescue.""" reachable = {f"cn/model-{i}" for i in range(42)} assert restrict_to_nous_policy([], reachable) == [] + + +class TestPolicyRunsBeforeTierSplit: + """A rescued id must still pass the free/paid predicate. + + Rescuing after the tier split put paid models back into a free-tier user's + selectable list, and the same id into both lists at once. + """ + + def test_a_rescued_paid_model_stays_unavailable_for_a_free_tier_user(self): + from hermes_cli.models import partition_nous_models_by_tier + + pricing = { + "vendor/free": {"prompt": "0", "completion": "0"}, + "vendor/paid": {"prompt": "0.000002", "completion": "0.00001"}, + } + narrowed = restrict_to_nous_policy( + list(pricing), {"vendor/paid"}, rescue_empty=True + ) + selectable, unavailable = partition_nous_models_by_tier( + narrowed, pricing, free_tier=True + ) + + assert selectable == [] + assert unavailable == ["vendor/paid"]