feat: Expose session ttl/expire_time through the api_server REST create-session endpoint#6408
Open
ItsMacto wants to merge 1 commit into
Open
feat: Expose session ttl/expire_time through the api_server REST create-session endpoint#6408ItsMacto wants to merge 1 commit into
ItsMacto wants to merge 1 commit into
Conversation
…te-session endpoint
Contributor
Author
|
/gemini review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
--auto_create_session, is left as a follow-up so this PR stays small)2. Or, if no issue exists, describe the change:
Problem:
VertexAiSessionService.create_session(**kwargs)supportsttlandexpire_time, but deployments that serve ADK throughadk api_server/get_fast_api_appcannot use them. The REST create-session endpoint only acceptsstate/session_id/eventsand forwards nothing else, so there is no way to create an expiring session over HTTP without patching private internals.Solution:
Add optional
expire_timeandttlfields toCreateSessionRequestand forward them to the session service, with the following behavior:expire_time, duration like"7200s"forttl), matching the documented kwarg usage. The Vertex API stays the authority on value formats.VertexAiSessionServiceitself raises for that case.create_sessionaccepts**kwargs, so custom services registered through the service registry work without the server having to know about them.POST .../sessions/{session_id}endpoint is intentionally unchanged.I kept the REST surface to an explicit whitelist of the two expiration fields rather than an open kwargs pass-through. The underlying Vertex config also accepts keys like
http_optionsandwait_for_completionthat should not be reachable by HTTP clients, and named fields keep the OpenAPI schema meaningful. Safe user-facing keys such asdisplay_nameandlabelscould be added the same way later if there is interest.Testing Plan
Unit Tests:
Five tests added to
tests/unittests/cli/test_fast_api.py, using a smallInMemorySessionServicesubclass that accepts and records expiration kwargs:expireTimeis forwarded to a supporting session service asexpire_time.ttlis forwarded asttl.ttlandexpireTimereturns 422.ttlagainst a plainInMemorySessionServicereturns 400 with the not-supported message.pyink --checkandisort --check-onlyare clean on both touched files, andmypyreports no new errors onapi_server.pycompared to main.Manual End-to-End (E2E) Tests:
Not run against a live Agent Engine backend. The Vertex-side handling of
ttl/expire_timeis already covered by the existingVertexAiSessionServiceunit tests; this change only adds the REST plumbing in front of it, and the new unit tests exercise that seam directly through the FastAPI test client, including the 400 path.Checklist
Additional context
The mutual-exclusion error message intentionally reuses the exact wording from
VertexAiSessionService.create_sessionso the two layers cannot drift apart.