fix(api): reject unknown stream_options keys even when null - #653
fix(api): reject unknown stream_options keys even when null#653seonghobae wants to merge 13 commits into
Conversation
…closed otherwise Chat history: message-level audio and legacy function_call are null/empty omit no-ops; non-empty fail closed with named errors (including tools passthrough). Tip substrate from #577 assistant refusal/annotations honesty. Local full unit: 940 passed.
…ed otherwise OpenAI fine-tune style message weight is not applied on this gateway. Accept null/0/1 as honest no-ops; reject other types and values with invalid_message_weight. Tip substrate from #578. Local full unit: 943 passed.
…ion role Reject unsupported message keys with named unknown_message_fields (not silent strip or tools-passthrough smuggle). Reject legacy function role with invalid_message_role migration to tool. Tip substrate from #579. Local full unit: 947 passed.
OpenAI partial-assistant prefix flag is not applied on this gateway. null/false are honest no-ops; true and non-booleans fail closed with invalid_message_prefix. Tip substrate from #580. Local full unit: 950 passed.
…therwise Named invalid_max_tool_calls on /v1/chat/completions instead of opaque unknown_fields. Aligns with Responses max_tool_calls honesty; gateway has no multi-step tool loop.
…losed otherwise Legacy /v1/completions treated max_tool_calls as unknown_fields. Accept the key for named invalid_max_tool_calls (null/empty/whitespace omit-equivalent), matching chat/Responses honesty so SDKs get a clear migration path.
SDK clients often send include_usage/include_obfuscation as JSON null. Drop null flag values before validation so null (and null+false mixes) match omit / all-false no-ops on chat, Completions, and Responses. True flags remain fail-closed with invalid_stream_options.
…or Responses parallel true SDK optional defaults often send function.strict and json_schema.strict as null — treat as omit rather than type errors. Align Responses parallel_tool_calls=true with chat by requiring a non-empty tools array.
SDK optional defaults often send description and parameters as JSON null. Treat null as omit rather than type errors; non-null non-string/object values remain fail-closed with invalid_tools.
OpenAI-style tool descriptions are at most 1024 characters. Over-long descriptions fail closed with named invalid_tools so SDKs never believe a truncated description was accepted.
SDK optional participant name blanks ("" / whitespace) are omit-equivalent
like JSON null. Non-string, over-long, and invalid charset names remain
fail-closed with invalid_message_name.
SDK optional defaults serialize omitted tool.function description/parameters/strict as JSON null. Accepting those keys without popping them is not omit-equivalent: proxy_completion forwards the body and several providers reject null parameters. Pop in place so passthrough matches omit; keep non-null wrong types on invalid_tools. Also pop response_format.json_schema.strict null. Tip substrate from #614. Local full unit: 989 passed.
Null flag values on allowed keys (include_usage / include_obfuscation) stay
omit-equivalent. Dropping nulls before the allow-list made {unknown: null}
look empty and silently omit — dishonest for buyers. Fail closed with
invalid_stream_options on chat, Completions, and Responses. Tip substrate
from #638. Local full unit: 996 passed.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Important Review skippedToo many files! This PR contains 144 files, which is 44 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (144)
You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Verdict
Do not merge #653 at c53774a. The unique helper-order fix is sound on Completions, Responses, and the non-passthrough chat path. The PR claim that chat rejects unknown-null stream_options is false on the tools / response_format path that buyers actually hit.
What is sound
- Unknown keys are checked before null-drop in
_validate_completions_stream_options,_validate_chat_stream_options, and_validate_responses_stream_options. - Allowed
include_usage/include_obfuscationnulls stay omit-equivalent. - Completions and Responses (including Responses + tools) return
400+invalid_stream_options. - New HTTP tests pass for the non-passthrough cases.
Blocking hole (verified live on this head)
PASSTHROUGH_TRIGGER_KEYS returns from proxy_completion before _validate_chat_stream_options:
| Request | Result on c53774a |
|---|---|
chat, no tools, {include_logprobs: null} |
400 invalid_stream_options |
chat + tools + {include_logprobs: null} |
200 billed |
chat + tools + {include_usage: true} |
200 billed |
chat + response_format + unknown-null |
200 billed |
Next action: do not land this head. The hoist lives on the successor (_validate_chat_stream_options before proxy_completion, plus tools / response_format HTTP tests).
Stack
144 files / 13 commits / +24127 vs main. Unique tip is 2 files. History still contains defective #587 9d10fa9. Do not merge that commit. Do not treat this stack as the merge vehicle.
Residual (not a #653 merge blocker once the hoist lands)
Tools passthrough still skips _validate_messages and model. Keep those on the empty-messages / stream-model hoist slices. Do not fold them onto this unknown-null tip.
Independent non-author APPROVE + Full unit + Semgrep still required on the successor. This review does not approve #653.
Sent by Cursor Automation: Fix Issues
| @@ -733,36 +3654,226 @@ def do_POST(self) -> None: # noqa: N802 | |||
| return | |||
There was a problem hiding this comment.
This proxy_completion return is the buyer-facing hole. Live on this head: tools + stream_options: {include_logprobs: null} and tools + {include_usage: true} both bill 200. _validate_chat_stream_options is still below this return (3681), so the PR claim “reject unknown keys on chat” is only true when passthrough is not taken.
Hoist stream parsing + _validate_chat_stream_options above this if so the allow-list runs on the tools / response_format path. Do not merge this head.
| if not isinstance(stream, bool): | ||
| raise RequestError(400, "invalid_request", "stream must be a boolean") | ||
| if "stream_options" in body: | ||
| _validate_chat_stream_options(body, stream) |
There was a problem hiding this comment.
This call never runs when PASSTHROUGH_TRIGGER_KEYS is present. Move it (and the stream normalize just above) to before the passthrough return. Completions/Responses already validate before their proxy; chat must match.
| { | ||
| "model": "mock-planner", | ||
| "messages": [{"role": "user", "content": "unknown null"}], | ||
| "stream_options": {"include_logprobs": None}, |
There was a problem hiding this comment.
This case never sends tools or response_format, so it cannot catch the 200-billed passthrough hole. Add HTTP cases for tools + unknown-null, tools + include_usage: true, and response_format + unknown-null before claiming the chat path is closed.
Pull request was closed
|
Superseded by tip substrate ≥ #691 (cumulative OpenAI/gateway honesty band + auto-merge tip). Closing to free product-gate runners (Full unit + Semgrep). |


Summary
stream_optionsflags stay omit-equivalent (SDK defaults).{unknown_flag: null}look empty and silently omit — dishonest for buyers.invalid_stream_optionson chat, Completions, and Responses even when the unknown value is null.Test plan
python -m pytest tests -q(996 passed)