Skip to content

Conversation

@lwangverizon
Copy link

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

2. Or, if no issue exists, describe the change:

Problem:

When building frontend applications with ADK, there's a limitation where frontends cannot always guarantee that create_session is called before initiating a conversation. This creates friction in the user experience because:

  • Users may refresh the page or navigate directly to a conversation URL with a specific session_id
  • Frontend state management may lose track of whether a session was already created
  • Mobile apps or single-page applications have complex lifecycle management where ensuring create_session is called first adds unnecessary complexity
  • This forces developers to implement additional logic to check session existence before every conversation

Currently, if get_session is called with a non-existent session_id, it returns None, requiring the frontend to explicitly handle this case and call create_session separately.

Solution:

Modified the get_session method in DatabaseSessionService to automatically create a session if it doesn't exist in the database. This "get or create" pattern is common in many frameworks and provides a more developer-friendly API.

The implementation:

  1. Attempts to fetch the session from the database
  2. If the session doesn't exist (returns None), automatically calls create_session with the provided parameters
  3. Retrieves and returns the newly created session
  4. Maintains backward compatibility - existing code continues to work without changes

This allows frontends to simply call get_session with a session_id and be confident that the session will be available, regardless of whether it was previously created.

Benefits:

  • Simplifies frontend integration by removing the need to track session creation state
  • Reduces API calls (no need to check existence before calling get_session)
  • Follows the principle of least surprise - getting a session with an ID should work reliably
  • No breaking changes to existing code that checks for None return values

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

pytest results:

@google-cla
Copy link

google-cla bot commented Jan 5, 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 @lwangverizon, 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 enhances the DatabaseSessionService by introducing an automatic session creation mechanism within the get_session method. Previously, frontends had to explicitly handle cases where a session might not exist, leading to increased complexity. With this change, get_session will now create a session if it's not found, streamlining frontend integration and ensuring sessions are always available when requested, without requiring additional logic.

Highlights

  • Automatic Session Creation: The get_session method in DatabaseSessionService now automatically creates a new session if one doesn't already exist for the given app_name, user_id, and session_id. This implements a 'get or create' pattern.
  • Simplified Frontend Integration: This change simplifies frontend development by removing the need for explicit checks and calls to create_session before attempting to retrieve a session, reducing complexity and API calls.
  • Backward Compatibility: The modification maintains full backward compatibility, ensuring existing code that checks for None returns from get_session will continue to function as expected.

🧠 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.

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.

@adk-bot
Copy link
Collaborator

adk-bot commented Jan 5, 2026

Response from ADK Triaging Agent

Hello @lwangverizon, thank you for your contribution!

Before we can review your PR, you will need to sign the Contributor License Agreement (CLA). It looks like the CLA check is currently failing. Please visit https://cla.developers.google.com/ to sign the agreement.

Thanks!

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Jan 5, 2026
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 "get or create" pattern for get_session, which is a useful feature. However, the current implementation in DatabaseSessionService is inefficient, as it creates a session and then immediately re-fetches it, leading to redundant database calls. A more efficient approach would be to return the result of create_session directly. Furthermore, this change introduces a behavioral inconsistency: get_session will now always return a Session for DatabaseSessionService, while the base class and other implementations still allow for a None return. This should be addressed by either making the behavior consistent across all implementations and updating the base class contract, or by introducing a new method for this functionality. The unit tests also need to be updated to reflect this new behavior, as some will likely fail.

@ryanaiagent ryanaiagent self-assigned this Jan 6, 2026
@lwangverizon lwangverizon marked this pull request as ready for review January 7, 2026 21:33
@ryanaiagent
Copy link
Collaborator

Hi @lwangverizon, Thank you for your contribution! We appreciate you taking the time to submit this pull request.
Can you please fix the failing unit tests and lint errors before we proceed with the review.

@ryanaiagent ryanaiagent added the request clarification [Status] The maintainer need clarification or more information from the author label Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants