Skip to content

fix(api): fail-closed empty messages, spend keys, and request knobs on tools passthrough - #596

Closed
cursor[bot] wants to merge 14 commits into
mainfrom
cursor/bc-ca19a537-3b53-42fc-83e4-bbb9baed8cc7-ae07
Closed

fix(api): fail-closed empty messages, spend keys, and request knobs on tools passthrough#596
cursor[bot] wants to merge 14 commits into
mainfrom
cursor/bc-ca19a537-3b53-42fc-83e4-bbb9baed8cc7-ae07

Conversation

@cursor

@cursor cursor Bot commented Aug 16, 2026

Copy link
Copy Markdown

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_messages before proxy_completion: empty, omitted, null, non-list, and non-object messagesinvalid_message (same as orchestration). Live HTTP in tests/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_routing before proxy. Unknown spend dimensions fail closed. routing.channel=batch and latency_tolerant=true fail closed (no batch job plane).
  • Non-string user 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} → 400 invalid_stream_options.

Buyer next action: always send a non-empty messages array of objects; send known sync attribution; omit batch routing hints, seed, stop, n>1, and logprobs on tool-calling requests; send user/system content as a non-empty string or content-parts array; send SDK-default stream_options as 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.py
  • python3 tests/test_passthrough_attribution_routing_http_honesty.py
  • python3 tests/test_message_honesty_tools_passthrough_http_honesty.py
  • python3 tests/test_passthrough_stream_model_http_honesty.py
  • python3 tests/test_openai_passthrough.py
  • CI Full unit + Semgrep

Docs

  • docs/rest_api_design.md honesty contract (APA: OpenAI, 2024).
  • README architecture bullet matches.

seonghobae and others added 10 commits August 16, 2026 21:18
…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>
@cursor
cursor Bot requested a review from seonghobae August 16, 2026 15:31
cursoragent and others added 2 commits August 16, 2026 15:31
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>
@seonghobae seonghobae changed the title fix(api): fail-closed attribution and routing on tools passthrough fix(api): fail-closed attribution, routing, and request knobs on tools passthrough Aug 16, 2026
@seonghobae seonghobae changed the title fix(api): fail-closed attribution, routing, and request knobs on tools passthrough fix(api): fail-closed empty messages, spend keys, and request knobs on tools passthrough Aug 16, 2026
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>
@cursor

cursor Bot commented Aug 16, 2026

Copy link
Copy Markdown
Author

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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Stale comment

Review (#596 @ 7a07562)

Live HTTP on this head confirms the unique work is real:

  • _validate_messages before proxy_completiontools + [] / omitted / null / non-list / non-object → 400 invalid_message (not a billed completion with prompt_tokens: 0, not 500).
  • Attribution / routing hoist — unknown spend keys, routing.channel=batch, and latency_tolerant=true400.
  • _validate_chat_passthrough_request_knobsseed, stop, n>1, logprobs, logit_bias, out-of-range penalties, store=true, non-string user, unsupported reasoning_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, developer role, 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=true is now an SSE proxy (chat.completion.chunk, content matches non-stream JSON) instead of 400 invalid_stream. Do not merge #582#597 in parallel.

Buyer next action on the current tip (#606): send a non-empty messages array of objects; send stream=true when the client reads SSE; omit stream_options.include_usage, batch routing hints, seed, stop, n>1, and logprobs.

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/responses streaming (still rejected).

View PR

Open in Web View Automation 

Sent by Cursor Automation: Fix Issues

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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 before proxy_completion at server.py 3828–3847 (7a07562). That part is a functional superset of #597.

Regression vs #591 b7f81a6: _validate_chat_assistant_tool_calls (line 1919) shape-checks id / type / function and then returns. It does not reject unknown entry or function keys. Live: tools + a valid tool-call history plus smuggle: true or function.extra_hint returns 200. The same bodies are 400 unknown_tool_call_fields / unknown_tool_call_function_fields on #591. This head also lacks #591's thread-local request_sampling.

This is not a git ancestor of #591 (merge-base 1a196b0) 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 + index block into _validate_chat_assistant_tool_calls immediately after the dict check, and restore tests/test_tool_calls_entry_keys_http_honesty.py. Keep sending only id / type / function / optional index on assistant tool_calls.

Independent non-author APPROVE + Full unit / Semgrep still required. Do not self-approve.

Open in Web View Automation 

Sent by Cursor Automation: Fix Issues

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

  1. Assistant tool_calls extra keys still 200. tools[] rejects unknown siblings, but tool_calls[0].smuggle and function.extra_hint billed a chat.completion and forwarded the raw object.
  2. Gateway mode / include_orchestration_trace still 200. mode=bogus, mode=conduct, include_orchestration_trace="yes", and include_orchestration_trace=true billed 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.

View PR

Open in Web View Automation 

Sent by Cursor Automation: Fix Issues

@opencode-agent opencode-agent 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.

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 success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before 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 head 7a075628bb741d79969e49c70535ec8dbd036b3e.

  • 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"]
Loading

@opencode-agent

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: 7a075628bb741d79969e49c70535ec8dbd036b3e
  • Workflow run: 32091419562
  • Workflow attempt: 1
  • Gate result: REQUEST_CHANGES (approval step)

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 success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before 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 head 7a075628bb741d79969e49c70535ec8dbd036b3e.

  • 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"]
Loading

@opencode-agent
opencode-agent Bot disabled auto-merge August 18, 2026 03:20
@seonghobae seonghobae closed this Aug 20, 2026
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