Repository navigation
ValueError when querying hosted ADK agent from Gemini Enterprise via Google Cloud Agent Engine #6036
Description
🔴 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:
- Deploy a Python ADK agent using
google-adkversion2.2.0on Google Cloud Agent Runtime. - Query the agent via the Gemini Enterprise app.
- The platform sends a fully qualified session path.
- 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).

Activity
adk-bot commentedon Jun 9, 2026
I will read the guidelines and instructions for analyzing GitHub issues first.I will retrieve the details for issue 6036 using the
fetch_github_issuetool.I will find the location ofvertex_ai_session_service.pywithin the codebase.I will view the beginning ofvertex_ai_session_service.pyto find the definition of_validate_session_id.I will view lines 201 to 400 ofvertex_ai_session_service.pyto check for further usages of_validate_session_id.I will search for all occurrences of_validate_session_idin the codebase.I will find occurrences ofsession_idor references to validation tests intest_vertex_ai_session_service.py.I will grep forsession_idinsidetest_vertex_ai_session_service.pyto see validation-related test cases.I will search forValueErrorintest_vertex_ai_session_service.pyto identify tests checking validation logic or failures.I will view lines 720 to 800 oftest_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 thegh pr listsearch 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 EngineExecutive Summary
ValueErroris raised ingoogle-adkwhen 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.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:However, under GCP Agent Runtime (Reasoning Engine), integrations like Gemini Enterprise send fully qualified resource names containing slashes, e.g.:
When this string is received by
get_session, it fails_validate_session_idimmediately with aValueErrorbecause 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:
2. Existing Pull Requests ("Is there a linked PR that fixes this issue?")
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:
vertex_ai_session_service.pythat parses the session ID from the resource name if a fully qualified resource name is supplied, before running validation.../../sessions/my_session_id) are rejected by verifying the path starts withprojects/and contains/sessions/.Example Fix Outline:
The extracted ID must then be assigned back to
session_idat the entry point of methods likecreate_session,get_session,delete_session, andappend_event.Summary of Work
I successfully analyzed the issue
https://github.com/google/adk-python/issues/6036and provided a premium-grade diagnostic report.ValueErrorcrash to be a strict session ID pattern validation error when receiving fully qualified resource paths (containing slashes) under Google Cloud Agent Runtime.dbarrbc commentedon Jun 10, 2026
I am running into the same error
surajksharma07 commentedon Jun 12, 2026
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!
KenTandrian commentedon Jun 13, 2026
Hi @surajksharma07, thanks for the suggestions.
Pinning
google-adkto2.1.0successfully 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!
surajksharma07 commentedon Jun 16, 2026
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!
GWeale commentedon Jun 16, 2026
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.