From 8a949659c3e5705fe6b6e16b611a7600dbf091de Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 22 Aug 2026 04:12:02 +0530 Subject: [PATCH] refactor(credits): fold review findings for stealth free-tier fix - credits_tracker: trim inline comment block (duplicated docstring) and correct its safety claim - a paid model under stealth/ would fail closed (suppressed banner), not open; state the trade-off honestly. - run_agent: update stale call-site comment to mention stealth/ prefix. - auxiliary_client: widen sibling free-SKU detector _is_free_model to recognize stealth/ prefix (same bug class as #91843: free_only=true wrongly skipped the OpenRouter fallback and the paid-lane warning fired spuriously for stealth models). - tests: bind the new sibling behavior (stealth/ox-alpha free, my-stealth/model not). --- agent/auxiliary_client.py | 7 +++++-- agent/credits_tracker.py | 10 +++------- run_agent.py | 3 ++- tests/agent/test_auxiliary_client.py | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 7322a14b9a..31e99c0e5b 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -2830,8 +2830,11 @@ _paid_lane_warned: set = set() def _is_free_model(model: Optional[str]) -> bool: - """True when ``model`` is an OpenRouter free SKU (``:free`` suffix).""" - return bool(model) and str(model).strip().endswith(":free") + """True when ``model`` is a free SKU (``:free`` suffix or ``stealth/`` prefix).""" + if not model: + return False + normalized = str(model).strip() + return normalized.endswith(":free") or normalized.startswith("stealth/") def _aux_openrouter_settings() -> Tuple[bool, str]: diff --git a/agent/credits_tracker.py b/agent/credits_tracker.py index 5988773044..39c74ea58b 100644 --- a/agent/credits_tracker.py +++ b/agent/credits_tracker.py @@ -244,13 +244,9 @@ def is_free_tier_model(model: str, base_url: str = "") -> bool: return False if model.endswith(":free"): return True - # Stealth-preview SKUs (e.g. stealth/ox-alpha) are free-tier but carry no - # ``:free`` suffix. Spend is forced to zero server-side, so a ``paid_access: - # false`` header on these models is a false positive for the depleted banner. - # The ``stealth/`` prefix is the Nous naming convention for these SKUs and - # is checked here as a zero-network signal, same design as the ``:free`` - # suffix above. Fail-open to False (the banner still shows) if the prefix - # ever changes — recoverable noise, never a masked depletion on a paid model. + # Stealth-preview SKUs are free-tier but carry no ``:free`` suffix (see + # docstring point 2). Naming-convention trust: if a PAID model ever shipped + # under ``stealth/`` this would wrongly suppress the banner on it. if model.startswith("stealth/"): return True if not base_url: diff --git a/run_agent.py b/run_agent.py index 6237738141..6704ad7cbd 100644 --- a/run_agent.py +++ b/run_agent.py @@ -4251,7 +4251,8 @@ class AIAgent: latch = self._credits_latch = new_credits_latch() # Free-model gate: a depleted account on a free model can still # inference, so the depleted error banner is suppressed. Local-data - # only (":free" suffix + pricing-cache peek) — never a network call. + # only (":free" suffix, "stealth/" prefix + pricing-cache peek) — + # never a network call. model_is_free = is_free_tier_model( getattr(self, "model", "") or "", getattr(self, "base_url", "") or "", diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.py index ad4966acaa..238c9e5038 100644 --- a/tests/agent/test_auxiliary_client.py +++ b/tests/agent/test_auxiliary_client.py @@ -1071,7 +1071,10 @@ class TestOpenRouterPaidLaneGuard: def test_is_free_model(self): from agent.auxiliary_client import _is_free_model assert _is_free_model("nvidia/nemotron-3-ultra-550b-a55b:free") + # Stealth-preview SKUs are free-tier without a :free suffix (issue #91843). + assert _is_free_model("stealth/ox-alpha") assert not _is_free_model("google/gemini-3.6-flash") + assert not _is_free_model("my-stealth/model") assert not _is_free_model("") assert not _is_free_model(None)