Skip to content

Comments

fix: use session.NewEvent in generateRequestConfirmationEvent#591

Closed
mohamedabozeid wants to merge 1 commit intogoogle:mainfrom
mohamedabozeid:fix/missing-event-id-in-request-confirmation
Closed

fix: use session.NewEvent in generateRequestConfirmationEvent#591
mohamedabozeid wants to merge 1 commit intogoogle:mainfrom
mohamedabozeid:fix/missing-event-id-in-request-confirmation

Conversation

@mohamedabozeid
Copy link

Fixes #590

Description

generateRequestConfirmationEvent in internal/llminternal/functions.go constructs an Event using a raw struct literal, bypassing session.NewEvent(). This results in:

  1. Missing ID — empty string instead of a UUID. Any downstream logic relying on event IDs for deduplication, ordering, tracing, or correlation will break.
  2. Uninitialized StateDelta — nil map instead of map[string]any{}, which could cause nil map panics if anything writes to it.

Root Cause

The function was written as a raw struct literal &session.Event{...} instead of calling session.NewEvent(). The NewEvent constructor sets:

  • ID: uuid.NewString()
  • Timestamp: time.Now()
  • Actions: EventActions{StateDelta: make(map[string]any)}

The raw literal only set Timestamp and left ID empty and StateDelta nil.

Fix

Replace the raw struct literal with session.NewEvent() and set the remaining fields (Author, Branch, LLMResponse, LongRunningToolIDs) on the returned object. This is consistent with how events are created elsewhere in the codebase.

Testing Plan

Unit Tests

Updated tests in internal/llminternal/functions_test.go:

  • Added assertions verifying that the returned event has a non-empty ID and a non-zero Timestamp.
  • Updated existing test expectation to match the properly initialized StateDelta from NewEvent.

Manual E2E Test

Verified with go test ./internal/llminternal/... — all tests pass with no regressions.

The function was constructing an Event with a raw struct literal,
bypassing session.NewEvent(). This resulted in missing ID (empty
string) and uninitialized StateDelta (nil map). Use NewEvent to
ensure all fields are properly initialized.
@google-cla
Copy link

google-cla bot commented Feb 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mohamedabozeid, 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 critical issues in event generation by refactoring the generateRequestConfirmationEvent function. By adopting the session.NewEvent() constructor, it guarantees that all new events are correctly initialized with unique IDs and properly structured state delta maps, preventing potential runtime errors and ensuring data integrity for downstream event processing.

Highlights

  • Event Initialization Fix: Corrected the generateRequestConfirmationEvent function to use session.NewEvent() instead of a raw struct literal, ensuring proper initialization of ID (UUID) and StateDelta (empty map).
  • Prevented Nil Map Panics: Addressed the risk of nil map panics by ensuring StateDelta is initialized as an empty map, rather than nil, when creating new events.
  • Enhanced Test Coverage: Updated unit tests to verify that generated events have a non-empty ID and a non-zero Timestamp, and adjusted expectations for StateDelta initialization.

🧠 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
  • internal/llminternal/functions.go
    • Removed time import as session.NewEvent handles timestamp generation.
    • Refactored event creation from a raw struct literal to session.NewEvent(), then assigned specific fields.
  • internal/llminternal/functions_test.go
    • Updated test expectation for session.Event to include an initialized Actions.StateDelta map.
    • Added assertions to verify that the generated event has a non-empty ID and a non-zero Timestamp.
Activity
  • Unit tests were updated in internal/llminternal/functions_test.go to include new assertions for ID and Timestamp and to match the correct StateDelta initialization.
  • Manual end-to-end testing was performed by running go test ./internal/llminternal/..., confirming all tests pass without regressions.
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 correctly fixes a bug where session.Event was being created with a raw struct literal, leading to missing fields. The switch to session.NewEvent() is the right approach, and the updated tests properly verify the fix. I have one minor suggestion to make the code slightly more concise.

Comment on lines +82 to 87
event.LLMResponse = model.LLMResponse{
Content: &genai.Content{
Parts: parts,
Role: genai.RoleModel,
},
Timestamp: time.Now(),
LongRunningToolIDs: longRunningToolIDs,
Actions: session.EventActions{},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Since session.Event embeds model.LLMResponse, you can set the Content field directly on the event object. This avoids the explicit model.LLMResponse struct literal, making the code a little more direct.

For example:

event.Content = &genai.Content{
    Parts: parts,
    Role:  genai.RoleModel,
}

This is functionally equivalent to the current implementation because session.NewEvent already zero-initializes the embedded model.LLMResponse struct.

@mohamedabozeid
Copy link
Author

duplicate to #588

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.

generateRequestConfirmationEvent creates events with missing ID

1 participant