The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(agent): fold the five memory-ceiling cases into one parametrized invariant
kshitijk4poore669800e2aa1
diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.pyindex 05418126581..d5d0ca6d50d 100644--- a/tests/agent/test_error_classifier.py+++ b/tests/agent/test_error_classifier.py@@ -683,63 +683,33 @@ class TestClassifyApiError:# ── Local-inference memory ceiling (oMLX/MLX prefill guard, #52261) ──- def test_omlx_prefill_guard_is_overloaded_not_overflow(self):- """oMLX 0.5.6 prefill guard → overloaded, never compression. The body- names a memory peak in BYTES, but its remediation tail says "Reduce- context length" — which used to route it into the compress loop, where- shrinking history cannot lower a prefill peak."""- e = MockAPIError(- "Prefill memory guard rejected request: Prefill would require ~13.87 GB peak, "- "dynamic ceiling is 13.50 GB. Reduce context length or lower memory_guard_tier.",- status_code=400,- )- result = classify_api_error(e, provider="omlx")+ @pytest.mark.parametrize("message, status_code, body", [+ # 0.5.6 prefill guard: a memory peak in BYTES whose remediation tail says "Reduce context+ # length" — the phrase that used to route it into the compress loop.+ ("Prefill memory guard rejected request: Prefill would require ~13.87 GB peak, "+ "dynamic ceiling is 13.50 GB. Reduce context length or lower memory_guard_tier.", 400, None),+ # 0.5.7 rewording ("predicted peak would require"); cap names survive the verb change.+ ("process memory limit exceeded: predicted peak would require ~78.57 GB, prefill "+ "safety cap is 77.76 GB (90% of metal_cap ceiling 86.40 GB). Reduce context size.", 400, None),+ # Mid-stream the guard exits as a generic 500 (streaming generator drops the code).+ ("predicted peak would exceed prefill safety cap 77.8GB. Reduce context length.", 500, None),+ # Status-less: "memory limit exceeded" contains "limit exceeded" and would otherwise read+ # as billing in the usage-limit disambiguation — the memory rule runs in the message HEAD.+ ("process memory limit exceeded: predicted peak would require ~78.57 GB. "+ "Reduce context size.", None, None),+ # Proxy flattened the wording; only the structured code survives (400 must read it, since+ # _by_status runs before _by_error_code).+ ("Request failed.", 400, {"error": {"message": "Request failed.", "code": "prefill_memory_exceeded"}}),+ ])+ def test_memory_ceiling_rejection_is_overloaded_not_overflow(self, message, status_code, body):+ kwargs = {"status_code": status_code} if status_code is not None else {}+ if body is not None:+ kwargs["body"] = body+ result = classify_api_error(MockAPIError(message, **kwargs), provider="omlx")assert result.reason == FailoverReason.overloadedassert result.should_compress is False- assert result.retryable is True-- def test_omlx_057_reworded_peak_accounting(self):- """0.5.7 rewrote the sentence to "predicted peak would require"; the- cap names (prefill safety cap, metal_cap) survive the verb change."""- e = MockAPIError(- "process memory limit exceeded: predicted peak would require ~78.57 GB, prefill "- "safety cap is 77.76 GB (90% of metal_cap ceiling 86.40 GB). Reduce context size.",- status_code=400,- )- assert classify_api_error(e, provider="omlx").reason == FailoverReason.overloaded-- def test_omlx_memory_ceiling_mid_stream_500(self):- """Mid-stream the guard exits as a generic 500 (the streaming generator- catches bare Exception and drops the structured code)."""- e = MockAPIError(- "predicted peak would exceed prefill safety cap 77.8GB. Reduce context length.",- status_code=500,- )- assert classify_api_error(e, provider="omlx").reason == FailoverReason.overloaded-- def test_omlx_memory_ceiling_without_status_is_not_billing(self):- """"memory limit exceeded" contains "limit exceeded", so a flattened,- status-less rejection would hit the usage-limit disambiguation and read- as billing — rotating a healthy credential. The memory rules run in the- message HEAD, before that disambiguation."""- e = MockAPIError(- "process memory limit exceeded: predicted peak would require ~78.57 GB. "- "Reduce context size."- )- result = classify_api_error(e, provider="omlx")- assert result.reason == FailoverReason.overloadedassert result.should_rotate_credential is False- def test_omlx_memory_ceiling_by_error_code_alone(self):- """A proxy that flattens the body and drops the wording still leaves- the structured code; _by_status runs before _by_error_code, so the 400- handler has to read it or the request falls through to format_error."""- e = MockAPIError(- "Request failed.", status_code=400,- body={"error": {"message": "Request failed.", "code": "prefill_memory_exceeded"}},- )- assert classify_api_error(e, provider="omlx").reason == FailoverReason.overloaded-def test_genuine_context_overflow_still_compresses(self):"""Guard against over-reach: a real window overflow must keep itscompression recovery."""