fix(antigravity): align Client-Metadata platform/identity with Antigravity requests#1578
Conversation
Summary of ChangesHello @happycastle114, 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 refactors the Antigravity authentication mechanism to dynamically generate client metadata, ensuring consistent platform and identity signaling across various requests. This change is crucial for maintaining compatibility with recent Antigravity interop updates, preventing discrepancies between header and request body metadata. 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 correctly centralizes the generation of Antigravity metadata, replacing hardcoded values with dynamic ones. This improves consistency between request headers and bodies. I've identified a couple of areas for improvement in the new implementation. The platform detection logic is not fully robust and could misidentify operating systems like Linux. Additionally, there's an opportunity to refactor the new helper functions to eliminate code duplication and a minor inefficiency. My review comments provide specific suggestions to address these points.
| func runtimeMetadataPlatform() string { | ||
| if runtime.GOOS == "windows" { | ||
| return "WINDOWS" | ||
| } | ||
| return "MACOS" | ||
| } |
There was a problem hiding this comment.
The current implementation for runtimeMetadataPlatform is not robust. It correctly identifies Windows, but incorrectly classifies all other operating systems, including Linux, as MACOS. Given that the APIClient constant suggests usage in vscode_cloudshelleditor, which is a Linux environment, this will lead to incorrect platform reporting.
It would be better to use a switch statement on runtime.GOOS to explicitly handle different supported operating systems. For macOS, the value of runtime.GOOS is "darwin". I suggest handling linux explicitly and adding a default case to fall back to PLATFORM_UNSPECIFIED for any other OS, which was the value used prior to this change.
func runtimeMetadataPlatform() string {
switch runtime.GOOS {
case "windows":
return "WINDOWS"
case "darwin":
return "MACOS"
case "linux":
return "LINUX"
default:
return "PLATFORM_UNSPECIFIED"
}
}| func antigravityJSONClientMetadata() string { | ||
| return fmt.Sprintf(`{"ideType":"ANTIGRAVITY","platform":"%s","pluginType":"GEMINI"}`, runtimeMetadataPlatform()) | ||
| } | ||
|
|
||
| func antigravityRequestMetadata() map[string]string { | ||
| return map[string]string{ | ||
| "ideType": "ANTIGRAVITY", | ||
| "platform": runtimeMetadataPlatform(), | ||
| "pluginType": "GEMINI", | ||
| } | ||
| } |
There was a problem hiding this comment.
There is some duplication between antigravityJSONClientMetadata and antigravityRequestMetadata. Both functions construct similar metadata structures and call runtimeMetadataPlatform(). In functions like FetchProjectID, both helpers are called, resulting in runtimeMetadataPlatform() being executed twice, which is slightly inefficient.
To improve this, you could determine the platform once at package initialization and store it in a package-level variable. This variable can then be reused in both helper functions, making the code more efficient and adhering to the Don't Repeat Yourself (DRY) principle.
var platform = runtimeMetadataPlatform()
func antigravityJSONClientMetadata() string {
return fmt.Sprintf("{\"ideType\":\"ANTIGRAVITY\",\"platform\":\"%s\",\"pluginType\":\"GEMINI\"}", platform)
}
func antigravityRequestMetadata() map[string]string {
return map[string]string{
"ideType": "ANTIGRAVITY",
"platform": platform,
"pluginType": "GEMINI",
}
}
Summary
This patch aligns Antigravity metadata identity fields across auth requests.
Changes
Client-MetadataJSON (IDE_UNSPECIFIED/PLATFORM_UNSPECIFIED) with dynamic Antigravity metadata.Client-Metadatanow uses:ideType: ANTIGRAVITYplatform: WINDOWSon Windows, otherwiseMACOSpluginType: GEMINImetadatato use the same dynamic platform mapping.Why
Recent Antigravity interop updates require consistent identity/platform signaling. This avoids mixed metadata values between headers and request body.
Notes
go testin this environment because Go toolchain is unavailable (go: command not found).