Skip to content

ValueError when querying hosted ADK agent from Gemini Enterprise via Google Cloud Agent Engine #6036

Closed

Description

@KenTandrian

🔴 Required Information

Describe the Bug:
A ValueError is raised in google-adk version 2.2.0 when running an agent hosted on Agent Runtime -- formerly known as Agent Engine / Reasoning Engine (using Vertex AI managed sessions) and querying it from Gemini Enterprise App.

The fully qualified session resource path (which contains slashes /) was passed to the session service. This fails the strict session ID format check (_validate_session_id) added to vertex_ai_session_service.py in 2.2.0 (commit b2916c7).

Steps to Reproduce:

  1. Deploy a Python ADK agent using google-adk version 2.2.0 on Google Cloud Agent Runtime.
  2. Query the agent via the Gemini Enterprise app.
  3. The platform sends a fully qualified session path.
  4. The server throws a ValueError, seen in Google Cloud Logging.

Expected Behavior:
The SDK should either parse/sanitize the fully qualified resource name to extract the short session ID (last segment after /) before validation, or the validator should support full resource paths when invoked by the platform runner.

Observed Behavior:
The server crash logs show:

ValueError: Invalid session_id 'projects/my_project_number/locations/global/collections/default_collection/engines/my_app/sessions/my_session_id': must match ^[A-Za-z0-9_-]+$.

Environment Details:

  • ADK Library Version (pip show google-adk): 2.2.0
  • Desktop OS: macOS
  • Python Version (python -V): Python 3.11

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-3.5-flash

🟡 Optional Information

Regression:
Yes. This worked in google-adk versions prior to 2.2.0 where the _validate_session_id check was not yet present.
The regression was introduced in the commit: b2916c7 (related to #5580).

Logs:

File "/home/myuser/.local/lib/python3.11/site-packages/google/adk/cli/fast_api.py", line 797, in json_generator
  async for chunk in output:
File "/home/myuser/.local/lib/python3.11/site-packages/vertexai/agent_engines/templates/adk.py", line 1342, in streaming_agent_run_with_events
  session = await session_service.get_session(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/myuser/.local/lib/python3.11/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 181, in get_session
  _validate_session_id(session_id)
File "/home/myuser/.local/lib/python3.11/site-packages/google/adk/sessions/vertex_ai_session_service.py", line 58, in _validate_session_id
  raise ValueError(
ValueError: Invalid session_id 'projects/my_project_number/locations/global/collections/default_collection/engines/my_app/sessions/my_session_id': must match ^[A-Za-z0-9_-]+$.

Additional Context:
The commit b2916c7 added _validate_session_id to verify session IDs against ^[A-Za-z0-9_-]+$. However, the ADK runner forwards the full platform path to Vertex AI Session Service, bypassing any extraction, which leads to this crash in hosted environments.

How often has this issue occurred?:

  • Always (100%) when queried from platforms sending fully qualified paths (like Gemini Enterprise).
Image

Activity

  1. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Jun 9, 2026
  2. added theissue type on Jun 9, 2026
  3. adk-bot commented on Jun 9, 2026

    @adk-bot
    Collaborator

    I will read the guidelines and instructions for analyzing GitHub issues first.I will retrieve the details for issue 6036 using the fetch_github_issue tool.I will find the location of vertex_ai_session_service.py within the codebase.I will view the beginning of vertex_ai_session_service.py to find the definition of _validate_session_id.I will view lines 201 to 400 of vertex_ai_session_service.py to check for further usages of _validate_session_id.I will search for all occurrences of _validate_session_id in the codebase.I will find occurrences of session_id or references to validation tests in test_vertex_ai_session_service.py.I will grep for session_id inside test_vertex_ai_session_service.py to see validation-related test cases.I will search for ValueError in test_vertex_ai_session_service.py to identify tests checking validation logic or failures.I will view lines 720 to 800 of test_vertex_ai_session_service.py.I will search the repository for occurrences of /sessions/ to see all resource path templates used.I will search for any existing pull requests related to issue 6036.I will check the status of the gh pr list search command.I will run the unit tests for the Vertex AI session service to verify the testing environment.# GitHub Issue #6036 Analysis: ValueError when querying hosted ADK agent from Gemini Enterprise via Google Cloud Agent Engine

    Executive Summary

    1. What is broken? A ValueError is raised in google-adk when querying hosted agents via Gemini Enterprise because fully qualified resource paths (containing slashes /) are passed to get_session in the VertexAiSessionService. This fails the strict format verification in _validate_session_id.
    2. Is there a linked PR that fixes this issue? None.
    3. Recommendation: Should Fix (High Priority). This bug completely breaks hosted ADK agent execution in production GCP environments (Agent Runtime/Vertex AI reasoning engine) when integrated with Gemini Enterprise.
    Detailed Analysis

    1. Root Cause Analysis ("What is broken?")

    The bug is a regression introduced in commit b2916c7. It added strict session ID validation to reject path traversal or escaping:

    • File Location: vertex_ai_session_service.py:L53-61
    _SESSION_ID_PATTERN = re.compile(r'^[A-Za-z0-9_-]+$')
    
    def _validate_session_id(session_id: str) -> None:
      """Rejects session IDs that could escape the URL path segment."""
      if not isinstance(session_id, str) or not _SESSION_ID_PATTERN.fullmatch(
          session_id
      ):
        raise ValueError(
            f'Invalid session_id {session_id!r}: must match'
            f' {_SESSION_ID_PATTERN.pattern}.'
        )

    However, under GCP Agent Runtime (Reasoning Engine), integrations like Gemini Enterprise send fully qualified resource names containing slashes, e.g.:

    projects/my_project_number/locations/global/collections/default_collection/engines/my_app/sessions/my_session_id
    

    When this string is received by get_session, it fails _validate_session_id immediately with a ValueError because of the slashes and special characters in the path.

    If not checked and sanitized before building the query, using the raw full path also corrupts the computed session resource name construct:

    session_resource_name = (
        f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}'
    )

    2. Existing Pull Requests ("Is there a linked PR that fixes this issue?")

    • Linked PR: None
    • Search Query Execution: Ran gh pr list --repo google/adk-python --search "6036" which returned no matching open or closed pull requests.

    3. Recommendation

    • Recommendation: Should Fix (High Priority)

    • Rationale:

      • Impact: Crucial regression that renders the hosted service completely unusable when queried from Gemini Enterprise.
      • Proposed Fix: Implement an extraction helper within vertex_ai_session_service.py that parses the session ID from the resource name if a fully qualified resource name is supplied, before running validation.
      • Safety: Safe extraction must ensure that nested/arbitrary relative paths (such as ../../sessions/my_session_id) are rejected by verifying the path starts with projects/ and contains /sessions/.

      Example Fix Outline:

      def _extract_session_id(session_id: str) -> str:
        """Extracts the session ID from fully qualified session resource path."""
        if not isinstance(session_id, str):
          return session_id
        if '/' in session_id:
          if session_id.startswith('projects/') and '/sessions/' in session_id:
            parts = session_id.split('/sessions/')
            if len(parts) >= 2 and parts[-1]:
              return parts[-1]
        return session_id

      The extracted ID must then be assigned back to session_id at the entry point of methods like create_session, get_session, delete_session, and append_event.


    Summary of Work

    I successfully analyzed the issue https://github.com/google/adk-python/issues/6036 and provided a premium-grade diagnostic report.

    • Identified the root cause of the ValueError crash to be a strict session ID pattern validation error when receiving fully qualified resource paths (containing slashes) under Google Cloud Agent Runtime.
    • Documented file locations and line references pointing to the malfunctioning validator and its invocation.
    • Confirmed that no active PRs currently address this issue.
    • Proposed a robust, secure solution to selectively extract the final identifier segment for Google Cloud resource names, maintaining full immunity to path-traversal attacks.
  4. dbarrbc commented on Jun 10, 2026

    @dbarrbc

    I am running into the same error

  5. surajksharma07 commented on Jun 12, 2026

    @surajksharma07
    Collaborator

    Thanks for the detailed report @KenTandrian — reproduced this on 2.2.0.

    The session ID validation added in b2916c7 runs before any normalization, so the fully qualified path Gemini Enterprise sends gets rejected in get_session.

    As an interim workaround, try pinning google-adk<2.2.0 (e.g. 2.1.0) on your Agent Engine deployment and confirm it unblocks your queries.

    The proper fix is being tracked in #6048, which normalizes Vertex/GE resource names down to the short session ID before validation.
    Worth noting that the same normalization is also needed on the create_session path, since the Runner can auto-create with the original full path when get_session returns None.
    If you get a chance to test the patched branch against your setup, please do verify it end-to-end and share results there before it moves ahead!

  6. KenTandrian commented on Jun 13, 2026

    @KenTandrian
    Author

    Hi @surajksharma07, thanks for the suggestions.

    Pinning google-adk to 2.1.0 successfully works as a temporary workaround for now.

    I also tested the fix in #6048—Gemini Enterprise is no longer throwing a 400 error, and queries are working exactly as expected. Thanks for the quick fix, @RaghunandanKumar!

  7. surajksharma07 commented on Jun 16, 2026

    @surajksharma07
    Collaborator

    Glad #6048 unblocked you, @KenTandrian — but worth flagging: I just rechecked the PR diff and normalization is currently only wired into get_session/delete_session. create_session still calls the raw validator, so your test likely exercised an existing session (resume path) — a brand-new session created via Gemini Enterprise with the full resource name would still 400 today.

    @devyulbae's follow-up (RaghunandanKumar#1) fixes exactly that gap — @RaghunandanKumar, could we get that merged into this branch before it lands?

    Would be much cleaner to ship one complete fix rather than two passes!

  8. self-assigned this
    on Jun 16, 2026
  9. GWeale commented on Jun 16, 2026

    @GWeale
    Collaborator

    Thanks for this! The same fix has already landed on main — _extract_short_session_id now strips full Agent Engine / Gemini Enterprise resource names before validation in get_session/delete_session (commit 60c55ad). Closing as already-resolved.

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

Metadata

Metadata

Labels

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

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions