Skip to content

studio/openai: align chat completions docstring with stream=false default (closes #5047) - #5524

Merged
rolandtannous merged 7 commits into
unslothai:mainfrom
wtfashwin:fix/5047-openai-stream-default-docstring
May 17, 2026
Merged

rolandtannous merged 7 commits into
unslothai:mainfrom
wtfashwin:fix/5047-openai-stream-default-docstring

Conversation

@wtfashwin

Copy link
Copy Markdown
Contributor

Summary

POST /v1/chat/completions's docstring still says "Streaming (default)", but the schema and the existing pydantic regression test were already corrected so ChatCompletionRequest.stream defaults to false (matching OpenAI's spec). The stale docstring is the last loose end on #5047 — anyone debugging the original .NET / System.Text.Json report and grepping the route would still come away thinking SSE is the default behavior.

Two tiny changes, no logic touched:

  1. studio/backend/routes/inference.py — flip the two-line block in openai_chat_completions' docstring to list Non-streaming (default) first and add a one-line note pointing to [Bug] /v1/chat/completions defaults to streaming when stream is omitted #5047.
  2. studio/backend/tests/test_openai_tool_passthrough.py — extend the comment on test_stream_defaults_false_matching_openai_spec to mention the .NET / System.Text.Json failure mode from [Bug] /v1/chat/completions defaults to streaming when stream is omitted #5047, so the test's intent stays discoverable.

Why this is the right scope

I checked all three OpenAI-compat schemas — ChatCompletionRequest, AnthropicMessagesRequest, ResponsesRequest — and all three already pin stream to False with matching tests in test_openai_tool_passthrough.py:299, test_anthropic_messages.py:89, and test_responses_api.py:91. Confirmed via grep + reading; nothing else to change.

I also checked routes/inference.py for other stale Streaming (default) mentions — there's only the one at line 1962. The Anthropic Messages and Responses route docstrings are neutrally worded.

Test plan

  • ruff check — clean on both files
  • scripts/enforce_kwargs_spacing.py — clean (no kwarg lines touched; only docstring + comment)
  • python3 -m ast parse — both files import cleanly
  • pytest studio/backend/tests/test_openai_tool_passthrough.py in CI

Happy to extend if you'd like an httpx.AsyncClient integration test that hits the route with the stream field omitted and asserts JSON (vs. SSE) — wasn't sure if the existing schema-level pin felt sufficient. Defer to your call.

…ault

The schema and regression test for ChatCompletionRequest.stream were
already corrected to default `false` (matching OpenAI's spec), but the
route docstring still claimed streaming was the default -- misleading
for anyone reading the source while debugging the original report.

Updates the docstring to reflect the actual behavior, adds an explicit
note pointing to unslothai#5047, and tags the existing regression test with the
issue reference and the .NET / System.Text.Json client class so the
intent survives future cleanup.

Closes unslothai#5047
@wtfashwin
wtfashwin force-pushed the fix/5047-openai-stream-default-docstring branch from f4b396f to 4227091 Compare May 17, 2026 16:03

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the documentation and test comments for the openai_chat_completions endpoint to reflect that non-streaming is now the default behavior, aligning with the OpenAI specification. Feedback suggests removing internal issue references from public-facing docstrings to keep API documentation clean and expanding test coverage to include route-level verification of the non-streaming response.

Comment thread studio/backend/routes/inference.py Resolved
wtfashwin and others added 2 commits May 17, 2026 21:39
…I doc, add route-level test

Two follow-ups on review feedback:

- Drop "(see unslothai#5047)" from the openai_chat_completions docstring so the
  internal issue number doesn't leak into the FastAPI-generated
  OpenAPI / Swagger schema. The reference now lives in a code comment
  next to the actual `if payload.stream:` branch, where it's most
  useful for the next person debugging the same class of report.

- Add test_post_without_stream_field_decodes_to_stream_false_over_http:
  a TestClient-based wire-level guard that POSTs a body without
  `stream` (the exact shape naive curl / .NET / System.Text.Json
  clients send) and asserts both that the request deserialises into
  stream=False *and* that the response Content-Type is
  application/json, never text/event-stream. The existing
  constructor-level test would silently miss regressions introduced
  by middleware or alias rewrites that mutate the body before the
  pydantic model is built.

Refs unslothai#5047
@rolandtannous

Copy link
Copy Markdown
Contributor

Addressed review feedback:

  1. #5047 reference: confirmed already moved out of the route docstring in 3fb0ffc. The issue ref now lives in a code comment at inference.py:2190-2192, so it is not exposed via OpenAPI/Swagger.

  2. Route-level test coverage: expanded test_post_without_stream_field_decodes_to_stream_false_over_http to mount the real routes.inference.router instead of a synthetic FastAPI app. The test overrides get_current_subject, monkey-patches _proxy_to_external_provider to capture payload.stream, and POSTs with provider_type: "openai" (no stream field) so the request hits the actual openai_chat_completions handler. This catches middleware/aliasing regressions on the live endpoint, which addresses Gemini's original comment.

@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: f684baebd5

ℹ️ 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 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: 253b27ec89

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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