Skip to content

fix(gen): restore async client with langchain-google-genai >= 4.3.7 - #1

Closed
friedrichwilken wants to merge 1 commit into
mainfrom
fix-google-genai-async
Closed

friedrichwilken wants to merge 1 commit into
mainfrom
fix-google-genai-async

Conversation

@friedrichwilken

@friedrichwilken friedrichwilken commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Context

Review copy on the fork before raising it upstream.

What this PR does and why it is needed

Problem: the SDK's ChatGoogleGenerativeAI overrides an upstream pydantic validator (validate_environment) to inject the AI Core client, and since 4.3.7 upstream also does its async setup in that validator, so the override drops it and every async call fails:

AttributeError: 'ChatGoogleGenerativeAI' object has no attribute '_client_cleanup'

Solution: do that async setup in a validator of our own. A new after-validator _register_client_cleanup on ChatGoogleGenerativeAI wraps the injected client in upstream's _ClientCleanup, which is what async_client and aclose() read. The override itself has to stay because upstream overwrites self.client unconditionally. Embeddings are untouched; upstream's embeddings have no such setup.

_ClientCleanup is a private upstream name. It is imported unconditionally: the pin guarantees it exists, and if upstream ever moves it the SDK fails at import time instead of on the first async call.

Also: pin lifted to langchain-google-genai~=4.4.0, uv.lock regenerated (only that package changes), stale pin in README_sphynx.md updated.

Testing

  • Added test_async_client_available: asserts async_client resolves and aclose() completes, with a mocked proxy client. Fails on 4.4.0 without the fix, passes with it.
  • Live async integration tests (TestAsyncGoogleGenerativeAI) not run locally (no working AI Core credentials at hand). They exercise exactly this path and run in the upstream CI integration job.

@friedrichwilken
friedrichwilken force-pushed the fix-google-genai-async branch 3 times, most recently from 38f97b9 to d6b37e2 Compare September 24, 2026 17:11
The SDK's ChatGoogleGenerativeAI shadows the upstream `validate_environment`
validator to inject the AI Core client. Since langchain-google-genai 4.3.7 that
upstream validator also registers the client with a `_ClientCleanup` object
which the `async_client` property and `aclose()` dereference, so every async
call failed with AttributeError. Register the injected client in a validator
of our own on the chat class, add a unit test covering `async_client` and
`aclose()`, lift the `<4.3.7` pin introduced as a stopgap in SAP#122/SAP#129, and
update the stale pin in README_sphynx.md.

Refs SAP#152
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant