Skip to content

fix(api): fail-closed conduct and trusted-trace on tools passthrough - #624

Closed
cursor[bot] wants to merge 28 commits into
mainfrom
cursor/bc-ea84b878-f9a0-42c8-8956-f1fb108e38b2-8e88
Closed

fix(api): fail-closed conduct and trusted-trace on tools passthrough#624
cursor[bot] wants to merge 28 commits into
mainfrom
cursor/bc-ea84b878-f9a0-42c8-8956-f1fb108e38b2-8e88

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 (including stream=true), omit mode=conduct and include_orchestration_trace=true, or send mode=route / include_orchestration_trace=false. Those knobs now fail closed instead of billing a silent single-agent completion with no Conductor workflow and no TRINITY trusted-trace plane.

Why this PR exists

#617 at a1823cc already type-checks unknown mode and non-boolean include_orchestration_trace before the tools / response_format proxy. Live HTTP on that head: tools + mode=conduct and tools + include_orchestration_trace=true still billed a chat.completion. The same fail-open applied to mixed orchestration=route + mode=conduct (the or chain hid conduct) and to stream=true.

  • _validate_chat_passthrough_orchestration_controls fails closed on conduct / unknown modes and on true / non-boolean include_orchestration_trace.
  • Each of orchestration / orchestration_mode / mode is checked on its own so a mixed route+conduct body cannot hide conduct.
  • HTTP cases in tests/test_passthrough_mode_trace_http_honesty.py (RED on fix(api): mock SSE tool_calls and streamed sampling knobs #617), including SSE tools and response_format.
  • Docs: docs/rest_api_design.md, docs/architecture.md, docs/papers/README.md, README, CHANGELOG (APA: Nielsen et al., 2025; Xu et al., 2025; OpenAI, 2024).

Prefer this head over #610 and #613 for the conduct/trace slice. #617 remains the SSE + tool_calls extra-keys substrate — this commit sits on a1823cc. Do not merge #610 / #613 / #601 in parallel. Independent non-author APPROVE + Full unit/Semgrep required. Do not self-approve.

Test plan

  • python3 tests/test_passthrough_mode_trace_http_honesty.py
  • python3 tests/test_tool_calls_entry_keys_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

  • Honesty contract now tells buyers to omit mode=conduct and include_orchestration_trace=true on tool-calling requests.
  • CHANGELOG Unreleased no longer tells buyers to send conduct on the tools path.
Open in Web View Automation 

seonghobae and others added 28 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 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>
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>
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>
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 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>
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>
OpenAI SDK tool callers send stream=true. Returning 400 was honest but
left every streaming tool client failing. Pipe a single pool agent as
chat.completion.chunk frames so concatenated mock content matches the
non-stream JSON body, and pipe live provider text so tool_calls deltas
survive. Keep include_usage, empty messages, and unsupported knobs
fail-closed.

Buyer next action: send stream=true on tool-calling requests; omit
stream_options.include_usage.

Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Keep tools/response_format SSE proxy from this branch and take #601's
null tool.function omit-pop, request-knob HTTP cases, and streamed
route temperature. Conflict resolution keeps stream=true as SSE, not
400. CHANGELOG records the combined unreleased slice.

Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Unknown assistant tool_calls entry/function fields, non-boolean
include_orchestration_trace, and unknown mode used to bill a JSON or SSE
completion on the tools proxy. They now return the same named 400s as the
orchestration path before the first byte.

Buyer next action: send only id/type/function/optional index on assistant
tool_calls; send a boolean or omit include_orchestration_trace; send
auto/route/conduct or omit mode.

Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
mock:// lookup_balance now returns assistant tool_calls and streams
delta.tool_calls with finish_reason=tool_calls so offline SDK clients
match the live _stream_raw path. Invoice identifiers bind from the
user text (default INV-9).

Buyer next action: send stream=true on tool-calling requests and include
the invoice id in the user message.

Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
stream_chat recorded temperature but omitted the request-scoped top_p,
presence_penalty, and frequency_penalty that chat() already forwards.
A streamed invoice summary at top_p=0.1 no longer drops those knobs.

Buyer next action: send the nucleus and penalty values you want on
stream=true route requests; streaming matches the JSON path.

Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
Tools / response_format proxy is the route hop. mode=conduct and
include_orchestration_trace=true billed a silent chat.completion with no
Conductor workflow and no TRINITY trace. Reject them with the same named
errors as orchestration, including mixed orchestration=route + mode=conduct
and the SSE tools path.

Co-authored-by: Seongho Bae <seonghobae@users.noreply.github.com>
@seonghobae
seonghobae marked this pull request as ready for review August 16, 2026 16:11
@seonghobae
seonghobae enabled auto-merge (squash) August 16, 2026 16:11
@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.

Buyer next action

Do not merge #624. Do not send include_orchestration_trace=true or mode as spaces on tool-calling requests. Take the successor #640 (d898045 on this tip) for the parent-test flip and whitespace-only mode.

Verdict: NEEDS_SUCCESSOR

The unique helper does what the commit claims for conduct and include_orchestration_trace=true. Each of orchestration / orchestration_mode / mode is checked on its own, so mixed orchestration=route + mode=conduct cannot hide conduct. Live probes on 13ced1e for orchestration=conduct, SSE+trace=true, and response_format+conduct already 400.

The unique commit is still not mergeable: the #617 parent test still requires billed success for include_orchestration_trace=true, so Full unit is red. Tools + mode: " " still bills a chat.completion (orchestration treats whitespace-only mode as truthy invalid_mode).

What #640 changes

  • Flips test_http_tools_accepts_include_orchestration_trace_boolean_and_null so True is 400; False / None stay 200.
  • Adds HTTP cases for orchestration=conduct, orchestration_mode=conduct, SSE+trace=true, response_format+mode=conduct, and whitespace-only mode.
  • Keeps per-key checks. Do not take #629 instead — that head collapses aliases back into the or chain and sits on #613, not this SSE tip.

Independent non-author APPROVE + Full unit/Semgrep required. Do not self-approve. Do not merge #610 / #613 / #617 / #629 in parallel with this stack.

Open in Web View Automation 

Sent by Cursor Automation: Fix Issues

port,
_tools_payload(include_orchestration_trace=value),
)
assert status == 200, (value, body)

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 #617 parent case still loops (True, False, None) and asserts 200. The unique helper now 400s include_orchestration_trace=true (invalid_include_orchestration_trace), so Full unit on this head is red.

Successor #640 splits the case: True → 400; False / None stay billed no-ops.

Comment on lines +1254 to +1255
if raw_mode is None or (isinstance(raw_mode, str) and not raw_mode.strip()):
continue

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.

not raw_mode.strip() treats whitespace-only mode as omit. The orchestration or chain does not: mode: " " without tools is 400 invalid_mode because " " is truthy and not in ALLOWED_MODES.

Live on this head: tools + mode: " " bills a chat.completion. Successor #640 fails that closed while keeping the per-key loop (do not collapse back to the or chain — that would hide mode=conduct behind orchestration=route). JSON "" stays omit-equivalent.

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

  • Head SHA: 13ced1e86e2f91e661245e7a124c4b0b76dc832d

  • Workflow run: 32138309953

  • 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: 13ced1e86e2f91e661245e7a124c4b0b76dc832d
  • Workflow run: 32148175015
  • 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 13ced1e86e2f91e661245e7a124c4b0b76dc832d.

  • Head SHA: 13ced1e86e2f91e661245e7a124c4b0b76dc832d

  • Workflow run: 32148175015

  • 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 13ced1e86e2f91e661245e7a124c4b0b76dc832d.

  • Head SHA: 13ced1e86e2f91e661245e7a124c4b0b76dc832d

  • Workflow run: 32148175015

  • 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