Skip to content

fix(go/plugins/googlegenai): fixed tool thought signature#4798

Open
apascal07 wants to merge 1 commit intomainfrom
ap/go-gemini-fix-2
Open

fix(go/plugins/googlegenai): fixed tool thought signature#4798
apascal07 wants to merge 1 commit intomainfrom
ap/go-gemini-fix-2

Conversation

@apascal07
Copy link
Collaborator

Checklist (if applicable):

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @apascal07, 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 an issue where the ThoughtSignature in the googlegenai plugin was not being correctly processed after undergoing a JSON serialization and deserialization cycle. It introduces a dedicated helper function to robustly extract the signature, accommodating both its original byte slice format and its base64-encoded string representation, thereby ensuring consistent and reliable behavior across different data representations.

Highlights

  • Refactored ThoughtSignature Extraction: A new helper function, metadataSignature, was introduced to centralize the logic for retrieving the ThoughtSignature from part metadata.
  • Improved ThoughtSignature Handling: The metadataSignature function now correctly handles ThoughtSignature values that are either []byte (original format) or string (base64-encoded after a JSON clone roundtrip).
  • Consistent Logic Application: The updated ThoughtSignature extraction logic is consistently applied to both function call parts and general parts within the toGeminiPart function.

🧠 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
  • go/plugins/googlegenai/gemini.go
    • Refactored ThoughtSignature extraction logic into a new helper function.
    • Added metadataSignature function to handle []byte and base64-encoded string signatures from metadata.
    • Updated toGeminiPart to utilize the new metadataSignature function for assigning ThoughtSignature.
Activity
  • The pull request was created by apascal07.
  • The author has marked the PR title as conforming to conventional commits and confirmed manual/unit testing.
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.

Copy link
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 introduces a fix for handling tool thought signatures by extracting the logic into a new metadataSignature helper function. This is a great improvement as it centralizes the logic, removes duplicated code, and correctly handles signatures that have been base64-encoded as strings after a JSON roundtrip. The changes are logical and include relevant tests. I have a few minor suggestions to improve code organization and reduce comment duplication for better long-term maintainability.

Comment on lines +1011 to +1013
// Restore ThoughtSignature if present in metadata.
// Handle both []byte (original) and string (after JSON clone roundtrip
// which base64-encodes []byte values).
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This detailed comment is duplicated below (lines 1022-1024). Since the new metadataSignature function is well-commented, you can simplify the comments at the call sites to a single line to avoid repetition.

Suggested change
// Restore ThoughtSignature if present in metadata.
// Handle both []byte (original) and string (after JSON clone roundtrip
// which base64-encodes []byte values).
// Restore ThoughtSignature if present in metadata.

Comment on lines +1022 to +1024
// Restore ThoughtSignature if present in metadata.
// Handle both []byte (original) and string (after JSON clone roundtrip
// which base64-encodes []byte values).
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This is a duplicate of the comment above (lines 1011-1013). To improve maintainability, it's best to avoid duplicating comments. A single-line comment would be sufficient here, as the details are in the metadataSignature function's own comment.

Suggested change
// Restore ThoughtSignature if present in metadata.
// Handle both []byte (original) and string (after JSON clone roundtrip
// which base64-encodes []byte values).
// Restore ThoughtSignature if present in metadata.

Comment on lines +1037 to +1053
// metadataSignature extracts the thought signature from part metadata.
// It handles both []byte (original value) and string (base64-encoded
// after a JSON clone roundtrip).
func metadataSignature(metadata map[string]any) []byte {
switch sig := metadata["signature"].(type) {
case []byte:
return sig
case string:
decoded, err := base64.StdEncoding.DecodeString(sig)
if err != nil {
return nil
}
return decoded
}
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The placement of this new function separates the comment for validToolName from its implementation, which harms readability. For better code organization, please consider moving this new metadataSignature function to after the validToolName function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants