From 847cc47cdbfb2fdfb68731bf59c1285efff3c1e8 Mon Sep 17 00:00:00 2001 From: xxxigm Date: Wed, 12 Aug 2026 23:24:52 +0700 Subject: [PATCH] test(error_classifier): cover Qwen applyPromptTemplate vs llama.cpp grammar Add regressions for the Discord-shaped applyPromptTemplate 400 that embeds "No user query found", bare no-user-query on a large session, and the genuine llama.cpp unable-to-generate-parser grammar path that must stay recoverable. --- tests/agent/test_error_classifier.py | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.py index 37b498b251..d2e5a19421 100644 --- a/tests/agent/test_error_classifier.py +++ b/tests/agent/test_error_classifier.py @@ -483,9 +483,55 @@ class TestClassifyApiError: # ── Provider-specific: llama.cpp grammar-parse ── + def test_llama_cpp_unable_to_generate_parser_template(self): + e = MockAPIError( + "Unable to generate parser for this template. " + "Automatic parser generation failed: error parsing grammar", + status_code=400, + ) + result = classify_api_error(e, provider="custom", model="local-llama") + assert result.reason == FailoverReason.llama_cpp_grammar_pattern + assert result.retryable is True + assert result.should_compress is False + def test_qwen_apply_prompt_template_no_user_query_not_llama_cpp_grammar(self): + """Local engines wrap Qwen raise_exception as applyPromptTemplate 400. + Must NOT classify as llama_cpp_grammar_pattern (which strips tool + schema keywords and retries). Fail fast as format_error so the user + sees a request-shape failure instead of a misleading template/parser + loop — typical after context overflow + failed compression. + """ + e = MockAPIError( + "Engine protocol applyPromptTemplate request returned 400: " + '{"error":{"code":400,"message":"Unable to generate parser for ' + "this template. Automatic parser generation failed: " + "While executing CallExpression ... multi_step_tool %} " + "{{- raise_exception('No user query found in messages')", + status_code=400, + ) + result = classify_api_error( + e, + provider="custom", + model="qwen/qwen3.6-35b-a3b", + approx_tokens=226_000, + context_length=100_864, + ) + assert result.reason == FailoverReason.format_error + assert result.retryable is False + assert result.should_compress is False + assert result.should_fallback is True + def test_bare_no_user_query_found_is_format_error_even_on_large_session(self): + e = MockAPIError("No user query found in messages", status_code=400) + result = classify_api_error( + e, + approx_tokens=226_000, + context_length=100_864, + ) + assert result.reason == FailoverReason.format_error + assert result.retryable is False + assert result.should_compress is False # ── Provider-specific: Anthropic long-context tier ──