feat: dynamic model fetching for GitHub Copilot#408
feat: dynamic model fetching for GitHub Copilot#408luispater merged 2 commits intorouter-for-me:mainfrom
Conversation
- Add ListModels/ListModelsWithGitHubToken to CopilotAuth for querying the /models endpoint at api.githubcopilot.com - Add FetchGitHubCopilotModels in executor with static fallback on failure - Update service.go to use dynamic fetching (15s timeout) instead of hardcoded GetGitHubCopilotModels() - Add GitHubCopilotAliasesFromModels for auto-generating dot-to-hyphen model aliases from dynamic model lists
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 significant enhancement by enabling dynamic fetching of GitHub Copilot models. Instead of relying on hardcoded model lists, the system can now query the Copilot API directly to retrieve available models. This change improves the flexibility and accuracy of model availability, ensuring the application always reflects the latest offerings from GitHub Copilot. It also includes robust error handling and a fallback to static model definitions to maintain stability. 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. Changelog
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 introduces dynamic fetching of GitHub Copilot models, enhancing the current static list. However, several critical security issues have been identified. The most critical is a potential SSRF and token leakage vulnerability in the ListModels function, stemming from unvalidated endpoint URLs provided by the API. Additionally, there's a risk of memory exhaustion (DoS) due to a lack of response size limits, and a logic flaw in model registration could lead to incorrect availability tracking if duplicate model IDs are returned by the API. Beyond security, the review also highlights areas for improving code clarity, maintainability, and correctness, including refactoring opportunities, addressing unused code, and replacing magic numbers with constants.
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #37 by making the GitHub Copilot model list update dynamically from the Copilot API instead of relying solely on hardcoded registry entries, while preserving a static fallback for resiliency.
Changes:
- Fetch GitHub Copilot models dynamically via Copilot
/models(with fallback to static registry data). - Add Copilot auth support for
/modelslisting (data structs + request method). - Add a helper to derive GitHub Copilot OAuth model aliases from dynamically fetched model IDs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| sdk/cliproxy/service.go | Switches GitHub Copilot model registration to use the dynamic fetch helper with a timeout. |
| internal/runtime/executor/github_copilot_executor.go | Implements dynamic model fetching + static enrichment/fallback in the executor layer. |
| internal/auth/copilot/copilot_auth.go | Adds /models API types and a method to list models using a Copilot API token. |
| internal/config/oauth_model_alias_defaults.go | Adds helper for generating alias defaults from dynamically fetched model IDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| modelsURL := copilotAPIEndpoint + "/models" | ||
| if apiToken.Endpoints.API != "" { | ||
| modelsURL = apiToken.Endpoints.API + "/models" | ||
| } |
There was a problem hiding this comment.
When building modelsURL, apiToken.Endpoints.API may already include a trailing slash. Concatenating + "/models" can produce a double-slash URL; consider strings.TrimRight(apiToken.Endpoints.API, "/") + "/models" (similar to how the executor trims endpoints).
- Fix SSRF: validate API endpoint host against allowlist before use - Limit /models response body to 2MB to prevent memory exhaustion (DoS) - Use MakeAuthenticatedRequest for consistent headers across API calls - Trim trailing slash on API endpoint to prevent double-slash URLs - Use ListModelsWithGitHubToken to simplify token exchange + listing - Deduplicate model IDs to prevent incorrect registry reference counting - Remove dead capabilities enrichment code block - Remove unused ModelExtra field with misleading json:"-" tag - Extract magic numbers to named constants (defaultCopilotContextLength) - Remove redundant hyphenID == id check (already filtered by Contains) - Use defer cancel() for context timeout in service.go
|
@copilot code review[agent] |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| defer cancel() | ||
| models = executor.FetchGitHubCopilotModels(ctx, a, s.cfg) |
There was a problem hiding this comment.
The timeout context is canceled via defer, so the timer can stay active until registerModelsForAuth returns (which continues doing non-trivial work after this switch). Consider calling cancel() immediately after FetchGitHubCopilotModels returns (as done in the antigravity case) to release resources promptly.
| defer cancel() | |
| models = executor.FetchGitHubCopilotModels(ctx, a, s.cfg) | |
| models = executor.FetchGitHubCopilotModels(ctx, a, s.cfg) | |
| cancel() |
| // ListModels fetches the list of available models from the Copilot API. | ||
| // It requires a valid Copilot API token (not the GitHub access token). | ||
| func (c *CopilotAuth) ListModels(ctx context.Context, apiToken *CopilotAPIToken) ([]CopilotModelEntry, error) { | ||
| if apiToken == nil || apiToken.Token == "" { | ||
| return nil, fmt.Errorf("copilot: api token is required for listing models") | ||
| } |
There was a problem hiding this comment.
ListModels and the new endpoint validation/response-size limiting logic should have unit tests (similar to internal/auth/copilot/oauth_test.go) to cover: trusted vs untrusted endpoint host handling, non-2xx responses, and successful JSON parsing.
| // FetchGitHubCopilotModels dynamically fetches available models from the GitHub Copilot API. | ||
| // It exchanges the GitHub access token stored in auth.Metadata for a Copilot API token, | ||
| // then queries the /models endpoint. Falls back to the static registry on any failure. | ||
| func FetchGitHubCopilotModels(ctx context.Context, auth *cliproxyauth.Auth, cfg *config.Config) []*registry.ModelInfo { | ||
| if auth == nil { | ||
| log.Debug("github-copilot: auth is nil, using static models") | ||
| return registry.GetGitHubCopilotModels() | ||
| } |
There was a problem hiding this comment.
FetchGitHubCopilotModels introduces new behavior (dynamic model list + merging with static metadata) but there are no tests covering success, empty result fallback, and error fallback paths. Consider adding unit tests (e.g., using an httptest server and injecting/mocking CopilotAuth) to prevent regressions.
fix: #37