feat(api_server): expose session rewind as a REST endpoint - #7178
Open
chelsealong wants to merge 1 commit into
Open
chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
Runner.rewind_async already implements rewinding a session to before a
given invocation, but no HTTP endpoint exposed it in either the
production api server or the dev server used by `adk web`. Add a POST
/apps/{app_name}/users/{user_id}/sessions/{session_id}/rewind endpoint
to api_server.py (inherited by the dev server) so `adk api_server`
deployments can rewind a session, following the existing session
endpoint conventions in that file.
Fixes google#7177
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):
Problem:
Runner.rewind_asyncalready implements rewinding a session to before agiven invocation (added in a recent refactor of
sessions/_rewind_utils.py),but no HTTP endpoint exposed it. The issue reports that
adk api_serverdeployments have no clean way to abort a generation and rewind the session
to the previous state, even though the underlying capability already exists
in the
Runner.Solution:
Add a
POST /apps/{app_name}/users/{user_id}/sessions/{session_id}/rewindendpoint to
api_server.py, following the exact conventions already used bythe neighboring
get_session/create_session/delete_session/update_sessionendpoints in that file (this is also inherited by the devserver behind
adk web, sinceDevServerextendsApiServer). The requestbody carries
rewind_before_invocation_id(the same parameter nameRunner.rewind_asyncalready uses, and the exact name the issue itselfsuggested), and the endpoint returns the rewound
Session. AValueError(including
SessionNotFoundError, which subclasses it) raised byrewind_async— e.g. an unknown invocation ID or missing session — ismapped to an HTTP 404, matching the error-handling pattern used by the
other session endpoints in this file.
Testing Plan
Unit Tests:
Added
test_rewind_session(verifies the endpoint callsRunner.rewind_asyncwith the rightuser_id/session_id/rewind_before_invocation_idand returns the session) andtest_rewind_session_invocation_not_found(verifies aValueErrorfromrewind_asyncbecomes an HTTP 404) totests/unittests/cli/test_fast_api.py.Confirmed both new tests fail without the fix (
git checkout HEAD~1 -- src/google/adk/cli/api_server.py, rerun): both get a plain FastAPI 404Not Foundbecause the route doesn't exist yet:With the fix restored, the full file passes:
Also ran the existing rewind-focused suites to confirm no regressions in
the underlying rewind logic:
Lint/format (
isort,pyink) pass clean on both changed files.ruff checkreports one pre-existing unrelated finding (sysimported butunused) in
tests/unittests/cli/test_fast_api.pythat already exists onunmodified
main.Manual End-to-End (E2E) Tests:
Not performed beyond the unit tests above (no live LLM/agent environment
available in this session); the endpoint is a thin wrapper around the
already-tested
Runner.rewind_async/_rewind_utils.rewind_sessionpath.Checklist
Additional context
This PR was developed with AI assistance (Claude Code), including reading
the existing
api_server.pyconventions, writing the endpoint/tests, andrunning the verification steps described above; all changes were reviewed
before being pushed.