[model-gateway] bugfix: backward compatibility for GET endpoints#15413
Conversation
Summary of ChangesHello @alphabetc1, 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 resolves a compatibility issue where the router failed to retrieve metadata from older SGLang workers due to a mismatch in API endpoint versions. It implements a robust fallback mechanism that allows the router to gracefully handle 404 responses from modern endpoints by automatically retrying with their deprecated legacy counterparts. This ensures continued functionality for older worker versions while providing clear deprecation warnings, facilitating a smoother transition to the updated API. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds backward compatibility for metadata discovery by falling back to legacy endpoints when the new ones are not available. The implementation is correct, but it introduces some code duplication. My review includes suggestions to refactor the new code to improve maintainability by reducing this duplication.
| async fn get_json_fallback( | ||
| base_url: &str, | ||
| endpoint: &str, | ||
| api_key: Option<&str>, | ||
| ) -> Result<Value, String> { | ||
| // FIXME: This fallback logic should be removed together with /get_server_info | ||
| // and /get_model_info endpoints in http_server.py | ||
| warn!( | ||
| concat!( | ||
| "Endpoint '/{}' returned 404, falling back to '/get_{}' for backward compatibility. ", | ||
| "The '/get_{}' endpoint is deprecated and will be removed in a future version. ", | ||
| "Please use '/{}' instead." | ||
| ), | ||
| endpoint, endpoint, endpoint, endpoint | ||
| ); | ||
|
|
||
| let old_url = format!("{}/get_{}", base_url, endpoint); | ||
| let mut req = HTTP_CLIENT.get(&old_url); | ||
| if let Some(key) = api_key { | ||
| req = req.bearer_auth(key); | ||
| } | ||
|
|
||
| let response = req | ||
| .send() | ||
| .await | ||
| .map_err(|e| format!("Failed to connect to {}: {}", old_url, e))?; | ||
|
|
||
| if !response.status().is_success() { | ||
| return Err(format!( | ||
| "Server returned status {} from {}", | ||
| response.status(), | ||
| old_url | ||
| )); | ||
| } | ||
|
|
||
| response | ||
| .json::<Value>() | ||
| .await | ||
| .map_err(|e| format!("Failed to parse response from {}: {}", old_url, e)) | ||
| } |
There was a problem hiding this comment.
To reduce code duplication in get_server_info and get_model_info, you can make this function generic to handle deserialization. This moves the serde_json::from_value logic inside get_json_fallback and simplifies the call sites. This change will allow you to simplify the fallback logic in both get_server_info and get_model_info as suggested in the other comments. Using serde::de::DeserializeOwned is a bit more idiomatic here.
async fn get_json_fallback<T: serde::de::DeserializeOwned>(
base_url: &str,
endpoint: &str,
api_key: Option<&str>,
) -> Result<T, String> {
// FIXME: This fallback logic should be removed together with /get_server_info
// and /get_model_info endpoints in http_server.py
warn!(
concat!(
"Endpoint '/{}' returned 404, falling back to '/get_{}' for backward compatibility. ",
"The '/get_{}' endpoint is deprecated and will be removed in a future version. ",
"Please use '/{}' instead."
),
endpoint, endpoint, endpoint, endpoint
);
let old_url = format!("{}/get_{}", base_url, endpoint);
let mut req = HTTP_CLIENT.get(&old_url);
if let Some(key) = api_key {
req = req.bearer_auth(key);
}
let response = req
.send()
.await
.map_err(|e| format!("Failed to connect to {}: {}", old_url, e))?;
if !response.status().is_success() {
return Err(format!(
"Server returned status {} from {}",
response.status(),
old_url
));
}
let value: Value = response
.json()
.await
.map_err(|e| format!("Failed to parse response from {}: {}", old_url, e))?;
serde_json::from_value(value)
.map_err(|e| format!("Failed to parse {} from fallback response: {}", endpoint, e))
}| // If /server_info returns 404, fallback to /get_server_info for backward compatibility | ||
| if response.status() == reqwest::StatusCode::NOT_FOUND { | ||
| let json = get_json_fallback(base_url, "server_info", api_key).await?; | ||
| return serde_json::from_value(json) | ||
| .map_err(|e| format!("Failed to parse server info: {}", e)); | ||
| } |
There was a problem hiding this comment.
With the suggested generic get_json_fallback function, this block can be simplified to a single call, removing the duplicated deserialization logic.
// If /server_info returns 404, fallback to /get_server_info for backward compatibility
if response.status() == reqwest::StatusCode::NOT_FOUND {
return get_json_fallback::<ServerInfo>(base_url, "server_info", api_key).await;
}| // If /model_info returns 404, fallback to /get_model_info for backward compatibility | ||
| if response.status() == reqwest::StatusCode::NOT_FOUND { | ||
| let json = get_json_fallback(base_url, "model_info", api_key).await?; | ||
| return serde_json::from_value(json) | ||
| .map_err(|e| format!("Failed to parse model info: {}", e)); | ||
| } |
There was a problem hiding this comment.
With the suggested generic get_json_fallback function, this block can be simplified to a single call, removing the duplicated deserialization logic.
// If /model_info returns 404, fallback to /get_model_info for backward compatibility
if response.status() == reqwest::StatusCode::NOT_FOUND {
return get_json_fallback::<ModelInfo>(base_url, "model_info", api_key).await;
}
Summary
This commit adds backward-compatible metadata discovery: when
/server_infoor/model_infois unavailable, the router falls back to legacy/get_server_infoand/get_model_infoto keep older SGLang workers compatible with the newer SGLang router.Root Cause
Newer router versions use
/server_infoand/model_info, but older SGLang workers don’t implement these endpoints (only the legacy/get_*ones), This causes server_info and model_info to be lost:Solution
On 404 from
/server_infoor/model_info, automatically retry via the corresponding legacy/get_*endpoint, and emit a deprecation warning. A FIXME notes this fallback will be removed together with the worker’s legacy/get_server_infoand/get_model_infoendpoints in the future.Motivation
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist