From d8f4f08ee3ca3550683f5f17307071263bd369b0 Mon Sep 17 00:00:00 2001 From: Francesco Parisio <92143809+fparisio@users.noreply.github.com> Date: Fri, 14 Aug 2026 16:46:16 +0200 Subject: [PATCH] fix(llm-client): detect native sglang context-overflow messages Signed-off-by: Francesco Parisio <92143809+fparisio@users.noreply.github.com> --- crates/libsy-llm-client/src/backend.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/libsy-llm-client/src/backend.rs b/crates/libsy-llm-client/src/backend.rs index 99323b8f0..3c2d1735a 100644 --- a/crates/libsy-llm-client/src/backend.rs +++ b/crates/libsy-llm-client/src/backend.rs @@ -25,6 +25,8 @@ const OPENAI_OVERFLOW_PHRASES: &[&str] = &[ "context length is only", "please reduce the length of the input", "exceeds the maximum allowed input length", + "exceeds the maximum allowed length", + "is longer than the model's context length", ]; // Anthropic has no structured `error.code`, so detection is phrase-based only. @@ -339,6 +341,15 @@ mod tests { assert!(backend.is_context_overflow( r#"{"error":{"message":"Input length 877338 exceeds the maximum allowed input length of 639968 tokens","code":"400"}}"# )); + // Native SGLang: top-level envelope (no `error` key), caught by the raw-body phrase match. + // KV-pool rejection (managers/utils.py) and declared-context rejection + // (tokenizer_manager.py); both stable across v0.5.15-v0.5.17. + assert!(backend.is_context_overflow( + r#"{"object":"error","message":"Input length (700001 tokens) exceeds the maximum allowed length (536826 tokens). Use a shorter input or enable --allow-auto-truncate.","type":"BadRequestError","param":null,"code":400}"# + )); + assert!(backend.is_context_overflow( + r#"{"object":"error","message":"The input (12345 tokens) is longer than the model's context length (8192 tokens).","type":"BadRequestError","param":null,"code":400}"# + )); } #[test]