Skip to content

fix(py): use async Google GenAI model discovery - #6298

Merged
hilariie merged 8 commits into
genkit-ai:mainfrom
mikemikimike:fix/py-google-genai-async-model-list
Sep 18, 2026
Merged

hilariie merged 8 commits into
genkit-ai:mainfrom
mikemikimike:fix/py-google-genai-async-model-list

Conversation

@mikemikimike

@mikemikimike mikemikimike commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Use client.aio.models.list() for Google GenAI model discovery in asynchronous plugin entry points.
  • Keep model discovery on one asynchronous path and remove the unused synchronous discovery helpers.
  • Update the Google GenAI plugin tests to use reusable async pager mocks that provide a fresh iterator for each discovery call.

Fixes #6186

Tests

  • pytest -p no:cacheprovider -o addopts='' py/packages/genkit-google-genai/test py/packages/genkit-google-genai/tests -q — 738 passed
  • ruff check on the changed Google GenAI source and test files — passed
  • python -m compileall on the Google GenAI source and test packages — passed
  • git diff --check on the changed files — passed

Compatibility / Known limitations

  • Model discovery now consistently uses client.aio.models.list() for both Google AI and Vertex AI plugin entry points.
  • The removed synchronous/private discovery helpers were only used by tests and are replaced by the single asynchronous discovery path.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces asynchronous model discovery to prevent blocking the event loop when fetching models from the Google GenAI SDK. This is achieved by wrapping the synchronous model listing call in asyncio.to_thread and updating the plugin initialization and action listing methods to await this new asynchronous helper. Feedback was provided to refactor the newly added test to avoid potential flakiness in CI/CD environments by asserting thread execution context instead of relying on timing delays.

Comment thread py/packages/genkit-google-genai/tests/google_genai_plugin_test.py Outdated
Comment thread py/packages/genkit-google-genai/src/genkit_google_genai/google.py Outdated
@hilariie

hilariie commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Two issues found, One blocking and one nit.

Blocking: five tests in test/google_plugin_test.py fail at this head with "object MagicMock can't be used in 'await' expression" (test_googleai_initialize, test_googleai_list_actions, test_vertexai_initialize, test_vertexai_list_actions, test_vertexai_list_actions_without_supported_actions). They stub client.models.list but init() and list_actions() now go through client.aio.models.list. Can we point those stubs at the aio surface, or add a fixture that does it once?

Nit: the PR body still describes the worker-thread approach and the slow-call test. Worth updating to match the client.aio change.

mikemikimike and others added 4 commits September 8, 2026 21:07
Dropping the _list_known_* tests took the only test that drove a
generateVideos model through the Google AI categorization branch. The
Vertex test returns before supported_actions is read, so it cannot
reach it.
@hilariie hilariie changed the title fix(py): keep Google GenAI model discovery off the event loop fix(py): use async Google GenAI model discovery Sep 18, 2026
@hilariie
hilariie merged commit 30cfeaf into genkit-ai:main Sep 18, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(py/plugins/google-genai): init() blocks the event loop with a sync models.list()

2 participants