Skip to content

The agent that grows with you

chore: merge origin/main (resolve tests/agent/test_output_cap_parsing.py)

teknium1811d3959b2de
diff --cc agent/model_metadata.py
index 129320417a3,34e6e8309a7..30b10eab7d1
--- a/agent/model_metadata.py
+++ b/agent/model_metadata.py
@@@ -1351,9 -1385,9 +1394,10 @@@ _PARSEABLE_OUTPUT_CAP_SIGNALS =
("max_tokens", "available_tokens"), ("max_tokens", "available tokens"),
("in the output", "maximum context length"),
("maximum context length", "requested", "output tokens"),
+ ("maximum context length", "in the completion"), ("maximum context length", "for the completion"),
("range of max_tokens should be",), ("exceeds model", "maximum output tokens"),
("output limit",), ("max_tokens", "maximum allowed number of output tokens"),
+ ("max_tokens is too large", "supports at most"), ("tokens from the input messages", "tokens for the completion"),
)
@@@ -1373,14 -1400,15 +1417,18 @@@ def is_output_cap_error(error_msg: str
output-cap 400 misclassified as context overflow death-loops the compressor (same max_tokens, same
rejection). Signal: talks about max_tokens as a cap/range/limit and NOT about an oversized input."""
error_lower = error_msg.lower()
+ # The OpenAI-style split names neither max_tokens nor "output tokens" and ends with "reduce the
+ # length", so it fails both gates below; the measured prompt decides instead (#90607).
+ if _completion_split_budget(error_lower) is not None:
+ return True
# An error that ALSO describes an oversized INPUT is a genuine overflow — compression can fix it.
+ # SGLang states both figures: input >= window is that same genuine overflow.
+ _m_sglang = _sglang_window_and_input(error_lower)
return (
- any(p in error_lower for p in ("max_tokens", "max_output_tokens", "max_completion_tokens"))
+ any(p in error_lower for p in ("max_tokens", "max_output_tokens", "max_completion_tokens", "tokens for the completion"))
and _any_phrase_group(error_lower, _OUTPUT_CAP_SIGNALS)
and not any(p in error_lower for p in _INPUT_OVERFLOW_SIGNALS)
+ and not (_m_sglang and _m_sglang[1] >= _m_sglang[0])
)
diff --cc tests/agent/test_output_cap_parsing.py
index 89e17e5a818,3d10c23b3e2..a276097754a
--- a/tests/agent/test_output_cap_parsing.py
+++ b/tests/agent/test_output_cap_parsing.py
@@@ -210,27 -210,24 +210,50 @@@ class TestParseVllmTokenBasedOutputCap
+class TestParseAdvertisedCeilingWordings:
+ """Azure and SGLang name the ceiling without any phrase the parser knew (#78405, #83521).
+ Unrecognized, the 400 carried the bare ``max_tokens`` substring (or nothing at all) into
+ the compression path and a fresh session died with "cannot be shrunk further"."""
+
+ @pytest.mark.parametrize("msg, available", [
+ # Azure OpenAI (verbatim from #78405): the advertised completion ceiling IS the budget.
+ ("Error: max_tokens is too large: 65536. This model supports at most 32768 completion tokens.", 32768),
+ # SGLang (verbatim from #83521): window - input; never mentions max_tokens.
+ ("Requested token count exceeds the model's maximum context length of 131072 tokens. You requested "
+ "a total of 132528 tokens: 66992 tokens from the input messages and 65536 tokens for the completion. "
+ "Please reduce the number of tokens in the input messages or the completion to fit within the limit.",
+ 64080),
+ ])
+ def test_ceiling_is_parsed_and_classified_as_output_cap(self, msg, available):
+ assert parse_available_output_tokens_from_error(msg) == available
+ assert is_output_cap_error(msg) is True
+
+ def test_sglang_input_alone_over_window_routes_to_compression(self):
+ # Same wording, but the input by itself exceeds the window: shrinking the output cannot help.
+ msg = ("Requested token count exceeds the model's maximum context length of 100000 tokens. You requested "
+ "a total of 150000 tokens: 120000 tokens from the input messages and 30000 tokens for the completion.")
+ assert parse_available_output_tokens_from_error(msg) is None
+ assert is_output_cap_error(msg) is False
++
++
+ class TestParseOpenAiCompletionSplit:
+ """OpenAI's original overflow wording, copied by vLLM / llama-cpp-python, splits the request
+ as "(A in the messages, B in the completion)" and never names max_tokens (#90607)."""
+
+ @pytest.mark.parametrize("msg, budget", [
+ ("This model's maximum context length is 102400 tokens. However, you requested 102401 tokens "
+ "(36865 in the messages, 65536 in the completion). Please reduce the length of the messages or completion.",
+ 102400 - 36865),
+ ("This model's maximum context length is 4097 tokens, however you requested 4771 tokens "
+ "(771 in your prompt; 4000 for the completion). Please reduce your prompt; or completion length.",
+ 4097 - 771),
+ ])
+ def test_split_is_output_cap_with_window_minus_measured_prompt(self, msg, budget):
+ assert parse_available_output_tokens_from_error(msg) == budget
+ assert is_output_cap_error(msg)
+
+ def test_split_with_prompt_filling_window_stays_on_compression(self):
+ msg = ("This model's maximum context length is 4097 tokens. However, you requested 6000 tokens "
+ "(5000 in the messages, 1000 in the completion). Please reduce the length of the messages or completion.")
+ assert parse_available_output_tokens_from_error(msg) is None
+ assert not is_output_cap_error(msg)