diff --git a/src/google/adk/runners.py b/src/google/adk/runners.py index e2f5bf6dcf..17b72dda8f 100644 --- a/src/google/adk/runners.py +++ b/src/google/adk/runners.py @@ -2333,6 +2333,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.') @@ -2340,6 +2341,22 @@ 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: + 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: raise ValueError( f'No user message available for resuming invocation: {invocation_id}' diff --git a/tests/unittests/test_import_loading.py b/tests/unittests/test_import_loading.py index 1aad559059..49e9623e3a 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',