Skip to content

helios/server: return context error on exhausted default output limit - #71

Draft
FujitsuPolycom wants to merge 1 commit into
mainfrom
jetson/pr-b-context-filled-error
Draft

FujitsuPolycom wants to merge 1 commit into
mainfrom
jetson/pr-b-context-filled-error

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Why

When an OpenAI-compatible client omits max_tokens and max_completion_tokens (or sets them to null, as Open WebUI and many SDK defaults do) and submits a prompt whose length is at or above the server's max_sequence_tokens, output_limit computes remaining = context.saturating_sub(prompt) == 0 and clamps the default output budget to 0. The subsequent bounds check then rejects the request with the generic bad-request error "output limit must be between 1 and 2147483647 tokens" (mapped by helios/src/server/http.rs preparation_error to an untyped HTTP 400 invalid-request response), hiding the actual context-length failure and omitting the context_length_exceeded code and the server's optional configured context-limit hint (state.context_hint) attached to AdmissionError::Context responses.

What changed

Before this change, output_limit in helios/src/server/request.rs merged an exhausted default remaining budget (remaining == 0) with an explicitly invalid max_tokens: 0.

  • helios/src/server/request.rs:
    • Before: In output_limit, the None branch returned (configured as usize).min(remaining) as u64, producing 0 whenever prompt >= context and falling through to "output limit must be between 1 and 2147483647 tokens".
    • After: When neither max_completion_tokens nor max_tokens is provided (requested is None) and remaining == 0, output_limit returns Error::admission(AdmissionError::Context, ...) with:
      • "prompt of {prompt} tokens exceeds this server's context of {context} tokens" when prompt > context, or
      • "prompt of {prompt} tokens fills this server's context of {context} tokens, leaving no room for output tokens" when prompt == context.
    • Explicit max_tokens: 0 or max_completion_tokens: 0 continues 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 return AdmissionError::Context.
    • Unit tests (helios/src/server/request.rs): Expands omitted_output_limit_uses_remaining_context_and_explicit_limits_win to assert Error::Admission(AdmissionError::Context(_)) and exact messages for prompt == context and prompt > context with omitted and null limits, explicit positive overflow returning AdmissionError::Context, and explicit max_tokens: 0 / max_completion_tokens: 0 keeping the non-context "output limit must be between 1 and 2147483647 tokens" error.
  • Compatibility & defaults: HTTP status remains 400 Bad Request; the error code for 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

  • Isolated effect: Clients that omit max_tokens receive an accurate context_length_exceeded error reporting prompt and server context token counts instead of a misleading output-limit range error.
  • Performance impact: None (cold error path during HTTP request validation).

Supporting evidence and limitations

Tested on clean git archive 16c4c4d71e127fea6a0971bd2808f80e8ed13577 atop NVIDIA/hyperflare-inference main (7bbc6707792aa1cb8633794ee189b7592091cc45):

  • Layer 1 — CPU crate & boundary tests (passed on 16c4c4d71e127fea6a0971bd2808f80e8ed13577):
    • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server (with FLARE_TEST_TEMPLATE_DIR prepared via tests/frontend/prepare_templates.py): 1,917 passed; 0 failed; 49 ignored (lib, including server::request::tests::omitted_output_limit_uses_remaining_context_and_explicit_limits_win) and 62 passed; 0 failed; 36 ignored across integration tests (85 ignored tests require external model checkpoint snapshots or GPU hardware).
    • CUDA_VISIBLE_DEVICES="" pytest tests/preparation/test_core_boundary.py -q: 4 passed.
    • Layers 2 and 3 (scheduling simulator, TLA+, Kani) do not apply because this change is confined to HTTP request parameter validation before scheduler admission.
  • Limitations: Pure CPU HTTP request validation; checkpoint-backed integration tests (FLARE_TEST_SNAPSHOT) and GPU paths were not run and are unaffected.

Discord: Dooner

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants