Repository navigation
fix(gateway): enforce OpenAI tool_choice required/function contracts - #88558
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed May 31, 2026, 9:52 AM ET / 13:52 UTC. Summary PR surface: Source +215, Tests +450, Docs +7. Total +672 across 10 files. Reproducibility: yes. Source inspection of the PR head shows both constrained streaming paths append deltas to unbounded strings until the run resolves, and current main still lacks the requested Chat enforcement. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Land a refreshed, focused Gateway PR only after constrained streaming is bounded, Do we have a high-confidence way to reproduce the issue? Yes. Source inspection of the PR head shows both constrained streaming paths append deltas to unbounded strings until the run resolves, and current main still lacks the requested Chat enforcement. Is this the best way to solve the issue? No. The compatibility direction is sound, but the proposed implementation should bound constrained streaming and prove live Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 0d17623f0090. Label changesLabel justifications:
Evidence reviewedPR surface: Source +215, Tests +450, Docs +7. Total +672 across 10 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
f8a3570 to
aa2e519
Compare
|
The post-run enforcement makes sense, and buffering assistant prose until the structured tool call is confirmed is the right direction for API compatibility. One follow-up question: should the buffered commentary have a size cap on the streaming path? If an upstream model ignores the tool-choice prompt and emits a lot of prose before ending, |
1165a66 to
aabdc63
Compare
f87c4c6 to
79fa094
Compare
|
Proof for final head
Known gap: no live external OpenAI/Gemini provider call was run; coverage is repo HTTP compatibility/unit regression coverage plus full exact-head CI. |
Summary
tool_choice: "required"and pinned function tool choice in/v1/chat/completions./v1/responses, including the Responses API flat pinned shape{ "type": "function", "name": "..." }.tool_choiceforms.Refs #45049.
Verification
node scripts/run-vitest.mjs src/gateway/openai-http.test.ts -t "handles request validation and routing|streams SSE chunks" --reporter=verbose- passed; 4 focused Gateway HTTP e2e cases acrossgateway-serverandgateway-client.node scripts/run-vitest.mjs src/gateway/openai-http.test.ts- passed; 18/18 tests.node scripts/run-vitest.mjs src/gateway/openresponses-http.test.ts src/gateway/openai-http.test.ts- passed; 43/43 tests covering Chat Completions plus Responses required/pinned tool-choice success and failure paths.pnpm docs:list- passed;docs/gateway/openresponses-http-api.mdwas the relevant docs page.git diff --check- passed..agents/skills/autoreview/scripts/autoreview --mode local --engine codex- clean; no accepted/actionable findings after addressing two review findings.Real behavior proof
Behavior addressed: OpenAI-compatible Gateway HTTP requests now accept standard Chat Completions and Responses
tool_choice: "required"and pinned function tool choice, return structured tool calls when the model complies, and reject invalid or unsatisfied tool-choice contracts instead of silently returning ordinary assistant text.Real environment tested: Local Gateway HTTP server started from this checkout via
startGatewayServer, loopback port18812,auth: none,gateway.http.endpoints.chatCompletions.enabled=true, modeldeepseek/deepseek-chat, provider base URLhttps://api.deepseek.com, and a temporary DeepSeek API key supplied only through the process environment. Responses behavior was also tested through the repo Gateway HTTP e2e harness with the real/v1/responsesHTTP handler and mocked agent results for deterministic required/pinned success and failure paths.Exact steps or command run after this patch: Started the Gateway in-process from the current checkout, then posted four local requests to
/v1/chat/completions: onetool_choice: "required"request with aget_weatherfunction tool, one pinned function request forget_weather, onetool_choice: "required"request without tools, and one pinned function request for a missing tool. After adding/v1/responsesenforcement, rannode scripts/run-vitest.mjs src/gateway/openresponses-http.test.ts src/gateway/openai-http.test.tsto exercise Responses non-streaming and streaming required/pinned tool-choice success and failure cases through the HTTP endpoint.Evidence after fix:
{ "ok": true, "modelRef": "deepseek/deepseek-chat", "chatCompletionsLiveResults": [ { "label": "required", "httpStatus": 200, "finishReason": "tool_calls", "toolCallCount": 1, "toolNames": ["get_weather"], "contentPreview": "" }, { "label": "pinned_function", "httpStatus": 200, "finishReason": "tool_calls", "toolCallCount": 1, "toolNames": ["get_weather"], "contentPreview": "" }, { "label": "required_no_tools", "httpStatus": 400, "errorType": "invalid_request_error", "errorMessage": "Invalid tools/tool_choice: tool_choice=required but no tools were provided" }, { "label": "missing_tool", "httpStatus": 400, "errorType": "invalid_request_error", "errorMessage": "Invalid tools/tool_choice: tool_choice requested unknown tool: missing_tool" } ], "responsesFocusedTests": { "command": "node scripts/run-vitest.mjs src/gateway/openresponses-http.test.ts src/gateway/openai-http.test.ts", "testFiles": 2, "tests": 43, "result": "passed" } }Observed result after fix: The valid Chat Completions
requiredand pinned-function requests completed through the real local Gateway and live DeepSeek provider withfinish_reason: "tool_calls"and a singleget_weatherstructured tool call. Invalid Chat Completions tool-choice requests were rejected at the Gateway boundary with deterministic OpenAI-compatible400 invalid_request_errorresponses. Responses HTTP e2e tests now prove non-streaming unsatisfiedtool_choicereturns a failed502 api_error, streaming unsatisfiedtool_choiceemitsresponse.failedwithout leaking buffered text, and satisfied required/pinned turns return or stream the matchingfunction_calloutput.What was not tested: Crabbox/Testbox and cross-OS proof were not run. The live provider proof used DeepSeek rather than OpenAI because the reported compatibility gap is OpenAI-compatible tool-choice protocol behavior and DeepSeek exposes an OpenAI-compatible Chat Completions API for this flow.
/v1/responseswas verified with deterministic local Gateway HTTP e2e tests rather than a live external Responses provider.