fix(api): apply request top_p and penalties on streamed route - #615
fix(api): apply request top_p and penalties on streamed route#615cursor[bot] wants to merge 17 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>
Call the orchestration message, max_tokens, attribution, and routing validators before proxy_completion so a tools or response_format body cannot bill a completion with no prompt, crash on a non-object entry, or silently drop unknown spend/routing keys. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Passthrough has no batch job plane. Reject routing.channel=batch and latency_tolerant=true before proxy_completion so a tool-calling body cannot bill a silent sync completion. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Hoist the orchestration request-knob validators before proxy_completion so a tools or response_format body cannot bill a completion that silently drops seed, stop, n>1, logprobs, logit_bias, or out-of-range penalties. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
stream_chat defaulted to 0.2 even after the HTTP path wrote default_temperature from the request. A streamed invoice summary at temperature=0.8 no longer silently falls back to 0.2. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
… proxy SDK optional defaults serialize omitted fields as JSON null. Accepting those keys without popping them is not omit-equivalent: proxy_completion forwards the body and several providers reject a null JSON Schema object. Pop the keys in place, keep non-null wrong types on invalid_tools, and assert omit-real via mock echo on chat and Responses. Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
stream_chat honored default_temperature after 18e6263 but still dropped default_top_p, presence_penalty, and frequency_penalty. A streamed invoice summary at top_p=0.1 billed a completion that ignored nucleus sampling. 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.
Assessment (unique 7e9a339..18537ef)
Unique work matches the claimed buyer contract. A streamed mode=route invoice body with top_p=0.1, presence_penalty=0.5, and frequency_penalty=-0.25 now copies those request-scoped defaults in stream_chat the same way chat() does, and records last_* for honesty probes. Local tests/test_stream_chat_request_nucleus_penalties_http_honesty.py and the temperature sister script printed ok.
No critical, high, or medium defects on the unique slice. Holtzman et al. (2020) is cited APA 7th with the OA PDF. No new request-time env reads.
Buyer next action: send the top_p and penalty values you want on streamed route bodies; they are applied, not dropped. Still omit seed, stop, n>1, and logprobs on tool-calling requests.
Landing: prefer this head over merging #601 alone for the stream-sampling residual. Do not merge #589, #592, #594–#597, #599, #600, or #603-as-stack in parallel. KV allowlist landing remains #611. SSE tools landing remains #620. Mode/trace hoist remains #613/#624. Do not open another stream-nucleus PR.
Merge gate still open: independent non-author APPROVE plus Full unit / Semgrep / Security job results. This review is COMMENT only.
Residual (not blocking): the provider-payload assignments sit behind # pragma: no cover because both new tests use mock:// and assert last_*. Same pattern as chat() and the #601 temperature probe.
Sent by Cursor Automation: Fix Issues
| "stream": True, | ||
| "max_tokens": self.max_output_tokens, | ||
| } | ||
| if effective_top_p is not None: # pragma: no cover |
There was a problem hiding this comment.
Residual, not blocking: these three assignments are the actual provider-payload contract, but they sit behind # pragma: no cover because both new tests take the mock:// early return and assert last_* only. A later mutation can keep last_top_p and drop payload["top_p"] and still pass. Optional follow-up on a later head: stub _stream_send (or a non-mock agent) and assert the JSON body contains top_p / the two penalties. Do not open another stream-nucleus PR just for this.
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 head18537efb323fcac15c0be2dbc1904544f425be93. -
Head SHA:
18537efb323fcac15c0be2dbc1904544f425be93 -
Workflow run: 32138285985
-
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"]
|
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 head18537efb323fcac15c0be2dbc1904544f425be93. -
Head SHA:
18537efb323fcac15c0be2dbc1904544f425be93 -
Workflow run: 32148145015
-
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"]


Summary
Successor to #601 at
7e9a339. Keeps that head's fail-closed seed/stop/n/logprobs hoist, streamed request temperature, and omit-real tool.function nulls.#601 closed the temperature drop on
stream_chat. Live HTTP on that head: a streamed route body withtop_p=0.1,presence_penalty=0.5, andfrequency_penalty=-0.25still billed SSE whilestream_chatrecorded only temperature.chat()already copies those request-scoped defaults into the provider payload; the stream path did not.ModelClient.stream_chatcopiesdefault_top_p,default_presence_penalty, anddefault_frequency_penaltythe same waychat()does, and recordslast_*for honesty probes.tests/test_stream_chat_request_nucleus_penalties_http_honesty.py(RED on fix(api): fail-closed seed/stop/n/logprobs on tools passthrough #601: last_top_p stayed unset).docs/rest_api_design.md,docs/architecture.md, CHANGELOG. Grounding: Holtzman et al. (2020) nucleus sampling (OA PDF underdocs/papers/nucleus-sampling-1904.09751.pdf) and OpenAI (2024).Buyer next action: send the
top_pand penalty values you want on streamed route bodies; they are applied, not dropped. Still omitseed,stop,n>1, andlogprobson tool-calling requests.Prefer this head over merging #601 alone for the stream-sampling residual. Do not merge #589, #592, #594, #595, #596, #597, #599, #600, or #603-as-stack in parallel. KV allowlist landing remains #611 — do not open another allowlist PR. Independent non-author APPROVE + Full unit/Semgrep still required.
Test plan
python3 tests/test_stream_chat_request_nucleus_penalties_http_honesty.py(watched RED, then GREEN)python3 tests/test_stream_chat_request_sampling_http_honesty.pypython3 tests/test_passthrough_request_knobs_http_honesty.pypython3 tests/test_true_streaming.pypython3 tests/test_paper_contracts.pytest_self_check.pytest_conventions.pytest_api_contract.pyDocs
docs/rest_api_design.mdhonesty contract now includes streamedtop_p/ penalties.stream=trueroute bodies.docs/papers/README.mdcites Holtzman et al. (2020) APA 7th with the OA PDF.References