From 16c4c4d71e127fea6a0971bd2808f80e8ed13577 Mon Sep 17 00:00:00 2001 From: Dooner Date: Fri, 4 Dec 2026 15:06:16 -0600 Subject: [PATCH] helios/server: return context error on exhausted default output limit When a request omits max_tokens and max_completion_tokens (or passes null) and the prompt length reaches or exceeds the server context limit, output_limit previously computed remaining = 0, clamped the default limit to 0, and fell through to the bad-request branch ("output limit must be between 1 and 2147483647 tokens"). That hid the context-length failure and prevented helios/src/server/http.rs from reporting context_length_exceeded and the server's context hint. - helios/src/server/request.rs: - Before: omitted output limits with prompt >= context fell through to the max_new_tokens == 0 bad-request branch. - After: when requested is None and remaining == 0, output_limit returns Error::admission(AdmissionError::Context, ...) stating whether the prompt fills the server context (leaving no room for output tokens) or exceeds it. Explicit max_tokens: 0 and max_completion_tokens: 0 keep the existing bad-request error ("output limit must be between 1 and 2147483647 tokens"). Expands omitted_output_limit_uses_remaining_context_and_explicit_limits_win to assert error variants and messages for each case. - Compatibility: HTTP status stays 400; error code for omitted-limit context exhaustion becomes context_length_exceeded (with context_hint), matching explicit output-limit overflow and count_only checks. Result: - Clients omitting max_tokens (such as Open WebUI) receive an accurate context_length_exceeded error instead of an output-limit range error. Evidence: - Verified via cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server and pytest tests/preparation/test_core_boundary.py on clean git archive. - Limitations: pure CPU HTTP request validation; no GPU path is affected. Discord: Dooner Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b Signed-off-by: Dooner --- helios/src/server/request.rs | 50 +++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/helios/src/server/request.rs b/helios/src/server/request.rs index bde28ab42..3f2cf606a 100644 --- a/helios/src/server/request.rs +++ b/helios/src/server/request.rs @@ -608,7 +608,23 @@ fn output_limit( Some(value) => value .as_u64() .ok_or("output limit must be a nonnegative integer")?, - None => (configured as usize).min(remaining) as u64, + None => { + if remaining == 0 { + return Err(Error::admission( + AdmissionError::Context, + if prompt > context { + format!( + "prompt of {prompt} tokens exceeds this server's context of {context} tokens" + ) + } else { + format!( + "prompt of {prompt} tokens fills this server's context of {context} tokens, leaving no room for output tokens" + ) + }, + )); + } + (configured as usize).min(remaining) as u64 + } }; let max_new_tokens = u32::try_from(limit).map_err(|error| { Error::Admission(AdmissionError::Invalid(Failure::caused_by( @@ -1037,8 +1053,36 @@ mod tests { ] { assert!(limit(body, 262144, 144).is_err()); } - assert!(limit(serde_json::json!({}), 262144, 262144).is_err()); - assert!(limit(serde_json::json!({}), 262144, 262145).is_err()); + for (body, prompt) in [ + (serde_json::json!({"max_tokens":0}), 144), + (serde_json::json!({"max_completion_tokens":0}), 262144), + ] { + let error = limit(body, 262144, prompt).unwrap_err(); + assert!(!matches!(error, Error::Admission(AdmissionError::Context(_))), "{error:?}"); + assert!( + error.to_string().contains("output limit must be between 1 and 2147483647 tokens"), + "{error}" + ); + } + for body in [serde_json::json!({}), serde_json::json!({"max_tokens":null})] { + let filled = limit(body.clone(), 262144, 262144).unwrap_err(); + assert!(matches!(filled, Error::Admission(AdmissionError::Context(_))), "{filled:?}"); + assert!( + filled.to_string().contains("fills this server's context of 262144 tokens, leaving no room for output tokens"), + "{filled}" + ); + let exceeded = limit(body, 262144, 262145).unwrap_err(); + assert!(matches!(exceeded, Error::Admission(AdmissionError::Context(_))), "{exceeded:?}"); + assert!( + exceeded.to_string().contains("prompt of 262145 tokens exceeds this server's context of 262144 tokens"), + "{exceeded}" + ); + } + let explicit_overflow = limit(serde_json::json!({"max_tokens":1}), 262144, 262144).unwrap_err(); + assert!( + matches!(explicit_overflow, Error::Admission(AdmissionError::Context(_))), + "{explicit_overflow:?}" + ); } #[test] fn absent_sampling_ranges_fix_distribution_parameters_and_preserve_seed() {