Skip to content

The agent that grows with you

fix(agent): recover from strict OpenAI-compatible "regex lookaround is not supported" 400s

liuhao10243306e105b3be
diff --git a/agent/error_classifier.py b/agent/error_classifier.py
index 7e190cf9005..7550fd65d3d 100644
--- a/agent/error_classifier.py
+++ b/agent/error_classifier.py
@@ -768,9 +768,12 @@ def _provider_special_cases(c: _Ctx) -> Optional[Verdict]:
# retry loop strips them. Exclude the Qwen/vLLM "No user query found" error
# local engines wrap as "Unable to generate parser for this template" —
# that is a poisoned transcript (→ format_error), not a grammar problem.
+ # Strict OpenAI-compatible schema validators reject regex lookaround in ``pattern``
+ # with a different sentence ("Invalid JSON schema: regex lookaround is not supported",
+ # #42631); same recovery — strip ``pattern``/``format`` and retry once.
grammar_hit = "error parsing grammar" in msg or "json-schema-to-grammar" in msg or (
"unable to generate parser" in msg and "template" in msg
- )
+ ) or ("invalid json schema" in msg and "regex lookaround" in msg and "not supported" in msg)
if status == 400 and grammar_hit and _NO_USER_QUERY_SIGNAL not in msg:
return _v(_R.llama_cpp_grammar_pattern)
# xAI Grok entitlement as an SSE ``type=error`` frame: no status, matches no
diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.py
index 059d633b574..d9cc6e531b0 100644
--- a/tests/agent/test_error_classifier.py
+++ b/tests/agent/test_error_classifier.py
@@ -968,6 +968,22 @@ class TestClassifyApiError:
assert result.retryable is True
assert result.should_compress is False
+ def test_openai_regex_lookaround_rejection_is_recoverable(self):
+ """Strict OpenAI-compatible endpoints reject ``pattern`` lookaround with a 400 (#42631);
+ it must reuse the strip-pattern/format retry instead of failing the turn."""
+ e = MockAPIError(
+ "Invalid JSON schema: regex lookaround is not supported. Found at $.properties.email.pattern.",
+ status_code=400,
+ )
+ result = classify_api_error(e, provider="custom", model="gpt-5.5")
+ assert result.reason == FailoverReason.llama_cpp_grammar_pattern
+ assert result.retryable is True
+ # A generic schema 400 without the lookaround sentence stays a plain client error.
+ other = classify_api_error(
+ MockAPIError("Invalid JSON schema: regex syntax error in pattern", status_code=400), provider="custom"
+ )
+ assert other.reason != FailoverReason.llama_cpp_grammar_pattern
+
def test_qwen_apply_prompt_template_no_user_query_not_llama_cpp_grammar(self):
"""Local engines wrap Qwen raise_exception as applyPromptTemplate 400.