The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(model-metadata): trim dated docstring, pin output-cap vs context-limit invariant
teknium1b309a713a8d0
diff --git a/agent/model_metadata.py b/agent/model_metadata.pyindex aa75082608c..3808833a50c 100644--- a/agent/model_metadata.py+++ b/agent/model_metadata.py@@ -1122,14 +1122,8 @@ def get_next_probe_tier(current_length: int) -> Optional[int]:def parse_context_limit_from_error(error_msg: str) -> Optional[int]:"""Context limit quoted in a provider error ("maximum context length is 32768 tokens"), if any.- 2026-09-08 bugfix: a message that talks only about an OUTPUT limit/cap and never mentions- "context" (e.g. Switchyard's "max_tokens cannot exceed the configured model output limit of- 16384") was matched by the generic "limit ... of N" pattern below and wrongly cached as the- CONTEXT window (switchyard/fallback's real context is >117K; 16384 is its output cap). Bail- out here so ``parse_available_output_tokens_from_error``/``is_output_cap_error`` — which run- first in the overflow-recovery path — get the chance to classify it as an output-cap error- instead. Genuine context-length messages (OpenAI/OpenRouter style) always say "context", so- this does not affect them."""+ A message about only an OUTPUT cap ("... model output limit of 16384") never says "context";+ bail out so the generic "limit ... of N" pattern can't cache the output cap as the window."""error_lower = error_msg.lower()if ("output limit" in error_lower or "output tokens" in error_lower or "output token" in error_lower) and "context" not in error_lower:return Nonediff --git a/tests/agent/test_model_metadata.py b/tests/agent/test_model_metadata.pyindex 485b892f030..38a4e13f0be 100644--- a/tests/agent/test_model_metadata.py+++ b/tests/agent/test_model_metadata.py@@ -1495,6 +1495,24 @@ class TestParseContextLimitFromError:)assert get_context_length_from_provider_error(msg, 131072) == 32768+ def test_output_cap_message_is_not_a_context_limit(self):+ """An output-cap error must never be cached as the context window (salvage #106769):+ the generic "limit ... of N" pattern matched Switchyard's message and clamped a+ >117K-context model to 16K on every later request."""+ from agent.model_metadata import (+ is_output_cap_error,+ parse_available_output_tokens_from_error,+ )++ msg = "max_tokens cannot exceed the configured model output limit of 16384"+ assert parse_context_limit_from_error(msg) is None+ assert parse_available_output_tokens_from_error(msg) == 16384+ assert is_output_cap_error(msg)+ # Genuine context messages still parse.+ assert parse_context_limit_from_error(+ "This model's maximum context length is 32768 tokens"+ ) == 32768+