Skip to content

fix(google-genai): await async generate_content wrappers inside agent-framework spans - #8415

Closed
PCTEJA wants to merge 1 commit into
getsentry:masterfrom
PCTEJA:fix-google-genai-async-await-8414
Closed

PCTEJA wants to merge 1 commit into
getsentry:masterfrom
PCTEJA:fix-google-genai-async-await-8414

Conversation

@PCTEJA

@PCTEJA PCTEJA commented Nov 26, 2026

Copy link
Copy Markdown

Fixes #8414. When the agent-framework chat-generation flag is set (e.g. by PydanticAIIntegration), the async generate_content wrappers in GoogleGenAIIntegration returned the wrapped coroutine without awaiting it, so callers received a coroutine instead of a GenerateContentResponse (or an async iterator for the stream variant): AttributeError: 'coroutine' object has no attribute 'candidates' plus a never-awaited coroutine warning. The flag is only set when the agent-framework chat span is a real sampled Span, so in production the failure is intermittent. Both wrappers now return await f(self, *args, **kwargs) on that path, matching the OpenAI and Anthropic async wrappers.

Why not duplicating: no open PR addresses #8414 (checked PR search by symbol new_async_generate_content is:pr — 0 results — and the issue's closing-PR references at verification); the reporter only suggests the fix and holds no patch.

Tests run: standalone repro with a real genai.Client and mocked HTTP (pre-fix returns a coroutine and raises AttributeError; post-fix returns the response with the expected text); 2 new regression tests in tests/integrations/google_genai/test_google_genai.py (async non-streaming + async streaming, both entering the real _AgentFrameworkChatGenerationContext) — both fail on the pre-fix code and pass with the fix; full test file tests/integrations/google_genai/test_google_genai.py: 101 passed, 1 skipped. ruff check and ruff format clean; mypy sentry_sdk tests: no issues in 502 source files. No live Google API or pydantic-ai agent run was used; the repro and tests mock the HTTP layer exactly as the file's existing tests do.

AI assistance was used to implement this fix; the change was reviewed line-by-line and the reproduction and tests were run locally before requesting review.

Note: the async embed wrapper has no such early-return branch and is unchanged, as are both sync wrappers.

…-framework spans

When the agent-framework chat-generation flag is set, the async
generate_content wrappers returned the wrapped coroutine without
awaiting it, so callers received a coroutine instead of a
GenerateContentResponse (or an async iterator for the stream variant).
Await the wrapped call on that path, matching the OpenAI and Anthropic
async wrappers.

Fixes getsentry#8414
@PCTEJA
PCTEJA requested a review from a team as a code owner November 26, 2026 23:28
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 2f8aec5.

Main concerns: reach.

This label is a hint for reviewers, not an approval.

@alexander-alderman-webb

Copy link
Copy Markdown
Collaborator

Closing in favor of #8423

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GoogleGenAIIntegration: async wrappers return an un-awaited coroutine inside agent framework chat spans

2 participants