Repository navigation
helios/server: return context error on exhausted default output limit - #71
Draft
FujitsuPolycom wants to merge 1 commit into
Draft
FujitsuPolycom wants to merge 1 commit into
FujitsuPolycom wants to merge 1 commit into
Conversation
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 <dooner@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When an OpenAI-compatible client omits
max_tokensandmax_completion_tokens(or sets them tonull, as Open WebUI and many SDK defaults do) and submits a prompt whose length is at or above the server'smax_sequence_tokens,output_limitcomputesremaining = context.saturating_sub(prompt) == 0and clamps the default output budget to0. The subsequent bounds check then rejects the request with the generic bad-request error"output limit must be between 1 and 2147483647 tokens"(mapped byhelios/src/server/http.rspreparation_errorto an untyped HTTP 400 invalid-request response), hiding the actual context-length failure and omitting thecontext_length_exceededcode and the server's optional configured context-limit hint (state.context_hint) attached toAdmissionError::Contextresponses.What changed
Before this change,
output_limitinhelios/src/server/request.rsmerged an exhausted default remaining budget (remaining == 0) with an explicitly invalidmax_tokens: 0.helios/src/server/request.rs:output_limit, theNonebranch returned(configured as usize).min(remaining) as u64, producing0wheneverprompt >= contextand falling through to"output limit must be between 1 and 2147483647 tokens".max_completion_tokensnormax_tokensis provided (requestedisNone) andremaining == 0,output_limitreturnsError::admission(AdmissionError::Context, ...)with:"prompt of {prompt} tokens exceeds this server's context of {context} tokens"whenprompt > context, or"prompt of {prompt} tokens fills this server's context of {context} tokens, leaving no room for output tokens"whenprompt == context.max_tokens: 0ormax_completion_tokens: 0continues to fall through to the existing bad-request error ("output limit must be between 1 and 2147483647 tokens"), and explicit positive limits overflowing context continue to returnAdmissionError::Context.helios/src/server/request.rs): Expandsomitted_output_limit_uses_remaining_context_and_explicit_limits_winto assertError::Admission(AdmissionError::Context(_))and exact messages forprompt == contextandprompt > contextwith omitted andnulllimits, explicit positive overflow returningAdmissionError::Context, and explicitmax_tokens: 0/max_completion_tokens: 0keeping the non-context"output limit must be between 1 and 2147483647 tokens"error.400 Bad Request; the errorcodefor omitted-limit context exhaustion changes from generic invalid-request to"context_length_exceeded"(matching explicit-limit overflow and token-counting (count_only) checks) and now includes the configured context-limit hint when set.Claimed benefit and result
max_tokensreceive an accuratecontext_length_exceedederror reporting prompt and server context token counts instead of a misleading output-limit range error.Supporting evidence and limitations
Tested on clean
git archive 16c4c4d71e127fea6a0971bd2808f80e8ed13577atopNVIDIA/hyperflare-inferencemain(7bbc6707792aa1cb8633794ee189b7592091cc45):16c4c4d71e127fea6a0971bd2808f80e8ed13577):cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server(withFLARE_TEST_TEMPLATE_DIRprepared viatests/frontend/prepare_templates.py):1,917 passed; 0 failed; 49 ignored(lib, includingserver::request::tests::omitted_output_limit_uses_remaining_context_and_explicit_limits_win) and62 passed; 0 failed; 36 ignoredacross integration tests (85ignored tests require external model checkpoint snapshots or GPU hardware).CUDA_VISIBLE_DEVICES="" pytest tests/preparation/test_core_boundary.py -q:4 passed.FLARE_TEST_SNAPSHOT) and GPU paths were not run and are unaffected.Discord: Dooner