The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(error-surface): show a limit reset time only on limit failures
Siddharth Balyan98d80689990d
diff --git a/agent/turn_recovery.py b/agent/turn_recovery.pyindex 635fb552976..0aa8c5fa9c6 100644--- a/agent/turn_recovery.py+++ b/agent/turn_recovery.py@@ -828,9 +828,15 @@ def limit_reset_epoch(agent: Any, api_error: Exception) -> Optional[float]:return None-def _stamp_limit_reset(result: dict[str, Any], agent: Any, api_error: Exception) -> None:+# Responses for other failures can still carry rate-limit headers; a reset time only explains a limit.+_LIMIT_REASONS = frozenset({FailoverReason.rate_limit, FailoverReason.upstream_rate_limit, FailoverReason.billing})+++def _stamp_limit_reset(result: dict[str, Any], agent: Any, api_error: Exception, classified: Any) -> None:"""``failure_resets_at`` for structured clients (Desktop card: "Limit resets at HH:mm") and thesame sentence appended to the chat text every plain surface (CLI/TUI/gateway) renders (#98852)."""+ if classified.reason not in _LIMIT_REASONS:+ returnresets_at = limit_reset_epoch(agent, api_error)if resets_at is None:return@@ -1105,7 +1111,7 @@ def nonretryable_client_error_result(})if _keep_partial:result["partial"] = True- _stamp_limit_reset(result, agent, api_error)+ _stamp_limit_reset(result, agent, api_error, classified)if _welcome_hint and (_kind := _welcome_surface_kind(classified)):# The card form: the desktop renders the sign-in as a button, so no "To sign in" tail._stamp_free_tier(result, _kind,@@ -1252,7 +1258,7 @@ def max_retries_exhausted_result(if _keep_partial:result["final_response"] = _final_responseresult["partial"] = True- _stamp_limit_reset(result, agent, api_error)+ _stamp_limit_reset(result, agent, api_error, classified)if _free_tier_kind:_stamp_free_tier(result, _free_tier_kind, (_welcome_tier_guidance(classified, model=model, in_chat=True, door=False)diff --git a/tests/agent/test_error_classifier_data_policy.py b/tests/agent/test_error_classifier_data_policy.pyindex 3ad8442c2d8..d4ff5bda966 100644--- a/tests/agent/test_error_classifier_data_policy.py+++ b/tests/agent/test_error_classifier_data_policy.py@@ -27,3 +27,18 @@ def test_data_policy_copy_gives_free_tier_users_a_way_out():model="some/model", summary="No endpoint qualifies.")free_tier = copy[copy.index("free tier"):]assert "'some/model'" in copy and "upgrade" in free_tier and "/compress" in free_tier and "/new" in free_tier+++def test_limit_reset_line_only_explains_a_limit():+ import time+ from types import SimpleNamespace++ from agent.turn_recovery import _stamp_limit_reset++ agent = SimpleNamespace(_extract_api_error_context=lambda _e: {"reset_at": time.time() + 600})+ refused = {"final_response": "refused"}+ _stamp_limit_reset(refused, agent, Exception(), SimpleNamespace(reason=FailoverReason.data_policy_denied))+ limited = {"final_response": "slow down"}+ _stamp_limit_reset(limited, agent, Exception(), SimpleNamespace(reason=FailoverReason.rate_limit))+ assert refused == {"final_response": "refused"}+ assert "failure_resets_at" in limited and "Limit resets at" in limited["final_response"]