Skip to content

Studio: serve /v1/completions from managed vLLM and SGLang engines - #14227

Merged
danielhanchen merged 6 commits into
mainfrom
studio-completions-managed-engine
Oct 20, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
studio-completions-managed-engine

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Problem

/v1/completions only served a resident GGUF (llama-server) or MLX model. With a model running on the opt-in managed vLLM or SGLang engine, every completions request got the No GGUF model loaded 503, even though both engines serve /v1/completions natively, including logprobs, echo and prompt_logprobs.

That blocks log-likelihood evaluation (lm-evaluation-harness local-completions, MMLU, HellaSwag and similar multiple-choice tasks) through Studio for any non-GGUF model on Linux GPUs.

Part of #7703.

What changed

  • /v1/completions now relays the request to the managed engine when one is resident and alive. Only model is rewritten (public id to the served name on the way in, and back on the way out); every other field reaches the engine as sent, so vLLM / SGLang validate and serve logprobs, echo and prompt_logprobs themselves.
  • Streaming and non-streaming both work. Streaming always asks the engine for usage so the API monitor can count tokens, and drops it again unless the caller asked for stream_options.include_usage.
  • Same lifecycle as managed-engine chat: API monitor entry, active-generation tracking (a non-forced unload waits for the request), cancel on client disconnect, keepwarm marking on failure, and engine errors keep their status code.
  • echo is no longer refused up front while an engine is resident. suffix and best_of are still refused as before.

What does not change

  • A loaded GGUF still wins and is proxied exactly as before, and MLX is still served in process ahead of this path.
  • With nothing resident the 503 is unchanged.
  • Auto-switch still refuses to load a managed-engine target from /v1/completions; a request naming the resident engine model is served.
  • No UI change.

Tests

studio/backend/tests/test_managed_engine_completions.py (9 tests): non-stream logprobs + echo relay with the model rewritten both ways, streaming with and without usage, engine 400 keeps its status, echo reaching a resident engine, plus controls (dead engine still 503, safetensors without an engine still 503, echo still refused with no engine, a loaded GGUF still wins). The 5 behaviour tests fail on main and pass here; the 4 controls pass on both.

cd studio/backend
python -m pytest -q tests/test_managed_engine_completions.py tests/test_managed_engine_tools.py tests/test_openai_tool_passthrough.py tests/test_openai_auto_switch.py

Against a real vllm serve of Qwen/Qwen2.5-0.5B-Instruct in fp16 on a T4, with the lm-eval scoring shape (logprobs: 2, echo: true, max_tokens: 1): the merge base answers 503, this branch answers 200 with the public model id, and the prompt logprobs equal what vLLM returns when asked directly. Streaming answers 200 as well.

A resident vLLM or SGLang model answered /v1/completions with the GGUF-only
503. Relay the body to the engine's own /v1/completions with the served model
id swapped in, so logprobs, echo and prompt_logprobs reach clients such as
lm-evaluation-harness local-completions. GGUF and MLX routing are unchanged.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T22:46:30.675673Z e098c31 Manual request
🔒 Security Review ⚠️ Failed 2026-10-19T09:04:29.923254Z 943a29f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen danielhanchen self-assigned this Oct 19, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 943a29f78c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

engine = backend._managed_engine
public = api._orchestrator_public_model_id(backend) or engine.model
stream = bool(body.get("stream"))
include_usage = bool((body.get("stream_options") or {}).get("include_usage"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve engine validation for malformed stream_options

When a managed-engine request supplies a truthy non-object stream_options value (for example, {"prompt":"hi","stream":true,"stream_options":true}), this .get() raises AttributeError before the request reaches vLLM/SGLang, producing a Studio 500 instead of the engine's normal validation response. The mapping expansion on line 496 has the same problem; check that the value is a dict before inspecting or merging it so invalid client input remains a 4xx.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A non-object stream_options is malformed input, and the pre-existing GGUF branch of this same endpoint reads it the same way two lines below, so this is existing behaviour rather than something introduced here.

Comment on lines +528 to +531
response = await client.send(
client.build_request("POST", url, headers = engine.headers, json = upstream),
stream = True,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid waiting for the first SGLang token before responding

For streaming SGLang completions, the supported 0.5.17 server consumes the first generated chunk before sending its HTTP 200 response (SGLang handler), while this eager client.send() must receive those upstream headers before Studio constructs its own streaming response. A queued or long-prefill request therefore sends neither headers nor keepalives to the caller until the first token, so clients and proxies can time out even though engine_request_timeout() deliberately permits a much longer generation; start the upstream request from the relay and pace the silent wait instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The GGUF completions path awaits its upstream send before responding too (_send_stream_with_preheader_cancel), as does managed chat, so this matches the shipped contract rather than regressing it. Moving the send into the relay would change that contract for all three paths, and a disconnect during the wait is already handled: the watcher closes the client and the send raises into the 499 branch.

if response.status_code != 200:
await close()
api.api_monitor.fail(monitor_id, response.text[:500])
raise api._openai_passthrough_error(response.status_code, response.text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Attribute managed completion overflows to prompt

When vLLM or SGLang rejects an oversized completion prompt, _openai_passthrough_error() recognizes the context-overflow text but hard-codes param="messages", because it was written for chat requests. Calling it here therefore returns context_length_exceeded for a field that does not exist on /v1/completions; clients that use the parameter to decide what to trim cannot identify prompt. Pass a completions-specific parameter to the error mapper on this path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed that param names a field this endpoint does not have, but it is an error-payload label with no behaviour attached, and threading an override through a helper shared with chat is not worth it here.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: eded3b7ddb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 19, 2026
@NilayYadav NilayYadav self-assigned this Oct 19, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: d7464e2828

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: e098c311c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@NilayYadav

Copy link
Copy Markdown
Collaborator

Review + reproduction evidence

Pinned review: e098c311c6d1cbaf30543b2440812ad135454647. 1 finding, fixed in ee3bafc25 (the new echo test returned 503 instead of 400 on Apple Silicon because the device was not pinned).

I reproduced loading Qwen/Qwen2.5-0.5B-Instruct on the managed vLLM 0.26.0 engine and calling /v1/completions on the merge base a33463f (Linux, NVIDIA L4, Chromium 1440x900 for the API page):

  • Before (a33463f): the lm-eval scoring request {"prompt": "The capital of France is Paris", "logprobs": 2, "echo": true, "max_tokens": 1, "temperature": 0} returns 503 No GGUF model loaded. Load a GGUF model first.. Plain, list-prompt, streaming and streaming with usage requests return the same 503. The API page shows 0 /completions rows (REQUESTS 1, the chat call only).
  • PR head: the same request returns 200 with "model": "Qwen/Qwen2.5-0.5B-Instruct", echoed text "The capital of France is Paris." and prompt token logprobs [null, -9.883, -0.320, -4.293, -0.358, -1.204, -0.660] for The / capital / of / France / is / Paris / .. Streaming returns 7 events without usage and 8 with stream_options.include_usage, both ending in [DONE]. A list prompt returns 2 choices. suffix is still refused with 400. The API page lists 5 /completions rows, all completed (REQUESTS 6, ERRORS 0).

PR 14227 before/after: API page after the same requests, merge base vs PR

  • Unchanged on both sides: chat on the engine (same reply), a GGUF model's completions (200 " 4, ", and 400 for echo), and the 503 after unloading.
  • Disconnecting a long stream and then unloading without force returns 200 after 5.6 s, so nothing stays marked as running.
  • The new tests fail 6 of 10 on the merge base and pass 10 of 10 on the PR, on Linux and macOS. The existing auto-switch, tool passthrough and managed tool suites pass the same on both sides (1357 tests).

Conclusion: This is a real gap and the PR fixes it. It merges cleanly with #14229 in either order. SGLang and Windows were not run.

@unslothai unslothai deleted a comment from NilayYadav Oct 20, 2026
@unslothai unslothai deleted a comment from NilayYadav Oct 20, 2026
@danielhanchen
danielhanchen merged commit 1935c8a into main Oct 20, 2026
@danielhanchen
danielhanchen deleted the studio-completions-managed-engine branch October 20, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants