Skip to content

fix(api): fail-closed tool_calls extra keys and mode/trace on tools path - #610

Closed
cursor[bot] wants to merge 15 commits into
mainfrom
cursor/bc-e79a0774-82b8-4afc-8ac8-e29ea0b87ff2-15d8
Closed

fix(api): fail-closed tool_calls extra keys and mode/trace on tools path#610
cursor[bot] wants to merge 15 commits into
mainfrom
cursor/bc-e79a0774-82b8-4afc-8ac8-e29ea0b87ff2-15d8

Conversation

@cursor

@cursor cursor Bot commented Aug 16, 2026

Copy link
Copy Markdown

Buyer next action

On /v1/chat/completions with tools or response_format, send assistant tool_calls with only id / type / function / optional index. Omit mode=conduct and include_orchestration_trace=true (or send mode=route / include_orchestration_trace=false). Extra tool_calls keys, mode=conduct, unknown modes, and include_orchestration_trace=true / non-boolean values now fail closed instead of billing a silent sync completion.

Why this PR exists

#596 at 7a07562 closed empty/non-object messages, spend keys, batch routing, and request knobs on the tools path. Live HTTP on that head: tools + tool_calls[0].smuggle / function.extra_hint still billed a chat.completion and forwarded the raw object. The same fail-open applied to mode=bogus, mode=conduct, include_orchestration_trace="yes", and include_orchestration_trace=true.

  • Reject unknown tool_calls siblings and function keys (unknown_tool_call_fields) before proxy_completion.
  • _validate_chat_passthrough_gateway_knobs fails closed on conduct / unknown modes and on true / non-boolean include_orchestration_trace.
  • HTTP cases in tests/test_tool_calls_entry_keys_http_honesty.py and tests/test_passthrough_mode_trace_http_honesty.py (RED on fix(api): fail-closed empty messages, spend keys, and request knobs on tools passthrough #596).
  • Docs: docs/rest_api_design.md and README tell buyers the next action (APA: OpenAI, 2024).

Prefer this head over #582#587, #589, #591#597, and #596 for the tool_calls / mode / trace slice. #601 still has unique streamed-route temperature work — cherry-pick that onto this tip; do not merge those heads in parallel. Independent non-author APPROVE + Full unit/Semgrep required. Do not self-approve.

Test plan

  • python3 tests/test_tool_calls_entry_keys_http_honesty.py
  • python3 tests/test_passthrough_mode_trace_http_honesty.py
  • python3 tests/test_chat_assistant_tool_calls_http_honesty.py
  • python3 tests/test_chat_include_orchestration_trace_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_chat_messages_array_tools_passthrough_http_honesty.py
  • python3 tests/test_paper_contracts.py test_self_check.py test_conventions.py test_api_contract.py
  • CI Full unit + Semgrep

Docs

  • docs/rest_api_design.md honesty contract now includes tool_calls extra keys and mode/trace before passthrough.
  • README architecture bullet tells buyers to omit those knobs on tool-calling requests.
Open in Web View Automation 

seonghobae and others added 15 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>
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>
Unknown assistant tool_calls siblings and function keys, plus mode=conduct
and include_orchestration_trace=true, billed a silent chat.completion on
the tools proxy. Reject them with the same named errors as orchestration.

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.

@seonghobae
seonghobae enabled auto-merge (squash) August 16, 2026 15:59

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

Buyer next action

Do not merge #610. Keep using #617 (a1823cc) as the honesty landing vehicle (SSE tools + mock tool_calls + extra tool_calls keys). Cherry-pick only the remaining fail-closed slice onto that tip: mode=conduct and include_orchestration_trace=true must 400 on tools / response_format instead of billing a silent single-agent completion.

What this head actually adds

Unique commit 009b75c (5 files, +456) is real and locally green:

  • python3 tests/test_tool_calls_entry_keys_http_honesty.pyok
  • python3 tests/test_passthrough_mode_trace_http_honesty.pyok

Compared to the current tip:

Slice #610 009b75c #617 a1823cc
Unknown tool_calls siblings / function keys fail-closed already landed (and splits unknown_tool_call_function_fields, checks extras before name)
mode=bogus / non-boolean trace fail-closed already landed via _validate_request_mode_if_present / _validate_include_orchestration_trace_flag
mode=conduct on tools / response_format 400 invalid_mode still bills — helper accepts conduct
include_orchestration_trace=true on that path 400 still bills — helper returns True and the call site discards it
stream=true + tools 400 invalid_stream (regresses SSE) SSE-proxied

#613 (37f1224) already has the conduct/trace hoist on the older #601 substrate. Prefer that unique function over merging this 146-file parallel stack.

Do not land from here

Merging #610 would race #617 and re-break SSE tool-calling (stream=true still fail-closed on this stack). Independent non-author APPROVE + Full unit/Semgrep are still required on the landing vehicle. This automation will not self-approve or merge #610.

Preserve #610’s all-keys loop when cherry-picking: orchestration=route plus mode=conduct must still 400. #617’s or chain would keep route and hide conduct.

Open in Web View Automation 

Sent by Cursor Automation: Fix Issues

Comment on lines +1714 to +1758
def _validate_chat_passthrough_gateway_knobs(body: dict[str, Any]) -> None:
"""Fail-closed gateway knobs that otherwise run only after tools proxy.

``mode`` / ``orchestration`` / ``orchestration_mode`` and
``include_orchestration_trace`` are applied only on the orchestration
path. Tools / ``response_format`` proxy is single-agent and strips those
keys, so a billed ``chat.completion`` would hide that conduct/trace never
ran. ``auto`` and ``route`` are honest (passthrough is the route).
``conduct``, unknown modes, non-boolean trace, and ``trace=true`` fail
closed with the same named errors as orchestration.
"""
for key in ("orchestration", "orchestration_mode", "mode"):
if key not in body:
continue
raw_mode = body.get(key)
if raw_mode is None or (isinstance(raw_mode, str) and not raw_mode.strip()):
continue
mode = _validate_mode(raw_mode)
if mode == "conduct":
raise RequestError(
400,
"invalid_mode",
"mode=conduct is not supported with tools or response_format; "
"omit mode or set mode=route",
)
if "include_orchestration_trace" not in body:
return
include_trace_raw = body.get("include_orchestration_trace")
if include_trace_raw is None or (
isinstance(include_trace_raw, str) and not include_trace_raw.strip()
):
return
if not isinstance(include_trace_raw, bool):
raise RequestError(
400,
"invalid_include_orchestration_trace",
"include_orchestration_trace must be a boolean",
)
if include_trace_raw is True:
raise RequestError(
400,
"invalid_include_orchestration_trace",
"include_orchestration_trace=true is not supported with tools or "
"response_format; omit it or set false",
)

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.

This is the only slice still missing on #617. _validate_request_mode_if_present / _validate_include_orchestration_trace_flag already run before proxy_completion there, but they accept conduct and include_orchestration_trace=true and the call site drops the return value — so a tools body still bills a chat.completion with no workflow and no trace.

Cherry-pick this hoist onto #617. Keep the per-key loop (do not collapse to orchestration or orchestration_mode or mode) so a mixed mode=conduct + orchestration=route body cannot hide conduct. Do not merge this stack: it still 400s stream=true with tools.

Comment on lines +2037 to +2044
unknown_fn = sorted(set(function) - {"name", "arguments"})
if unknown_fn:
raise RequestError(
400,
"unknown_tool_call_fields",
"each tool_calls function accepts only name and arguments",
{"fields": unknown_fn},
)

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.

Already on #617, and that tip is stricter: it rejects extra function keys before name / arguments and uses unknown_tool_call_function_fields. Here {extra_hint: ...} without a valid name reports invalid_message instead of the smuggle error. Do not land this copy; keep #617’s taxonomy.

@opencode-agent
opencode-agent Bot disabled auto-merge August 16, 2026 17:46
@seonghobae
seonghobae enabled auto-merge (squash) August 16, 2026 20:00
@opencode-agent
opencode-agent Bot disabled auto-merge August 17, 2026 02:23
@seonghobae
seonghobae enabled auto-merge (squash) August 17, 2026 07:04
@opencode-agent
opencode-agent Bot disabled auto-merge August 17, 2026 07:50

@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 009b75cca5a2135c1e7ee5b2643aa2a58c6487c7.

  • Head SHA: 009b75cca5a2135c1e7ee5b2643aa2a58c6487c7

  • Workflow run: 32138273762

  • 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 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: 009b75cca5a2135c1e7ee5b2643aa2a58c6487c7
  • Workflow run: 32148129751
  • 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 009b75cca5a2135c1e7ee5b2643aa2a58c6487c7.

  • Head SHA: 009b75cca5a2135c1e7ee5b2643aa2a58c6487c7

  • Workflow run: 32148129751

  • 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 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 009b75cca5a2135c1e7ee5b2643aa2a58c6487c7.

  • Head SHA: 009b75cca5a2135c1e7ee5b2643aa2a58c6487c7

  • Workflow run: 32148129751

  • 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

@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