The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(usage-window): carry the refusal marker through the gateway turn projection
Teknium8da40c82dd5e
diff --git a/gateway/run_turn_runner.py b/gateway/run_turn_runner.pyindex cae1953ccc6..c5a6d6de541 100644--- a/gateway/run_turn_runner.py+++ b/gateway/run_turn_runner.py@@ -72,8 +72,9 @@ _LEDGER_PASSTHROUGH_KEYS = ("reasoning_tokens", "total_tokens", "provider", "turn_exit_reason", "service_tier",)# Beside ``failure_reason`` and ``error``: what ``agent.error_surface.build_error_surface_from_result`` reads,-# so the authority's ``message.complete`` carries the same error card the TUI path builds.-_FAILURE_DESCRIPTOR_KEYS = ("free_tier", "failure_retryable", "failure_resets_at")+# so the authority's ``message.complete`` carries the same error card the TUI path builds;+# ``usage_window_message`` also marks a window-plan refusal for the chat rewording.+_FAILURE_DESCRIPTOR_KEYS = ("free_tier", "failure_retryable", "failure_resets_at", "usage_window_message")def _finite_viewer_turn() -> bool:diff --git a/tests/gateway/test_authority_turn_error_surface.py b/tests/gateway/test_authority_turn_error_surface.pyindex 3916d52077c..e0ca4abf6c3 100644--- a/tests/gateway/test_authority_turn_error_surface.py+++ b/tests/gateway/test_authority_turn_error_surface.py@@ -75,6 +75,17 @@ def test_rate_limited_turn_completes_with_rate_limit_and_reset_time():{k: v for k, v in complete.items() if k not in ('content', 'admission_id', 'outcome')})+def test_usage_window_refusal_completes_with_the_window_card():+ limit = {'limit': 'weekly', 'suggestions': [{'model': 'nous/free-model', 'label': 'Free model'}]}+ refusal = {'failure_reason': 'billing', 'failure_retryable': False, 'error': 'HTTP 402',+ 'usage_window_message': "You've hit your weekly limit.", 'failure_resets_at': 1900000000.0,+ 'usage_limit': limit}+ surface = _complete(*_authority_turn(Platform.LOCAL, refusal))['error_surface']+ assert (surface['code'], surface['message'], surface['resets_at']) == (+ 'usage_window', "You've hit your weekly limit.", 1900000000.0)+ assert surface['usage_limit'] == limit++def test_a_managed_worker_turn_carries_the_free_tier_failure_to_the_owner():from agent.managed_worker import accept_result, encode_frame, read_frame, result_frame