Skip to content

fix(model): return OpenAI context-overflow error envelopes - #3978

Merged
ananthsub merged 4 commits into
mainfrom
alexandery/context-overflow-error-envelope
Oct 15, 2026
Merged

ananthsub merged 4 commits into
mainfrom
alexandery/context-overflow-error-envelope

Conversation

@alexandery-nvidia

@alexandery-nvidia alexandery-nvidia commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

With propagate_context_overflow_errors on, the vLLM model server lets the engine's HTTP 400 reach the harness when a request no longer fits the model's context window. On main the harness receives vLLM's raw body, whose code is the integer 400. An OpenAI-compatible harness (Codex, OpenCode) classifies a context overflow by the string code context_length_exceeded inside OpenAI's error envelope, so it cannot recognize the refusal and compact its history; on a streaming /v1/chat/completions request that has passed its keepalive, the error event carries the same integer code.

  1. OpenAI's error envelope for a propagated refusal. VLLMModel._should_propagate_upstream_http_error returns false for an error the server marked as a propagated length refusal, so the shared error handler (fix(core): preserve provider bodies for propagated errors #4285) lets it through to the server's own middleware, which answers {"error": {"message": <the engine's message, verbatim>, "type": "invalid_request_error", "param": <the engine's param>, "code": ...}} with the engine's status. context_overflow_error_fields in nemo_gym.base_responses_api_model reads the message and param from vLLM's nested error object (0.10.1 and later), from the flat top-level message of older engines, or from the raw text, so no information is lost. The mark is one attribute, PROPAGATED_REFUSAL_CODE_ATTRIBUTE: its presence marks the error (is_propagated_refusal) and its value is the envelope code. A streaming /v1/responses request gets the same HTTP 400 before the stream, as main answers it since fix(core): preserve provider bodies for propagated errors #4285; nothing has been sent yet, so an HTTP status is the right answer and the one OpenAI itself gives.
  2. The code says whether compacting the prompt is the remedy. A body that names the context window carries code: "context_length_exceeded": vLLM 0.29.0's two wordings ("This model's maximum context length is ..." and "Input length (N) exceeds model's maximum context length (M)."), the engine's "decoder prompt ... is longer than the maximum model length", and llama.cpp's exceed_context_size_error type and phrases. A body that only names the output-token parameter ("max_tokens must be at least 1", "max_completion_tokens=N cannot be greater than max_model_len") carries code: null: lowering the parameter fixes those, shortening the prompt does not, so the harness reports an ordinary invalid request with the engine's sentence instead of compacting. The classification itself stays the shared _is_context_length_error; it now also recognizes max_completion_tokens and "maximum model length", two length refusals that the f128d43 base answered with a plain HTTP 400 from the shared handler. With the setting off they are now absorbed into an empty completion with finish_reason: "length" like every other recognized refusal (see below); with it on they carry the envelope, context_length_exceeded for the "maximum model length" wording and code: null for the max_completion_tokens parameter error.
  3. The chat-SSE error after the keepalive carries the envelope. Once a streaming /v1/chat/completions request has committed its headers, a marked refusal is reported as event: error with the same message, param, and code, and logged as one warning instead of a traceback.

The default (propagate_context_overflow_errors: false) keeps absorbing a recognized refusal into an empty HTTP 200 completion with finish_reason: "length". One consequence of the wider classifier: the max_completion_tokens and "maximum model length" phrasings are now recognized too, so with propagation off they are absorbed the same way, where before this change they fell through to the shared HTTP 400 handler. With propagation on, a parameter-only error keeps code: null and a context-window error carries context_length_exceeded.

Relation to the model-execution record

ModelExecutionOutcome records an absorbed overflow as local_response_reason: "context_length_exceeded" on the observability model-call record, and that path is unchanged here. This PR concerns the propagated case only, which is what the client sees.

Issue

No issue filed; observed while training with the Codex CLI through the streaming /v1/responses route, which could not classify the overflow and retried the request.

Validation

  • responses_api_models/vllm_model/tests/test_app.py, tests/unit_tests/test_base_responses_api_model.py, tests/unit_tests/test_responses_api_model_streaming.py, tests/unit_tests/test_chat_completions_streaming.py: 659 passed. The propagation test runs six engine bodies (vLLM 0.29.0's two overflow wordings with their param, the engine's "maximum model length" message, llama.cpp's typed refusal, and the two output-token parameter errors) on both engine routes and both APIs, with the setting on and off; new tests cover the HTTP 400 on a streaming /v1/responses request, the envelope in the chat-SSE error after the keepalive, and the message, param, and code extraction from the nested, flat, and raw bodies.
  • Full tests/unit_tests and every responses_api_models/*/tests suite on this branch: the only failures (opensandbox, telemetry, and the two servers that import vllm) are the same as on main f128d43 in the same environment.
  • ruff check and ruff format --check on the changed files: clean.
  • Rollout evidence: the envelope has run for weeks in a downstream fork training with OpenCode and Codex harnesses under token-id capture with propagate_context_overflow_errors: true. With it, Codex fails the turn without an item and OpenCode records the error and exits, so a session that reaches the window ends cleanly and trains up to its last completed call instead of retrying the refused request.

Review follow-up

Rebased onto main f128d43 after #3371 (the shared _is_context_length_error) and #4285 (the shared error handler and the HTTP 400 before a stream), which changed the shape of this change: the envelope is produced through the propagation hook, and the terminal response.failed event of the earlier revision is gone. The huggingface-hub<2 bound that the validation merges had added to this branch lives in #4362 now.

main 4518db9 is merged into the branch (c19c51c, 2026-10-14). The one conflict was the FastAPI import line of responses_api_models/vllm_model/app.py; both sides are kept, and Response is dropped from the import because the envelope is returned as a JSONResponse, so nothing in the module constructs a bare Response any more.

yaoyu-33's suggestion of 2026-10-12 (00ad0f0): the boolean marker and the code attribute are one attribute whose presence is the mark and whose value is the code (None for an output-token parameter refusal stays distinct from an unmarked exception); the marking helper, the shared-handler hook, the HTTP middleware and the chat-SSE path read it, and the extraction test covers the unmarked, None-code and overflow-code states. tests/unit_tests/test_base_responses_api_model.py 106 passed, responses_api_models/vllm_model/tests 439 passed.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@linj-glitch linj-glitch changed the title fix(model): a propagated context overflow is answered in OpenAI's error envelope on both the HTTP and streaming paths fix(model): return OpenAI context-overflow error envelopes Oct 5, 2026
@linj-glitch linj-glitch added area:model Model servers, inference providers, and model adapters bug Something isn't working ready-to-merge PR is approved, current, and waiting for final CI or merge labels Oct 5, 2026
@linj-glitch
linj-glitch marked this pull request as ready for review October 5, 2026 07:50
linj-glitch
linj-glitch previously approved these changes Oct 5, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed context-overflow versus max_tokens classification, OpenAI HTTP envelopes, SSE failure codes, and current-main credential redaction against current main and the existing model-server contract. No blocking findings remain.

Validation: 452 focused tests passed; full pre-commit suite and git diff --check passed. Model plugin imports were pinned to this review checkout in the shared dependency environment. Additive main merges preserve the author commits and retain the current-main credential-redaction regression tests. No fresh GPU/model rollout was run locally; the author-provided downstream deployment evidence is retained above.

@linj-glitch

Copy link
Copy Markdown
Collaborator

/ok to test 7e57c3f

@linj-glitch
linj-glitch enabled auto-merge October 5, 2026 07:50
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 5, 2026 07:51
@linj-glitch
linj-glitch added this pull request to the merge queue Oct 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 5, 2026
@yaoyu-33 yaoyu-33 added the complexity:medium Single-domain change with interacting parts or a moderate review surface label Oct 5, 2026
linj-glitch
linj-glitch previously approved these changes Oct 5, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed context-overflow versus max_tokens classification, OpenAI HTTP envelopes, SSE failure codes, and current-main credential redaction against current main and the existing model-server contract. No blocking findings remain.

Validation after the final additive merge of current main: 463 focused regression tests passed; the full repository pre-commit suite and git diff --check passed. The context-error classification preserves the current-main rollout-health error category on both upstream routes. Author history is preserved. Model plugin imports were pinned to this review checkout in the shared dependency environment. No fresh GPU/model rollout was run locally; the author-provided downstream deployment evidence is retained above.

@linj-glitch

Copy link
Copy Markdown
Collaborator

/ok to test 7038779

linj-glitch
linj-glitch previously approved these changes Oct 5, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed context-overflow versus max_tokens classification, OpenAI HTTP envelopes, SSE failure codes, and current-main credential redaction against current main and the existing model-server contract. No blocking findings remain.

Validation after the final additive merge of current main: 465 focused regression tests passed; the full repository pre-commit suite and git diff --check passed. The context-error classification preserves the current-main rollout-health error category on both upstream routes. Author history is preserved. Model plugin imports were pinned to this review checkout in the shared dependency environment. No fresh GPU/model rollout was run locally; the author-provided downstream deployment evidence is retained above.

The subsequent merge of Gym3977 preserves the engine-error warning and both test sets; the 465-test selection and full hooks passed again after that conflict resolution.

Added focused compatibility bounds for full server CI: Hugging Face Hub below2 in the dev extra, and a datasets floor confined to Aviary. These avoid the reproduced SDK/cookie transport failures and legacy tokenizer/PyArrow resolution; all locked package versions remain unchanged. Ordinary server setup also selects dev. Fresh installs across GDPVal, OpenEnv, session-state, Aviary, LangGraph, and Fabric passed640 tests with1 intentional Docker skip. Final-head focused tests, full pre-commit, uv lock --offline --check, and git diff --check passed. The full GitHub server suite remains required before merging. No separate issue is needed for these narrow CI compatibility fixes.

@linj-glitch

Copy link
Copy Markdown
Collaborator

/ok to test 84b427d

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 5, 2026 18:34
@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Oct 14, 2026
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

@ananthsub every thread of your 10/08 round is answered and resolved, and @yaoyu-33 approved the current head (00ad0f0) on 10/13 with the ready-to-merge label, but your earlier change request still blocks the merge. Could you re-review, or dismiss that review if the redesign on main's #3371/#4285 error path (summarized in the description) is what you had in mind? The re-request has been pending since 10/13.

linj-glitch
linj-glitch previously approved these changes Oct 14, 2026

@linj-glitch linj-glitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 00ad0f0. The error-envelope and marker changes address the prior concerns; 811 current-head native tests and 96 additional HTTP/SSE and propagation probes passed, with focused Ruff checks clean.

One description clarification: the newly recognized max_completion_tokens/maximum-model-length errors are absorbed into empty HTTP 200 length completions with propagation off; those cases previously reached the shared HTTP 400 handler. With propagation on, parameter-only errors correctly keep code=null and context-window errors use context_length_exceeded.

The remaining P0 conformance failures match demonstrated failures on the older main baseline and are addressed by upstream #4450. Those exact-head CI gates and Ananth's final shared-code review still need to be cleared before merge. No fresh GPU/model rollout was run.

alexandery-nvidia and others added 2 commits October 14, 2026 16:23
…erflow-error-envelope

Signed-off-by: alexandery <[email protected]>

# Conflicts:
#	responses_api_models/vllm_model/app.py
…used

The envelope is returned as a JSONResponse, so after the merge of main
nothing in the module constructs a bare Response any more.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test baa46da

@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

Merged main 4518db9 into the branch (c19c51c). The one conflict was the FastAPI import line of vllm_model/app.py: main now imports HTTPException there and this branch returns the envelope as a JSONResponse; both are kept, and the Response import nothing uses any more is dropped (baa46da). The description now says what @linj-glitch's review noted: with propagation off, the newly recognized max_completion_tokens and "maximum model length" phrasings are absorbed into an empty length completion instead of reaching the shared HTTP 400 handler. The Gym suites on this head match main's failures locally; CI is triggered on the new head. @ananthsub, your 10/08 change request is the one thing still blocking this PR (approved by @yaoyu-33 on 10/13 and @linj-glitch on 10/14, every thread of that round resolved); a re-review or a dismissal unblocks it.

@yaoyu-33 yaoyu-33 added waiting-on-maintainers Waiting on maintainers to respond and removed ready-to-merge PR is approved, current, and waiting for final CI or merge labels Oct 14, 2026

@ananthsub ananthsub left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this addresses everything from the last round:

  • The nested vLLM 0.29.0 error body is read, and the fixtures use the engine's real messages.
  • The HTTPException relay is gone.
  • The code split now lives in the envelope rather than the classification, so with the setting on, a misconfigured max_tokens is a visible 400 with code null.
  • Both follow-ups are done. The streaming chat-completions error after the keepalive carries the envelope, and the max_completion_tokens and "maximum model length" messages are classified.
  • The merge with main resolves the fastapi import the way main needs it.

One small description fix before merge. It says the max_completion_tokens and "maximum model length" refusals were answered with a 500 before. On the f128d43 base they were a plain 400 from the shared handler, and with the setting off they are now empty completions with finish_reason: length. Please say that, as Lin noted.

@alexandery-nvidia

Copy link
Copy Markdown
Contributor Author

Description fixed as you and Lin noted: the max_completion_tokens and "maximum model length" refusals were a plain HTTP 400 from the shared handler on the f128d43 base; with the setting off they are now absorbed into an empty completion with finish_reason: "length", and with it on they carry the envelope (context_length_exceeded for the model-length wording, code: null for the parameter error). Thanks for the approval, @ananthsub.

@ananthsub
ananthsub added this pull request to the merge queue Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/38659187647

@alexandery-nvidia alexandery-nvidia added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 15, 2026
Merged via the queue into main with commit c7b1bdf Oct 15, 2026
56 of 61 checks passed
@ananthsub
ananthsub deleted the alexandery/context-overflow-error-envelope branch October 15, 2026 00:36
JeffPengCoder added a commit that referenced this pull request Oct 18, 2026
Three conflicts, resolved as follows:

- nemo_gym/server_utils.py: the validation-failure log line keeps this
  branch's body shape (no raw body prefix, which can carry credentials or
  screenshot data) and adds main's validation_errors field. Main's
  test_validation_exception_custom_header_query_messages_are_not_rendered
  checks the body diagnostic under request_body_shape accordingly.
- responses_api_models/vllm_model/app.py: main's context-window markers
  (#3978) already cover vLLM's "decoder prompt ... longer than the maximum
  model length"; this branch's separate check is dropped.
- responses_api_models/vllm_model/tests/test_app.py: main's parametrization
  of the overflow cases, which includes the decoder-prompt message. This
  branch's test that unrelated failures are not overflow drops the case
  "The configured maximum model length is invalid", which main's broader
  marker classifies as overflow by design.

Checked on the merge: uv lock --check; pre-commit on the resolved files;
core unit tests (scripts/ci/core_unit_tests.sh extras, -m "not sandbox"):
9,020 passed, the 23 remaining failures fail identically on main b3103ea
on the same macOS host (launcher, CI-environment, OpenSandbox and telemetry
memory tests); shared web and WebVoyager 253, vllm_model 571, web_agent 87,
visual_browser 29 in their own environments.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Jeff Peng <[email protected]>

This branch was previously deployed

1 inactive deployment
public — baa46da6 Deployed Oct 14, 2026 by copy-pr-bot[bot] via release / finalize / notify #5428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model servers, inference providers, and model adapters bug Something isn't working complexity:medium Single-domain change with interacting parts or a moderate review surface ready-to-merge PR is approved, current, and waiting for final CI or merge sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants