From a6a44578baa2a8e3b3c263bc3753bdebf84bff45 Mon Sep 17 00:00:00 2001 From: ycsmiley Date: Sun, 23 Nov 2025 01:04:18 +0800 Subject: [PATCH 1/4] Fix: Add fallback logic to retrieve user message when resuming async invocation --- src/google/adk/runners.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/google/adk/runners.py b/src/google/adk/runners.py index 2bb01689282..bca6f85afdb 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -1127,6 +1127,7 @@ async def _setup_context_for_resumed_invocation( ValueError: If the session has no events to resume; If no user message is available for resuming the invocation; Or if the app is not resumable. """ + if not session.events: raise ValueError(f'Session {session.id} has no events to resume.') @@ -1134,6 +1135,17 @@ async def _setup_context_for_resumed_invocation( user_message = new_message or self._find_user_message_for_invocation( session.events, invocation_id ) + + # === [START FIX] Fallback mechanism === + if not user_message and session.events: + # If exact invocation match failed, try to find the latest user message + # This handles cases where invocation IDs might have drifted or for generic resume + for event in reversed(session.events): + if event.author == 'user' and event.content: + user_message = event.content + break + # === [END FIX] === + if not user_message: raise ValueError( f'No user message available for resuming invocation: {invocation_id}' From 18abe01151dc3d34bee0c65c551326b2cf1f9840 Mon Sep 17 00:00:00 2001 From: ycsmiley Date: Sun, 23 Nov 2025 01:14:27 +0800 Subject: [PATCH 2/4] Refactor: Add logging warning to fallback logic as suggested --- src/google/adk/runners.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/google/adk/runners.py b/src/google/adk/runners.py index bca6f85afdb..e262fe667db 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -1142,8 +1142,13 @@ async def _setup_context_for_resumed_invocation( # This handles cases where invocation IDs might have drifted or for generic resume for event in reversed(session.events): if event.author == 'user' and event.content: - user_message = event.content - break + logger.warning( + 'Could not find user message for invocation %s. Falling back to ' + 'the latest user message in the session.', + invocation_id, + ) + user_message = event.content + break # === [END FIX] === if not user_message: From 8f7290f3f04bae1b32b8ad82bad2820fbc4a1001 Mon Sep 17 00:00:00 2001 From: ycsmiley Date: Sun, 30 Nov 2025 13:22:39 +0800 Subject: [PATCH 3/4] fix: Remove unnecessary blank lines in experiment and run_experiment scripts This commit cleans up the code by removing trailing blank lines in `experiment.py` and `run_experiment.py`, improving readability without altering functionality. Additionally, it corrects the indentation in a warning log within the `runners.py` file. --- contributing/samples/gepa/experiment.py | 1 - contributing/samples/gepa/run_experiment.py | 1 - src/google/adk/runners.py | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/contributing/samples/gepa/experiment.py b/contributing/samples/gepa/experiment.py index 2f5d03a7728..f68b349d9c6 100644 --- a/contributing/samples/gepa/experiment.py +++ b/contributing/samples/gepa/experiment.py @@ -43,7 +43,6 @@ from tau_bench.types import EnvRunResult from tau_bench.types import RunConfig import tau_bench_agent as tau_bench_agent_lib - import utils diff --git a/contributing/samples/gepa/run_experiment.py b/contributing/samples/gepa/run_experiment.py index cfd850b3a30..1bc4ee58c8d 100644 --- a/contributing/samples/gepa/run_experiment.py +++ b/contributing/samples/gepa/run_experiment.py @@ -25,7 +25,6 @@ from absl import flags import experiment from google.genai import types - import utils _OUTPUT_DIR = flags.DEFINE_string( diff --git a/src/google/adk/runners.py b/src/google/adk/runners.py index 98a374d6bb2..32c2719f1b0 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -1145,10 +1145,10 @@ async def _setup_context_for_resumed_invocation( for event in reversed(session.events): if event.author == 'user' and event.content: logger.warning( - 'Could not find user message for invocation %s. Falling back to ' + 'Could not find user message for invocation %s. Falling back to ' 'the latest user message in the session.', invocation_id, - ) + ) user_message = event.content break # === [END FIX] === From 1f5384fd8c033685dbea74ad70c2d58c43fe6f36 Mon Sep 17 00:00:00 2001 From: ycsmiley Date: Sat, 22 Aug 2026 00:12:34 +0800 Subject: [PATCH 4/4] test(deps): accept GenAI's optional httpx2 import google-genai probes for httpx2 when another installed package provides it. Treat that environment-dependent compatibility import like its existing aiohttp and Pillow probes. --- tests/unittests/test_import_loading.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unittests/test_import_loading.py b/tests/unittests/test_import_loading.py index 1aad5590596..49e9623e3a7 100644 --- a/tests/unittests/test_import_loading.py +++ b/tests/unittests/test_import_loading.py @@ -82,8 +82,8 @@ 'typing_inspection', 'zstandard', # google.genai.types annotates optional fields with aiohttp and Pillow - # types and imports whichever of the two the environment happens to have. - # No ADK module imports either one, so these are absent in some installs. + # types and probes for httpx2 compatibility. It imports whichever packages + # the environment happens to have, so these are absent in some installs. 'PIL', 'aiohappyeyeballs', 'aiohttp', @@ -91,6 +91,7 @@ 'attr', 'defusedxml', 'frozenlist', + 'httpx2', 'multidict', 'propcache', 'yarl',