From ff8920299c10e5e58fc84326bf2c973b42ab4de1 Mon Sep 17 00:00:00 2001 From: herbalizer404 <8180647+herbalizer404@users.noreply.github.com> Date: Thu, 25 Jun 2026 12:50:25 -0700 Subject: [PATCH] fix(auxiliary): treat 403 subscription and session-usage-limit errors as payment errors for fallback Ollama Cloud (and similar) return 403 with bodies like "this model requires a subscription, upgrade for access" or "you have reached your session usage limit, upgrade for higher limits". These are capacity/billing conditions semantically identical to credit exhaustion, but _is_payment_error() did not recognize them (403 missing from the status set; keywords missing), so the configured fallback_chain was never tried and compression failed outright. Adds 403 to the status set and the subscription/session-usage keywords. Salvaged from #49076 by @herbalizer404. --- agent/auxiliary_client.py | 4 +++- tests/agent/test_auxiliary_client.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 0afb0add20b..18a6f9bfa73 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -2470,7 +2470,7 @@ def _is_payment_error(exc: Exception) -> bool: # but sometimes wrap them in 429 or other codes. # Daily quota exhaustion from Bedrock, Vertex AI, and similar providers # uses different language but is semantically identical to credit exhaustion. - if status in {402, 404, 429, None}: + if status in {402, 403, 404, 429, None}: if any(kw in err_lower for kw in ( "credits", "insufficient funds", "can only afford", "billing", @@ -2479,6 +2479,8 @@ def _is_payment_error(exc: Exception) -> bool: "balance_depleted", "no usable credits", "model_not_supported_on_free_tier", "not available on the free tier", + "requires a subscription", "upgrade for access", + "upgrade for higher limits", "reached your session usage limit", # Daily / monthly / weekly quota exhaustion keywords "quota exceeded", "quota_exceeded", "too many tokens per day", "daily limit", diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.py index dac9956b494..060a817998e 100644 --- a/tests/agent/test_auxiliary_client.py +++ b/tests/agent/test_auxiliary_client.py @@ -1406,6 +1406,21 @@ class TestIsPaymentError: exc.status_code = 404 assert _is_payment_error(exc) is True + def test_403_subscription_required_is_payment(self): + exc = Exception( + "this model requires a subscription, upgrade for access: " + "https://ollama.com/upgrade" + ) + setattr(exc, "status_code", 403) + assert _is_payment_error(exc) is True + + def test_429_session_usage_limit_is_payment(self): + exc = Exception( + "you have reached your session usage limit, upgrade for higher limits" + ) + setattr(exc, "status_code", 429) + assert _is_payment_error(exc) is True + def test_404_generic_not_found_is_not_payment(self): exc = Exception("Not Found") exc.status_code = 404