Skip to content

fix: remove public chat-to-responses auto conversion - #5364

Closed
QLHazyCoder wants to merge 2 commits into
QuantumNous:mainfrom
QLHazyCoder:codex/upstream-disable-chat-responses
Closed

fix: remove public chat-to-responses auto conversion#5364
QLHazyCoder wants to merge 2 commits into
QuantumNous:mainfrom
QLHazyCoder:codex/upstream-disable-chat-responses

Conversation

@QLHazyCoder

@QLHazyCoder QLHazyCoder commented Jun 7, 2026

Copy link
Copy Markdown

Summary

This PR removes the public Chat/Claude endpoint auto-conversion path that silently rewrote chat-completions requests into Responses requests and then wrapped the Responses stream back into Chat Completions chunks.

The public endpoint should preserve its protocol semantics:

  • /v1/chat/completions and Claude-compatible public entries should stay on their native relay path.
  • /v1/responses should stay on the native Responses relay path.
  • Hidden chat -> responses -> chat conversion should not alter the stream protocol visible to clients.

Root Cause

The issue was not the native /v1/responses route. The native Responses route emits Responses stream events correctly.

The problematic chain was:

  1. public /v1/chat/completions or Claude-compatible entry
  2. global.chat_completions_to_responses_policy matched
  3. request was internally rewritten to /v1/responses
  4. upstream Responses stream was wrapped back with Chat Completions stream helpers
  5. clients expecting Responses semantics could observe chat.completion.chunk objects from the hidden compatibility layer

That means the public API endpoint semantics could be pierced by a hidden compatibility setting.

What Changed

  • Removed runtime public-entry calls to chatCompletionsViaResponses from the OpenAI-compatible and Claude-compatible relay handlers.
  • Kept a compatibility helper only as an explicitly disabled legacy path.
  • Simplified the global model setting UI so this conversion is no longer configurable from the public settings page.
  • Added regression tests around the disabled policy behavior and legacy helper response.

Note for Maintainers

这确实是服务端逻辑错误,不是客户端“挑剔”。

/v1/responses 原生链路本身没错。

真正的问题就是公开 chat/Claude 入口被隐藏逻辑偷偷改成 responses,再包装回 chat,导致协议语义被打穿。

现在这条自动转换链已经从根上停掉了。

hurry 那个 completion_tokens=0 / 空输出问题我没有碰,仍然应该单独分析。

Validation

go test ./service/openaicompat ./relay

Summary by CodeRabbit

  • Breaking Changes

    • Automatic chat/completions → responses protocol conversion is removed; public endpoints now reject conversion attempts with a 400 Bad Request. Conversion retained only for backward-compatible config storage.
  • Tests

    • Added tests verifying the disabled conversion and policy behavior.
  • UI Updates

    • Settings UI reflects the deprecated feature, simplified input, and a "Format JSON" helper.
  • Localization

    • Added updated explanatory strings in multiple languages.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6656041-705b-4054-b982-d276f77fd153

📥 Commits

Reviewing files that changed from the base of the PR and between 6839d7c and a088d51.

📒 Files selected for processing (1)
  • relay/chat_completions_via_responses_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • relay/chat_completions_via_responses_test.go

Walkthrough

This PR removes the automatic Chat Completions → Responses protocol conversion: the conversion endpoint now returns 400 Bad Request, the policy is hardcoded to false, alternate handler routing is removed, config is annotated as deprecated for backward-compatible storage, and frontend UIs/translations are updated to reflect the disabled legacy state.

Changes

Chat Completions → Responses Conversion Removal

Layer / File(s) Summary
Policy disabling and endpoint error response
service/openaicompat/policy.go, relay/chat_completions_via_responses.go, relay/chat_completions_via_responses_test.go, service/openaicompat/policy_test.go
ShouldChatCompletionsUseResponsesPolicy always returns false; chatCompletionsViaResponses now immediately returns HTTP 400 Bad Request. New tests verify the disabled policy and endpoint behaviors.
Removal of alternate handler routing paths
relay/claude_handler.go, relay/compatible_handler.go
Claude and compatible handlers no longer route requests through chatCompletionsViaResponses; they always follow the standard adaptor request/response flow.
Configuration backward compatibility documentation
setting/model_setting/global.go
GlobalSettings gains deprecation/backward-compatibility comments indicating the stored conversion policy is legacy-only and not used at runtime for public endpoints.
Frontend UI updates (classic + default)
web/classic/src/pages/Setting/Model/SettingGlobalModel.jsx, web/default/src/features/system-settings/models/global-settings-card.tsx
UI sections now show the feature as disabled/legacy, remove inline example JSON templates, change labels/placeholders to "Legacy Format (JSON Object)" with {} placeholder, and replace template-fill buttons with a JSON formatter button.
Internationalization strings
web/default/src/i18n/locales/en.json, web/default/src/i18n/locales/fr.json, web/default/src/i18n/locales/ja.json, web/default/src/i18n/locales/ru.json, web/default/src/i18n/locales/vi.json, web/default/src/i18n/locales/zh.json
Add translation entries explaining that automatic public-endpoint protocol conversion has been removed and is retained only for backward-compatible storage.

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

  • QuantumNous/new-api#2889: Introduced Claude → chatCompletionsViaResponses routing that this PR removes.
  • QuantumNous/new-api#2643: Modified the same SettingGlobalModel.jsx UI and JSON formatting behavior related to chat_completions_to_responses_policy.
  • QuantumNous/new-api#2629: Previously added the chat/completions → responses conversion pathway that is now disabled.

Suggested Reviewers

  • Calcium-Ion
  • seefs001

Poem

🐰 Gone the old conversion path today,
I nibbled code and chased a stray array.
Legacy kept for dreams of yesterday,
Public endpoints now march their own way.
Hooray for simpler routing — hop hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: remove public chat-to-responses auto conversion' accurately describes the main objective of the changeset—disabling the automatic conversion from chat completions to responses protocol on public endpoints.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@relay/chat_completions_via_responses_test.go`:
- Around line 15-18: The test TestChatCompletionsViaResponsesDisabled calls
gin.SetMode(gin.TestMode) which mutates global Gin state and is not restored;
capture the current mode before changing it (via gin.Mode()), set gin to
gin.TestMode for the test, and ensure you restore the previous mode at the end
of the test (use a defer to call gin.SetMode(prevMode)) so
TestChatCompletionsViaResponsesDisabled leaves global Gin state unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f7cf43c-1272-4172-8b6b-b0e7fe820367

📥 Commits

Reviewing files that changed from the base of the PR and between 4ca47ee and 6839d7c.

📒 Files selected for processing (15)
  • relay/chat_completions_via_responses.go
  • relay/chat_completions_via_responses_test.go
  • relay/claude_handler.go
  • relay/compatible_handler.go
  • service/openaicompat/policy.go
  • service/openaicompat/policy_test.go
  • setting/model_setting/global.go
  • web/classic/src/pages/Setting/Model/SettingGlobalModel.jsx
  • web/default/src/features/system-settings/models/global-settings-card.tsx
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
💤 Files with no reviewable changes (2)
  • relay/claude_handler.go
  • relay/compatible_handler.go

Comment thread relay/chat_completions_via_responses_test.go
@seefs001 seefs001 closed this Jun 8, 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