Skip to content

fix: normalize model name in TranslateRequest fallback to prevent prefix leak#2220

Merged
luispater merged 2 commits intorouter-for-me:devfrom
xulongwu4:main
Mar 23, 2026
Merged

fix: normalize model name in TranslateRequest fallback to prevent prefix leak#2220
luispater merged 2 commits intorouter-for-me:devfrom
xulongwu4:main

Conversation

@xulongwu4
Copy link
Copy Markdown
Contributor

@xulongwu4 xulongwu4 commented Mar 18, 2026

When no request translator is registered for a format pair (e.g. openai-response → openai-response), TranslateRequest returned the raw payload unchanged. This caused client-side model prefixes (e.g. "copilot/gpt-5-mini") to leak into upstream requests, resulting in "The requested model is not supported" errors from providers.

The fallback path now updates the "model" field in the payload to match the resolved model name before returning.

…fix leak

        When no request translator is registered for a format pair (e.g.
        openai-response → openai-response), TranslateRequest returned the raw
        payload unchanged. This caused client-side model prefixes (e.g.
        "copilot/gpt-5-mini") to leak into upstream requests, resulting in
        "The requested model is not supported" errors from providers.

        The fallback path now updates the "model" field in the payload to
        match the resolved model name before returning.
Copilot AI review requested due to automatic review settings March 18, 2026 16:31
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial fix to prevent client-side model name prefixes from being inadvertently sent to upstream providers. Previously, if a specific request translator was not found for a given format pair, the raw payload was returned unchanged, potentially exposing internal model naming conventions. The updated logic ensures that even in fallback scenarios, the "model" field within the request payload is normalized to the correct, resolved model name, thereby avoiding errors from external APIs due to unrecognized model identifiers.

Highlights

  • Problem Addressed: Client-side model prefixes (e.g., "copilot/gpt-5-mini") were leaking into upstream requests when no specific request translator was registered, leading to "The requested model is not supported" errors from providers.
  • Solution Implemented: The TranslateRequest fallback path now updates the "model" field in the raw payload to match the resolved model name before returning, preventing these prefix leaks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where client-side model prefixes were leaking into upstream requests when no request translator was registered. The fix involves updating the 'model' field in the fallback path to use the resolved model name. The implementation is correct and uses gjson and sjson to manipulate the JSON payload. I have one suggestion regarding error handling to improve debuggability.

Comment thread sdk/translator/registry.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue in the SDK request translation fallback path where, if no request transformer is registered for a (from, to) format pair, the raw JSON payload was returned unchanged—allowing client-side model prefixes (e.g., copilot/...) to leak into upstream provider requests.

Changes:

  • Update TranslateRequest fallback behavior to rewrite the top-level "model" field to the resolved model name before returning the payload.
  • Add gjson/sjson usage in the registry to perform conditional JSON read/write during fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread sdk/translator/registry.go
  - Log a warning instead of silently ignoring sjson.SetBytes errors in the TranslateRequest fallback path
  - Add registry_test.go with tests covering the fallback model normalization and verifying registered transforms take precedence
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e27990561

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +58 to +63
if model != "" && gjson.GetBytes(rawJSON, "model").String() != model {
if updated, err := sjson.SetBytes(rawJSON, "model", model); err != nil {
log.Warnf("translator: failed to normalize model in request fallback: %v", err)
} else {
return updated
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve full custom model IDs on openai-response passthrough

This fallback now rewrites any top-level model to baseModel, which breaks the explicit support for custom registrations whose literal ID includes a thinking-style suffix (see sdk/api/handlers/handlers.go:795-810, e.g. my-model(8192)). In the compact OpenAI-compat path (internal/runtime/executor/openai_compat_executor.go:87-99), requests stay in openai-response format and are posted upstream directly, so a request for my-model(8192) will now send my-model instead. For those custom OpenAI-compatible models, that changes the actual upstream model ID and can cause the request to hit the wrong model or fail outright.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

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

Summary:
This PR fixes a real correctness issue in the fallback path of TranslateRequest by normalizing the model field when no request transformer is registered, preventing prefixed client model names from leaking upstream.

Key findings:

  • Blocking: none.
  • Non-blocking: test coverage is good for the core behavior and transform precedence; adding an invalid-JSON case would make failure-path expectations even clearer.

Validation:

  • Reviewed diff for sdk/translator/registry.go and sdk/translator/registry_test.go.
  • Ran go test ./sdk/translator (pass).
  • Ran go test ./... (pass).

Recommendation:
Approve. The change is scoped, addresses the reported failure mode, and includes targeted tests for the new fallback behavior.

This is an automated Codex review result and still requires manual verification by a human reviewer.

@luispater luispater changed the base branch from main to dev March 23, 2026 15:55
@luispater luispater merged commit 66ff916 into router-for-me:dev Mar 23, 2026
2 checks passed
Adamcf123 pushed a commit to Adamcf123/CLIProxyAPI that referenced this pull request Mar 24, 2026
fix: normalize model name in TranslateRequest fallback to prevent prefix leak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants