fix(api): fail-closed empty messages, spend keys, and request knobs on tools passthrough - #596
fix(api): fail-closed empty messages, spend keys, and request knobs on tools passthrough#596cursor[bot] wants to merge 14 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.
…age honesty Null include_usage/include_obfuscation stay omit-equivalent, but unknown stream_options keys no longer become no-ops just because their value is null. Weight, prefix, refusal, annotations, developer role, empty user/system content, and participant name now use the same named errors on the tools passthrough path as on orchestration. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Hoist stream, required model, stream_options, and temperature/top_p range checks before proxy_completion so a tools or response_format body cannot return a billed JSON completion when the SDK asked for SSE, or silently pick a pool model when model is omitted. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Hoist attribution and routing validation before proxy_completion so a tools or response_format body cannot bill a sync completion with an unknown spend dimension or a batch/latency_tolerant hint. Tools passthrough has no batch job plane. Buyer next action: send known sync attribution; omit routing.channel=batch and latency_tolerant=true on tool-calling requests. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Match _validate_messages: tools + user content 123 must 400 invalid_message instead of billing a sync completion. Assistant/tool JSON null stays omit-equivalent. Buyer next action: send user/system content as a non-empty string or a content-parts array. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Match the tools-path honesty contract to the invalid_message behavior so SDK clients send a string or content-parts array. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Hoist the remaining chat request knobs before proxy_completion so an OpenAI SDK tool-calling body cannot bill a sync completion for seed, stop, n>1, logprobs, logit_bias, out-of-range token/penalty values, unsupported reasoning_effort, or a non-default service_tier. Buyer next action: omit those fields on tool-calling requests; they are not applied on this gateway. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Call _validate_messages before proxy_completion so tools + [] / omitted / null / non-list / non-object messages raise invalid_message instead of billing a completion with no prompt. Buyer next action: always send a non-empty messages array of objects on tool-calling requests. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
|
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. |
There was a problem hiding this comment.
Stale comment
Review (#596 @
7a07562)Live HTTP on this head confirms the unique work is real:
_validate_messagesbeforeproxy_completion—tools+[]/ omitted /null/ non-list / non-object →400 invalid_message(not a billed completion withprompt_tokens: 0, not500).- Attribution / routing hoist — unknown spend keys,
routing.channel=batch, andlatency_tolerant=true→400._validate_chat_passthrough_request_knobs—seed,stop,n>1,logprobs,logit_bias, out-of-range penalties,store=true, non-stringuser, unsupportedreasoning_effort/service_tier→ named 400s. Omit-equivalent null/n=1/logprobs=false/logit_bias={}stay 200.- Probe also closed:
audio,web_search_options,prompt_cache_key,background=true,developerrole,prefix=true,weight=0.5.No blocking defect on this tip's claimed honesty slice.
Do not merge this head. It is still a draft; Full unit / Semgrep were queued (org queue), not green; independent non-author APPROVE is still required. Same-automation cannot APPROVE.
Prefer #606 (
3406210) over this head and over #597. #606 keeps this honesty stack and closes the buyer gap this draft still documents:tools/response_format+stream=trueis now an SSE proxy (chat.completion.chunk, content matches non-stream JSON) instead of400 invalid_stream. Do not merge #582–#597 in parallel.Buyer next action on the current tip (#606): send a non-empty
messagesarray of objects; sendstream=truewhen the client reads SSE; omitstream_options.include_usage, batch routing hints,seed,stop,n>1, andlogprobs.CodeRabbit CLI was not available in this environment (
command not found; agent auth has previously timed out here). Verification was live HTTP + source, not a CodeRabbit run.Next distinct gap after #606: KV
provider_egress.allowed_provider_hosts(#598) — do not open another allowlist PR. Then/v1/responsesstreaming (still rejected).Sent by Cursor Automation: Fix Issues
There was a problem hiding this comment.
Stale comment
Do not merge this head over #591
Claimed empty-
messages, attribution/routing, batch-hint reject, and request-knob hoists are real and live-HTTP closed beforeproxy_completionatserver.py3828–3847 (7a07562). That part is a functional superset of #597.Regression vs #591
b7f81a6:_validate_chat_assistant_tool_calls(line 1919) shape-checksid/type/functionand then returns. It does not reject unknown entry or function keys. Live: tools + a valid tool-call history plussmuggle: trueorfunction.extra_hintreturns 200. The same bodies are 400unknown_tool_call_fields/unknown_tool_call_function_fieldson #591. This head also lacks #591's thread-localrequest_sampling.This is not a git ancestor of #591 (
merge-base1a196b0) or #597 (b108251). Preferring this draft over #591 reopens a fail-closed hole a tool-calling SDK can smuggle.Buyer next action: do not merge #596, #591, or #597 in parallel. Port #591's unknown-key +
indexblock into_validate_chat_assistant_tool_callsimmediately after the dict check, and restoretests/test_tool_calls_entry_keys_http_honesty.py. Keep sending onlyid/type/function/ optionalindexon assistanttool_calls.Independent non-author APPROVE + Full unit / Semgrep still required. Do not self-approve.
Sent by Cursor Automation: Fix Issues
There was a problem hiding this comment.
Review (#596 @ 7a07562)
Unique work is sound. Empty/omitted/null/non-list/non-object messages, unknown spend dimensions, routing.channel=batch / latency_tolerant=true, and request knobs (seed, stop, n>1, logprobs, logit_bias, token/penalty ranges, reasoning_effort, service_tier) now fail closed before proxy_completion. Live HTTP on this SHA matches the claimed contract.
Do not merge this head. mergeable_state is blocked. Independent non-author APPROVE + Full unit/Semgrep are still required. Do not merge in parallel with #589–#597 or #601.
Residuals confirmed live on this SHA
- Assistant
tool_callsextra keys still 200.tools[]rejects unknown siblings, buttool_calls[0].smuggleandfunction.extra_hintbilled achat.completionand forwarded the raw object. - Gateway
mode/include_orchestration_tracestill 200.mode=bogus,mode=conduct,include_orchestration_trace="yes", andinclude_orchestration_trace=truebilled a single-agent completion. Passthrough has no workflow or trace plane.
Buyer next action
Prefer #610 (009b75c) for those two residuals: unknown_tool_call_fields plus fail-closed mode=conduct / true-or-non-boolean include_orchestration_trace. On tool-calling requests send tool_calls with only id / type / function / optional index; omit mode=conduct and include_orchestration_trace=true.
#601 still has unique streamed-route temperature work. Cherry-pick that onto #610; do not merge #596, #601, and #610 in parallel.
CodeRabbit CLI was not available in this environment (binary missing). Review is live HTTP + source on 7a07562.
Sent by Cursor Automation: Fix Issues
There was a problem hiding this comment.
Pull request overview
OpenCode cannot approve yet because required coverage evidence did not pass.
Review outcome
1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence
-
Problem: The required coverage-evidence job result was
failure, so OpenCode cannot establish approval sufficiency for this head. -
Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.
-
Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports
successwith required evidence or explicit no-source not-applicable evidence. -
Regression test: Keep the approval branch checking
needs.coverage-evidence.result == successbefore posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present. -
Result: REQUEST_CHANGES
-
Reason: coverage-evidence result was
failure, so required test/docstring evidence was not proven for current head7a075628bb741d79969e49c70535ec8dbd036b3e. -
Head SHA:
7a075628bb741d79969e49c70535ec8dbd036b3e -
Workflow run: 32091419562
-
Workflow attempt: 1
Coverage evidence
Coverage evidence job did not run or did not publish coverage evidence.
Changed-File Evidence Map
flowchart LR
Evidence["OpenCode evidence"] --> Review["Current PR review path"]
Review --> Verify["Required checks"]
OpenCode Review Overview
Pull request overviewOpenCode cannot approve yet because required coverage evidence did not pass. Review outcome1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence
Coverage evidenceCoverage evidence job did not run or did not publish coverage evidence. Changed-File Evidence Mapflowchart LR
Evidence["OpenCode evidence"] --> Review["Current PR review path"]
Review --> Verify["Required checks"]
|


Summary
Honesty-stack merge candidate on top of #592 at
856adb8. This head is a superset of #597's empty-messages + spend/routing hoist and the remaining request-knob fail-open that #597 still lists as residual._validate_messagesbeforeproxy_completion: empty, omitted, null, non-list, and non-objectmessages→invalid_message(same as orchestration). Live HTTP intests/test_chat_messages_array_tools_passthrough_http_honesty.py(RED on fix(api): fail-closed unknown stream_options keys and tools-path message honesty #592)._validate_attribution/_validate_routingbefore proxy. Unknown spend dimensions fail closed.routing.channel=batchandlatency_tolerant=truefail closed (no batch job plane).content(e.g.123) →invalid_message._validate_chat_passthrough_request_knobs:seed,stop,n>1,logprobs,logit_bias, token/penalty ranges,reasoning_effort,service_tier, store/modalities/prediction/metadata/user.tools+stream_options: {include_continuous: null}→ 400invalid_stream_options.Buyer next action: always send a non-empty
messagesarray of objects; send known syncattribution; omit batch routing hints,seed,stop,n>1, andlogprobson tool-calling requests; send user/system content as a non-empty string or content-parts array; send SDK-defaultstream_optionsas omit /null/false.Prefer this head over #582–#587, #589, #591–#594, and draft #597. Do not merge those in parallel. Independent non-author APPROVE + Full unit/Semgrep still required.
Test plan
python3 tests/test_chat_messages_array_tools_passthrough_http_honesty.pypython3 tests/test_passthrough_attribution_routing_http_honesty.pypython3 tests/test_message_honesty_tools_passthrough_http_honesty.pypython3 tests/test_passthrough_stream_model_http_honesty.pypython3 tests/test_openai_passthrough.pyDocs
docs/rest_api_design.mdhonesty contract (APA: OpenAI, 2024).