Skip to content

fix(llm): align stop-sequence limits and return 400 - #14462

Merged
rmccorm4 merged 2 commits into
ai-dynamo:mainfrom
flpanbin:fix-stop-validate
Sep 15, 2026
Merged

rmccorm4 merged 2 commits into
ai-dynamo:mainfrom
flpanbin:fix-stop-validate

Conversation

@flpanbin

@flpanbin flpanbin commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Overview:

Fixes the opaque HTTP 500 returned when a chat/completion request contains more than 4 stop (or stop_token_ids) entries. The request now fails fast at the HTTP boundary with a clear 400 validation error, and the two previously inconsistent stop-sequence limits in the codebase are aligned to a single constant.

Details:

The bug had two layers:

  • Inconsistent limits: pre-validation allowed up to 32 stop sequences (MAX_STOP_SEQUENCES = 32 in validate.rs), while request extraction bailed at more than 4 (hard-coded in openai.rs::extract_stop_conditions).
  • 500 instead of 400: the extraction failure was a plain anyhow::bail!, which the HTTP error mapper could not classify, so it fell through to the generic "Failed to generate completions" 500.

Changes:

  • lib/llm/src/protocols/openai/validate.rs
    • MAX_STOP_SEQUENCES tightened from 32 to 4, matching the OpenAI API contract.
    • Validation error messages corrected to the accurate "Maximum of N stop sequences allowed, got M" (the old "less than 4" wording was wrong — exactly 4 are accepted).
  • lib/llm/src/protocols/openai.rs
    • extract_stop_conditions now uses the shared MAX_STOP_SEQUENCES constant instead of a hard-coded 4, with corrected messages.

The 500→400 fix is structural, validation now rejects over-limit requests at the entry point, so they never reach the engine path that produced the opaque 500.

Where should the reviewer start?

  1. lib/llm/src/protocols/openai/validate.rs — the constant, the two validate_stop messages, and the new stop_token_ids count check in validate_no_unsupported_fields.
  2. lib/llm/src/protocols/openai.rs — extract_stop_conditions backstop now shares the same constant.
  3. Tests: validate.rs and chat_completions.rs

Validation

  • cargo test -p dynamo-llm --lib protocols::openai
  • cargo clippy -p dynamo-llm --lib
  • cargo fmt -p dynamo-llm
  • E2E(Frontend + vLLM worker):
curl -s http://<frontend>:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"Qwen3-VL-2B-Instruct","messages":[{"role":"user","content":"Say hi"}],"max_tokens":5,"stop":["a","b","c","d","e"]}'

# response
{"message":"Validation: Maximum of 4 stop sequences allowed, got 5","type":"Bad Request","code":400}
curl -s http://<frontend>:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"Qwen3-VL-2B-Instruct","messages":[{"role":"user","content":"Say hi"}],"max_tokens":5,"stop_token_ids":[1,2,3,4,5]}'

#response
{"message":"Validation: Maximum of 4 stop token IDs allowed, got 5","type":"Bad Request","code":400}

Related Issues

⚠️ This section is required. Choose one path below and delete the other.

🔗 This PR is linked to an issue:

🚫 This PR is NOT linked to an issue:

  • Confirmed — no related issue

Summary by CodeRabbit

  • Bug Fixes
    • Stop-sequence validation now consistently enforces a maximum of four entries across supported request formats.
    • Validation errors now identify the applicable limit and the number of entries provided.
  • Tests
    • Added coverage for valid four-entry configurations and rejected five-entry configurations, including token ID passthrough cases.

@flpanbin
flpanbin requested a review from a team as a code owner September 8, 2026 07:55
@copy-pr-bot

copy-pr-bot Bot commented Sep 8, 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.

@flpanbin
flpanbin temporarily deployed to external_collaborator September 8, 2026 07:55 — with GitHub Actions Inactive
@flpanbin
flpanbin temporarily deployed to external_collaborator September 8, 2026 07:55 — with GitHub Actions Inactive
@github-actions github-actions Bot added fix frontend `python -m dynamo.frontend` and `dynamo-run in=http|text|grpc` labels Sep 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

👋 Hi flpanbin! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions Bot added the external-contribution Pull request is from an external contributor label Sep 8, 2026
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 64f5bfc0-2039-4923-bdc4-b9c34a18156a

📥 Commits

Reviewing files that changed from the base of the PR and between 946acce and 8cfb970.

📒 Files selected for processing (3)
  • lib/llm/src/protocols/openai.rs
  • lib/llm/src/protocols/openai/chat_completions.rs
  • lib/llm/src/protocols/openai/validate.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

Changes

OpenAI stop sequence limits

Layer / File(s) Summary
Shared limit and request validation
lib/llm/src/protocols/openai/validate.rs
MAX_STOP_SEQUENCES changes from 32 to 4. Passthrough stop_token_ids validation rejects more than four entries and reports the configured maximum and received count. Tests cover accepted and rejected inputs.
Stop-condition extraction enforcement
lib/llm/src/protocols/openai.rs, lib/llm/src/protocols/openai/chat_completions.rs
Stop-condition extraction uses MAX_STOP_SEQUENCES for string stop sequences and token IDs. Tests cover validation and extraction for four-item and five-item inputs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 8cfb9

OpenAI requests with more than four stop sequences or stop token IDs now receive clear validation failures rather than reaching the engine path. The shared enforcement and boundary coverage indicate no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: aligning stop-sequence limits and returning HTTP 400 responses.
Description check ✅ Passed The description covers the overview, implementation details, reviewer starting points, validation commands, test behavior, and related issue. It is mostly complete, although it retains both Related Is…
  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

@flpanbin
flpanbin temporarily deployed to external_collaborator September 8, 2026 08:26 — with GitHub Actions Inactive
@flpanbin flpanbin changed the title fix(llm): align stop-sequence limits and return 400 instead of fix(llm): align stop-sequence limits and return 400 Sep 10, 2026
@rmccorm4
rmccorm4 temporarily deployed to external_collaborator September 10, 2026 18:02 — with GitHub Actions Inactive
@rmccorm4

Copy link
Copy Markdown
Contributor

/ok to test 9c4e4ab

Comment thread lib/llm/src/protocols/openai.rs Resolved
Comment thread lib/llm/src/protocols/openai.rs Resolved
@rmccorm4 rmccorm4 self-assigned this Sep 10, 2026
@flpanbin
flpanbin temporarily deployed to external_collaborator September 11, 2026 07:16 — with GitHub Actions Inactive
@flpanbin

flpanbin commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @rmccorm4, One follow-up thought: the stop-limit checks in this PR now return typed InvalidArgument errors, but validation is inconsistent elsewhere — the other bail! inside validate_stop (empty-array / empty-string checks) are still plain anyhow, and validators like validate_logprobs and validate_top_p bail with plain text throughout.

Is the intent that validation errors should generally be typed InvalidArgument? If so, I'd be happy to unify the remaining bail!(57 counts) sites in validate.rs in a separate PR.

@rmccorm4
rmccorm4 temporarily deployed to external_collaborator September 14, 2026 23:33 — with GitHub Actions Inactive
@rmccorm4

Copy link
Copy Markdown
Contributor

/ok to test ff62e88

@rmccorm4
rmccorm4 enabled auto-merge (squash) September 14, 2026 23:42
@rmccorm4
rmccorm4 merged commit 9062a66 into ai-dynamo:main Sep 15, 2026
116 checks passed

This branch was previously deployed

1 inactive deployment
external_collaborator — ff62e889 Deployed Sep 14, 2026 by rmccorm4 via ok-to-test #18139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix frontend `python -m dynamo.frontend` and `dynamo-run in=http|text|grpc` size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: stop / stop_token_ids with more than 4 entries returns opaque 500 instead of a 400 validation error

2 participants