Skip to content

Refactor Antigravity model handling and improve logging#2082

Merged
luispater merged 3 commits intodevfrom
antigravity
Mar 12, 2026
Merged

Refactor Antigravity model handling and improve logging#2082
luispater merged 3 commits intodevfrom
antigravity

Conversation

@hkfires
Copy link
Copy Markdown
Collaborator

@hkfires hkfires commented Mar 12, 2026

Refactor the handling of Antigravity models by removing unused code and clarifying log messages related to model refresh failures. Introduce a command to fetch and save the Antigravity model list.

@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 significantly refactors the handling of Antigravity models by introducing a dedicated command-line utility for fetching and persisting model definitions. This change moves away from dynamic, runtime API calls for model registration, leading to a more robust and predictable system. The internal data structures for Antigravity models have been standardized to a list format, and associated deprecated code for model caching and backfilling has been eliminated, resulting in a cleaner and more maintainable codebase with clearer logging for model refresh issues.

Highlights

  • New Command-Line Tool: A new command-line tool (cmd/fetch_antigravity_models) was introduced to fetch and save the Antigravity model list to a JSON file, enabling offline use and inspection.
  • Antigravity Model Refactoring: The internal representation of Antigravity models was refactored from a map-based configuration to a more consistent list-based structure, simplifying model handling.
  • Code Simplification and Removal: Significant unused code related to dynamic Antigravity model fetching, caching, and backfilling was removed, streamlining the codebase.
  • Improved Logging: Log messages related to model refresh failures were clarified to indicate the use of 'local data' instead of 'current data'.

🧠 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
  • cmd/fetch_antigravity_models/main.go
    • Added a new Go command-line tool to connect to the Antigravity API, fetch the available model list, and save it to a JSON file. This tool includes flags for specifying auth directory, output path, and pretty-printing.
  • internal/registry/model_definitions.go
    • Removed the sort import.
    • Deleted the AntigravityModelConfig struct.
    • Changed the Antigravity field in staticModelsJSON from map[string]*AntigravityModelConfig to []*ModelInfo.
    • Removed GetAntigravityModelConfig and cloneAntigravityModelConfig functions.
    • Added GetAntigravityModels function to return the list of Antigravity models.
    • Updated GetStaticModelDefinitionsByChannel to directly return GetAntigravityModels() instead of constructing models from AntigravityModelConfig.
    • Updated LookupStaticModelInfo to include data.Antigravity in the allModels slice and removed the separate check for Antigravity static config.
  • internal/registry/model_updater.go
    • Modified a log message from "using current data" to "using local data" for model refresh failures.
    • Updated validateModelsCatalog to include antigravity in the requiredSections slice.
    • Removed the validateAntigravitySection function.
  • internal/registry/models/models.json
    • Transformed the antigravity section from a JSON object (map) where keys were model IDs to a JSON array of model objects.
    • Each model object now explicitly includes id, object, owned_by, type, display_name, name, description, context_length, and max_completion_tokens fields, in addition to the existing thinking configuration.
  • internal/runtime/executor/antigravity_executor.go
    • Removed the antigravityModelsPath constant.
    • Removed the antigravityPrimaryModelsCache struct and all associated functions (cloneAntigravityModels, cloneAntigravityModelInfo, storeAntigravityPrimaryModels, loadAntigravityPrimaryModels, fallbackAntigravityPrimaryModels).
    • Removed the FetchAntigravityModels function, which was responsible for dynamically fetching models from the Antigravity API.
  • internal/runtime/executor/antigravity_executor_models_cache_test.go
    • Removed the entire test file as its functionality is no longer needed.
  • sdk/cliproxy/service.go
    • Removed a comment related to FetchAntigravityModels and potential timeouts.
    • Modified registerModelsForAuth for the "antigravity" provider to directly call registry.GetAntigravityModels() instead of executor.FetchAntigravityModels().
    • Removed the call to s.backfillAntigravityModels and the backfillAntigravityModels function itself.
  • sdk/cliproxy/service_antigravity_backfill_test.go
    • Removed the entire test file as its functionality is no longer needed.
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.

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

  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.

@luispater luispater merged commit 817cebb into dev Mar 12, 2026
2 checks passed
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 refactors the handling of Antigravity models by replacing the runtime dynamic fetching with a static model list in models.json. A new command-line tool, fetch_antigravity_models, is introduced to update this static list. This is a good simplification of the runtime logic. My review includes a suggestion to improve the efficiency of the new command-line tool by moving invariant operations out of a loop.

Comment on lines +162 to +259
func fetchModels(ctx context.Context, auth *coreauth.Auth) []modelEntry {
accessToken := metaStringValue(auth.Metadata, "access_token")
if accessToken == "" {
fmt.Fprintln(os.Stderr, "error: no access token found in auth")
return nil
}

baseURLs := []string{antigravityBaseURLProd, antigravityBaseURLDaily, antigravitySandboxBaseURLDaily}

for _, baseURL := range baseURLs {
modelsURL := baseURL + antigravityModelsPath

var payload []byte
if auth != nil && auth.Metadata != nil {
if pid, ok := auth.Metadata["project_id"].(string); ok && strings.TrimSpace(pid) != "" {
payload = []byte(fmt.Sprintf(`{"project": "%s"}`, strings.TrimSpace(pid)))
}
}
if len(payload) == 0 {
payload = []byte(`{}`)
}

httpReq, errReq := http.NewRequestWithContext(ctx, http.MethodPost, modelsURL, strings.NewReader(string(payload)))
if errReq != nil {
continue
}
httpReq.Close = true
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set("Authorization", "Bearer "+accessToken)
httpReq.Header.Set("User-Agent", "antigravity/1.19.6 darwin/arm64")

httpClient := &http.Client{Timeout: 30 * time.Second}
if transport, _, errProxy := proxyutil.BuildHTTPTransport(auth.ProxyURL); errProxy == nil && transport != nil {
httpClient.Transport = transport
}
httpResp, errDo := httpClient.Do(httpReq)
if errDo != nil {
continue
}

bodyBytes, errRead := io.ReadAll(httpResp.Body)
httpResp.Body.Close()
if errRead != nil {
continue
}

if httpResp.StatusCode < http.StatusOK || httpResp.StatusCode >= http.StatusMultipleChoices {
continue
}

result := gjson.GetBytes(bodyBytes, "models")
if !result.Exists() {
continue
}

var models []modelEntry

for originalName, modelData := range result.Map() {
modelID := strings.TrimSpace(originalName)
if modelID == "" {
continue
}
// Skip internal/experimental models
switch modelID {
case "chat_20706", "chat_23310", "tab_flash_lite_preview", "tab_jump_flash_lite_preview", "gemini-2.5-flash-thinking", "gemini-2.5-pro":
continue
}

displayName := modelData.Get("displayName").String()
if displayName == "" {
displayName = modelID
}

entry := modelEntry{
ID: modelID,
Object: "model",
OwnedBy: "antigravity",
Type: "antigravity",
DisplayName: displayName,
Name: modelID,
Description: displayName,
}

if maxTok := modelData.Get("maxTokens").Int(); maxTok > 0 {
entry.ContextLength = int(maxTok)
}
if maxOut := modelData.Get("maxOutputTokens").Int(); maxOut > 0 {
entry.MaxCompletionTokens = int(maxOut)
}

models = append(models, entry)
}

return models
}

return nil
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For efficiency, the httpClient and request payload can be created once before the loop, as they don't change between iterations.

func fetchModels(ctx context.Context, auth *coreauth.Auth) []modelEntry {
	accessToken := metaStringValue(auth.Metadata, "access_token")
	if accessToken == "" {
		fmt.Fprintln(os.Stderr, "error: no access token found in auth")
		return nil
	}

	baseURLs := []string{antigravityBaseURLProd, antigravityBaseURLDaily, antigravitySandboxBaseURLDaily}

	httpClient := &http.Client{Timeout: 30 * time.Second}
	if transport, _, errProxy := proxyutil.BuildHTTPTransport(auth.ProxyURL); errProxy == nil && transport != nil {
		httpClient.Transport = transport
	}

	var payload []byte
	if auth != nil && auth.Metadata != nil {
		if pid, ok := auth.Metadata["project_id"].(string); ok && strings.TrimSpace(pid) != "" {
			payload = []byte(fmt.Sprintf(`{"project": "%s"}`, strings.TrimSpace(pid)))
		}
	}
	if len(payload) == 0 {
		payload = []byte(`{}`)
	}
	payloadReader := string(payload)

	for _, baseURL := range baseURLs {
		modelsURL := baseURL + antigravityModelsPath

		httpReq, errReq := http.NewRequestWithContext(ctx, http.MethodPost, modelsURL, strings.NewReader(payloadReader))
		if errReq != nil {
			continue
		}
		httpReq.Close = true
		httpReq.Header.Set("Content-Type", "application/json")
		httpReq.Header.Set("Authorization", "Bearer "+accessToken)
		httpReq.Header.Set("User-Agent", "antigravity/1.19.6 darwin/arm64")

		httpResp, errDo := httpClient.Do(httpReq)
		if errDo != nil {
			continue
		}

		bodyBytes, errRead := io.ReadAll(httpResp.Body)
		httpResp.Body.Close()
		if errRead != nil {
			continue
		}

		if httpResp.StatusCode < http.StatusOK || httpResp.StatusCode >= http.StatusMultipleChoices {
			continue
		}

		result := gjson.GetBytes(bodyBytes, "models")
		if !result.Exists() {
			continue
		}

		var models []modelEntry

		for originalName, modelData := range result.Map() {
			modelID := strings.TrimSpace(originalName)
			if modelID == "" {
				continue
			}
			// Skip internal/experimental models
			switch modelID {
			case "chat_20706", "chat_23310", "tab_flash_lite_preview", "tab_jump_flash_lite_preview", "gemini-2.5-flash-thinking", "gemini-2.5-pro":
				continue
			}

			displayName := modelData.Get("displayName").String()
			if displayName == "" {
				displayName = modelID
			}

			entry := modelEntry{
				ID:          modelID,
				Object:      "model",
				OwnedBy:     "antigravity",
				Type:        "antigravity",
				DisplayName: displayName,
				Name:        modelID,
				Description: displayName,
			}

			if maxTok := modelData.Get("maxTokens").Int(); maxTok > 0 {
				entry.ContextLength = int(maxTok)
			}
			if maxOut := modelData.Get("maxOutputTokens").Int(); maxOut > 0 {
				entry.MaxCompletionTokens = int(maxOut)
			}

			models = append(models, entry)
		}

		return models
	}

	return nil
}

@luispater luispater deleted the antigravity branch March 12, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants