fix: normalize model name in TranslateRequest fallback to prevent prefix leak#2220
fix: normalize model name in TranslateRequest fallback to prevent prefix leak#2220luispater merged 2 commits intorouter-for-me:devfrom
Conversation
…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.
Summary of ChangesHello, 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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
TranslateRequestfallback behavior to rewrite the top-level"model"field to the resolved model name before returning the payload. - Add
gjson/sjsonusage 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.
- 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
There was a problem hiding this comment.
💡 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".
| 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 | ||
| } |
There was a problem hiding this comment.
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 👍 / 👎.
luispater
left a comment
There was a problem hiding this comment.
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.goandsdk/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.
fix: normalize model name in TranslateRequest fallback to prevent prefix leak
When no request translator is registered for a format pair (e.g. openai-response → openai-response),
TranslateRequestreturned 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.